home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / sci / math / symbolic / 2957 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.3 KB  |  48 lines

  1. Newsgroups: sci.math.symbolic
  2. Path: sparky!uunet!mcsun!chsun!bernina!neptune!maeder
  3. From: maeder@inf.ethz.ch (Roman Maeder)
  4. Subject: Re: Question about programming in mma
  5. Message-ID: <1992Nov12.150153.27220@neptune.inf.ethz.ch>
  6. Sender: news@neptune.inf.ethz.ch (Mr News)
  7. Nntp-Posting-Host: arcturus.inf.ethz.ch
  8. Reply-To: maeder@inf.ethz.ch (Roman Maeder)
  9. Organization: Theoretical Computer Science, ETH Zurich
  10. References: <1992Nov11.211405.27798@mlb.semi.harris.com>
  11. Date: Thu, 12 Nov 1992 15:01:53 GMT
  12. Lines: 34
  13.  
  14. In article <1992Nov11.211405.27798@mlb.semi.harris.com> gsp@mlb.semi.harris.com writes:
  15. > Can someone tell me how to pass symbols as parameters
  16. > in mathematica. (like nlambda or macros in lisp)
  17. > For example, I want to define a function "dropCar" that
  18. > takes a symbol as a parameter and has the side-effect of setting the 
  19. > symbol's value to the "rest" of it's list.
  20. >     dropCar[ symbol_ ] := Block[ {},
  21. >         symbol = Rest[ symbol ] 
  22. >     ]
  23. >         
  24. ...
  25.  
  26. This is simple: special forms correspond the definitions for functions
  27. with attribute HoldFirst:
  28.  
  29.     In[1]:= SetAttributes[dropCar, HoldFirst]
  30.     
  31.     In[2]:= dropCar[ symbol_ ] := symbol = Rest[ symbol ]
  32.     
  33.     In[3]:= y = { 1.1, 2.2, 3.3 }
  34.     
  35.     Out[3]= {1.1, 2.2, 3.3}
  36.     
  37.     In[4]:= dropCar[y]
  38.     
  39.     Out[4]= {2.2, 3.3}
  40.     
  41.     In[5]:= y
  42.     
  43.     Out[5]= {2.2, 3.3}
  44.  
  45. Roman Maeder
  46.