On May 24, 2012 8:42 AM, "jlk" <[email protected]> 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!
--
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