home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / function / 1038 < prev    next >
Encoding:
Text File  |  1992-08-26  |  1.7 KB  |  56 lines

  1. Newsgroups: comp.lang.functional
  2. Path: sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjh
  3. From: fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON)
  4. Subject: Re: transcendental functions in Gofer
  5. Message-ID: <9223923.29234@mulga.cs.mu.OZ.AU>
  6. Sender: news@cs.mu.OZ.AU
  7. Organization: Computer Science, University of Melbourne, Australia
  8. References: <aet.714816424@munagin>
  9. Date: Wed, 26 Aug 1992 13:33:53 GMT
  10. Lines: 44
  11.  
  12. aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
  13.  
  14. >has anyone implemented any functions in Gofer to do any of the following
  15. >on Floats:
  16. >
  17. >sqrt exp log sin atan erf
  18. >
  19. >btw, i don't mind if you've use `primitive' to define them in the interpreter
  20. >itself.
  21. Wed Aug 26 23:24:55 EST 1992
  22.  
  23. I haven't done these ones myself, but it is VERY easy to add new primitives.
  24.  
  25. Just add lines like
  26.     primitive "primitiveExpFloat" exp :: Float -> Float
  27. to the prelude, add functions like
  28.  
  29. /* one-argument example */
  30. primFun(primExpFloat) {           /* Float exp primitive       */
  31.     eval(primArg(1));
  32.     updateRoot(mkFloat(sin(whnfFloat)));
  33.                ^^^ substitute as appropriate
  34. }
  35.  
  36. /* two-argument example */
  37. primFun(primAtan2Float) {          /* Float atan2 primitive       */
  38.     Float x;
  39.     eval(primArg(2));
  40.     x = whnfFloat;
  41.     eval(primArg(1));
  42.     updateRoot(mkFloat(atan2(x,whnfFloat)());
  43.                ^^^^^ substitute as appropriate
  44. }
  45.  
  46. to "builtin.c", add these functions to the table of builtin functions
  47. in builtin.c, and then just run "make".
  48.  
  49. P.S. If you have any trouble, I'd be happy to give you a hand.
  50.  
  51. -- 
  52. Fergus Henderson             fjh@munta.cs.mu.OZ.AU      
  53. This .signature virus is a self-referential statement that is true - but 
  54. you will only be able to consistently believe it if you copy it to your own
  55. .signature file!
  56.