Article View: comp.lang.functional
Article #178Re: transcendental functions in Gofer
From: Fergus James HENDERSON
Date: Wed, 26 Aug 1992 13:33
Date: Wed, 26 Aug 1992 13:33
44 lines
1800 bytes
1800 bytes
aet@mullian.ee.mu.OZ.AU (bert thompson) writes:
>has anyone implemented any functions in Gofer to do any of the following
>on Floats:
>
>sqrt exp log sin atan erf
>
>btw, i don't mind if you've use `primitive' to define them in the interpreter
>itself.
Wed Aug 26 23:24:55 EST 1992
I haven't done these ones myself, but it is VERY easy to add new primitives.
Just add lines like
primitive "primitiveExpFloat" exp :: Float -> Float
to the prelude, add functions like
/* one-argument example */
primFun(primExpFloat) { /* Float exp primitive */
eval(primArg(1));
updateRoot(mkFloat(sin(whnfFloat)));
^^^ substitute as appropriate
}
/* two-argument example */
primFun(primAtan2Float) { /* Float atan2 primitive */
Float x;
eval(primArg(2));
x = whnfFloat;
eval(primArg(1));
updateRoot(mkFloat(atan2(x,whnfFloat)());
^^^^^ substitute as appropriate
}
to "builtin.c", add these functions to the table of builtin functions
in builtin.c, and then just run "make".
P.S. If you have any trouble, I'd be happy to give you a hand.
--
Fergus Henderson fjh@munta.cs.mu.OZ.AU
This .signature virus is a self-referential statement that is true - but
you will only be able to consistently believe it if you copy it to your own
.signature file!
Technical Details
Message-ID:
<9223923.29234@mulga.cs.mu.OZ.AU>Path:
arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjhReferences:
<aet.714816424@munagin>Show Full Headers
Complete Article Headers
Newsgroups: comp.lang.functional Path: arc1-ca.pugleaf.net!sparky!uunet!munnari.oz.au!cs.mu.OZ.AU!mundil.cs.mu.OZ.AU!fjh From: fjh@mundil.cs.mu.OZ.AU (Fergus James HENDERSON) Subject: Re: transcendental functions in Gofer Message-ID: <9223923.29234@mulga.cs.mu.OZ.AU> Sender: news@cs.mu.OZ.AU Organization: Computer Science, University of Melbourne, Australia References: <aet.714816424@munagin> Date: Wed, 26 Aug 1992 13:33:53 GMT Lines: 44