MathGroup Archive 2011

[Date Index] [Thread Index] [Author Index]

Search the Archive

execution model: Function vs. delayed execution

  • To: mathgroup at smc.vnet.net
  • Subject: [mg121327] execution model: Function vs. delayed execution
  • From: Alan <alan.isaac at gmail.com>
  • Date: Sat, 10 Sep 2011 07:30:29 -0400 (EDT)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • Reply-to: comp.soft-sys.math.mathematica at googlegroups.com

Warning: I am a Mathematica newbie and not a CS type, so my vocabulary may prove clumsy.

I am used to a deferred execution model of function definition.  Roughly, if I can write code that would be successfully executed outside a function definition, then I can make it a function body by appropriately "wrapping" it.

In Mathematica, I can evaluate the following):
x = {1,1,2}
x=DeleteDuplicates[x]; x
(Note: the redundancy is intentional.)

Next, I attempt to "wrap" this as follows
Clear[x]
Function[x, (x=DeleteDuplicates[x];x)][{1,1,2}]

This produces an error:
Set::shape: "Lists {1,1,2} and {1,2} are not the same shape."

Can you help me understand the execution model that leads to this?

Thanks,
Alan Isaac





  • Prev by Date: help to make code run faster (mathematica v8.01)
  • Next by Date: Re: DiscretePlot filling is darker above axis than below
  • Previous by thread: Re: help to make code run faster (mathematica v8.01)
  • Next by thread: Re: execution model: Function vs. delayed execution