Page 1 of 1

Juxtaposition

Posted: Mon Nov 12, 2012 12:49 am
by jopython
The clojure.core has this juxtapostion function which i find very useful. I wonder how easy is it to implement in newLisp.

Code: Select all

Takes a set of functions and returns a fn that is the juxtaposition
of those fns. The returned fn takes a variable number of args, and
returns a vector containing the result of applying each fn to the
args (left-to-right).
e.g
((juxt a b c) x) => [(a x) (b x) (c x)]
I am not worried whether this function returns a vector or a list.

Re: Juxtaposition

Posted: Mon Nov 12, 2012 4:54 am
by rickyboy
Try this on for size. Maybe there is a better way though.

Code: Select all

(define (juxt)
  (letex (_args (args))
    (lambda (x)
      (let (fs '_args)
        (map (lambda (f) (f x)) fs)))))

Re: Juxtaposition

Posted: Mon Nov 12, 2012 12:27 pm
by jopython
That is amazing.
Someday I will also get to learn the black art of macros.