MathGroup Archive 2006

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

Search the Archive

Re: Lisp-like let in Mathematica?

  • To: mathgroup at smc.vnet.net
  • Subject: [mg63465] Re: Lisp-like let in Mathematica?
  • From: Louis Theran <theran at gmail.com>
  • Date: Sun, 1 Jan 2006 01:16:24 -0500 (EST)
  • References: <dp5rpt$rpm$1@smc.vnet.net> <003a01c60e2c$9d083af0$210110ac@windsor>
  • Sender: owner-wri-mathgroup at wolfram.com

Thanks for the pointer.  I'll have a look at Block and Module.

I wouldn't mind so much if the function only looked backwards, but  
it's almost knotted up on itself, though this seems directly related  
to mixing function application from the left and the right.  (Hence  
my question about style; I could imagine a convention of not  
mixing // and @ being helpful.)

The operator precedence works out here, but I would have to look at  
the precedence rules and carefully parse it to explain why.  Usually  
I just try something and add more parens as needed.  Coming from a  
Lisp background, I must say that Mathematica is generally pretty difficult  
for me to read, especially since there is no clear way to indent  
expressions to show nesting.

I do appreciate the level of compactness of the Mathematica notation,  
though.  For example

DirectedIncidenceMatrix[G_] :=
   IncidenceMatrix[#] - IncidenceMatrix[ReverseEdges[#]] & @  
OrientGraph[G] //
            Transpose

GlueMatrixRight[A__] :=
   (Join @@ (Transpose /@ A))// Transpose

RigidityRow[e_,a_] := (e.a)*e

RigidityBlock[A_,a_] :=
   RigidityRow[#,a] & /@ A

RigidityMatrix[G_,P_] :=
   GlueMatrixRight[RigidityBlock[DirectedIncidenceMatrix[G],#] & /@  
Transpose[P]]

is quite terse, but doesn't hide what's going on too much, once you  
slog through all the operators.  That you can crank out symbolic  
coordinates with something like

{a\_#,b\_#} & /* Range[V[G]]

is convenient as well.



On Dec 31, 2005, at 12:06, Richard Fateman wrote:

> You might read about Block or Module.
> Or perhaps if you prefer let*  in common lisp..
>
> BlockX[{}, E_] := E
> BlockX[{a_, b___}, E_] := Block[{a}, BlockX[{b}, E]]
> Attributes[BlockX] = {HoldAll}
>
>
> As for whether your program is "good" Mathematica style, it seems  
> to me that it is a matter of taste.  Some people would
> say yes. I agree with you that it looks backwards, and by using
> so many operators it raises questions about precedence between
> them. Does Mathematica do the right thing?
> RJF
>
>
> ----- Original Message ----- From: <theran at gmail.com>
To: mathgroup at smc.vnet.net
> Newsgroups: comp.soft-sys.math.mathematica
> Subject: [mg63465] Lisp-like let in Mathematica?
>
>
>> Are functions like
>>  RealizeGraphicMatroid[G_] :=
>>    IncidenceMatrix[#] - IncidenceMatrix[ReverseEdges[#]] & @
>> OrientGraph[G] // Transpose
>> considered to be good Mathematica style?  This does what I want,  
>> but it
>> has the problem of being written in a right-to-left-to-right  
>> style.  Is
>> there an operator that works like let in Lisp that can give a local
>> name to a temporary value in an easier to read way?  I guess  
>> something
>> like
>>  Let[a_ , b_, body_] :=
>>    (body /. a -> #) & @ b
>> would work, but I'm relatively new to Mathematica and was  
>> wondering if
>> there is a built-in or less clunky solution.
>> ^L
>>
>


  • Prev by Date: Re: Lisp-like let in Mathematica?
  • Next by Date: Re: timer
  • Previous by thread: Re: Lisp-like let in Mathematica?
  • Next by thread: Re: is there a way to have the "Get" accept C formed%E numbers like Read does for Real?