On Friday, May 25, 2012 9:30:12 AM UTC+10, Stephen Compall wrote:
>
> On May 24, 2012 8:42 AM, "jlk" JLK wrote:
> > However the only way I can think of converting the argument list and the
> function into a function of one argument is with an intermediate function.
>
> Apply is the standard way to listify a function's arguments. Where f is a
> function taking n args, (partial apply f) is a function taking (among other
> disjoint possibilities) one arg being a list of n values.
>
> > (defn -cat
> > "example math function"
> > [{:keys [E A alpha t2 t1 W1 W2 g L T1 T2]}]
> > (- (+ (* E A alpha (- t2 t1)) (/ (* (sq W1) (sq g) (sq L) E A) (* 24.0
> (sq T1))) T2) T1 (/ (* (sq W2) (sq g) (sq L) E A) (* 24.0 (sq T2)))))
>
> Take a look at (meta #'-cat) in this example; you may find it of use.
>
> > As a side note, being able to define functions in infix would also be
> nice, but I don't feel up to creating a maths parser and dealing with ASTs,
> although I can visualise how I might manage the variables using this
> approach.
>
> If you parse Clojure lists, this reduces to a problem of grouping and
> flipping back to prefix.
>
> Traversable functors and the writer monad are good choices for collecting
> vars as you are grouping and flipping, though you perhaps have something
> else in mind. The real trouble is discriminating between bound and free
> vars.
>
> --
> Stephen Compall
> Greetings from sunny Appleton!
>
Hi Stephen
Firstly thanks for looking at the code - certainly given me a few tips and
ideas there. Also I'll look into monads when I get some spare brain time :)
I didn't realise that the argument list was in a var metadata. Do you know
if there is similar metadata for an undefined function (fn [] ...)?
Originally what I was thinking of was a kind of 'partial' function taking
map arguments and that is where I'm heading.
Playing around this morning I think I've stumbled upon what I was after and
the code is in the devel branch on github. It's currently horrible, but
seems to work. Basically the maths function is provided as a list of
symbols, then I do some substitution using clojure.walk and produce a
function of argument whatever is still undefined. Then I run this through
eval.
Speaking of it would be nice if eval could directly take a map of symbols
as an argument.
I'll tidy all this up when I get a chance.
Cheers
--
You received this message because you are subscribed to the Google
Groups "Clojure" group.
To post to this group, send email to [email protected]
Note that posts from new members are moderated - please be patient with your
first post.
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/clojure?hl=en