home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: sci.math.symbolic
- Path: sparky!uunet!mcsun!chsun!bernina!neptune!maeder
- From: maeder@inf.ethz.ch (Roman Maeder)
- Subject: Re: Question about programming in mma
- Message-ID: <1992Nov12.150153.27220@neptune.inf.ethz.ch>
- Sender: news@neptune.inf.ethz.ch (Mr News)
- Nntp-Posting-Host: arcturus.inf.ethz.ch
- Reply-To: maeder@inf.ethz.ch (Roman Maeder)
- Organization: Theoretical Computer Science, ETH Zurich
- References: <1992Nov11.211405.27798@mlb.semi.harris.com>
- Date: Thu, 12 Nov 1992 15:01:53 GMT
- Lines: 34
-
- In article <1992Nov11.211405.27798@mlb.semi.harris.com> gsp@mlb.semi.harris.com writes:
- > Can someone tell me how to pass symbols as parameters
- > in mathematica. (like nlambda or macros in lisp)
- >
- > For example, I want to define a function "dropCar" that
- > takes a symbol as a parameter and has the side-effect of setting the
- > symbol's value to the "rest" of it's list.
- >
- > dropCar[ symbol_ ] := Block[ {},
- > symbol = Rest[ symbol ]
- > ]
- >
- ...
-
- This is simple: special forms correspond the definitions for functions
- with attribute HoldFirst:
-
- In[1]:= SetAttributes[dropCar, HoldFirst]
-
- In[2]:= dropCar[ symbol_ ] := symbol = Rest[ symbol ]
-
- In[3]:= y = { 1.1, 2.2, 3.3 }
-
- Out[3]= {1.1, 2.2, 3.3}
-
- In[4]:= dropCar[y]
-
- Out[4]= {2.2, 3.3}
-
- In[5]:= y
-
- Out[5]= {2.2, 3.3}
-
- Roman Maeder
-