Path: utzoo!mnetor!uunet!seismo!sundc!pitstop!sun!decwrl!labrea!jade!ucbvax!sdcsvax!ucsdhub!hp-sdd!hplabs!otter!kers
From: kers@otter.HP.COM (Christopher Dollin)
Newsgroups: comp.lang.lisp
Subject: Composition/Partapply in CL Question
Message-ID: <1350002@otter.HP.COM>
Date: 17 Dec 87 11:07:38 GMT
Organization: hplabs-brc Bristol,UK.
Lines: 34

Another question about doing things in CL!

If p and q are functions with arbitrary in-arity and out-arity, what is the
idiomatic efficient way of writing a function 

    (compose p q)

which delivers a function that when applied, applies q to the result of 
applying p to the argument?

    (defun compose (p q)
        #'(lambda (&rest args)
            (multiple-value-call q (apply p args))
        )
    )

is the obvious solution. Would implementors like to comment on its efficiency?
Similarly if p is a function, what is an idiomatic or efficient way to define

    (partapply p a1 ... an)

which produces a function which, when applied to arguments b1 ... bn, applies
p to a1 ... an b1 ... bn.

    (defun partapply (p &rest args)
        #'(lambda (&rest more)
            (apply p (append args more))
        )
    )

should work but it certainly doesn't LOOK efficient ...

Regards,
Kers                                    | "Why Lisp if you can talk Poperly?"