Function composition?
Function composition?
Is there a builtin compose function in newlisp?
Re: Function composition?
No compose function, but for sure other means to achieve similar. This link talks about function factories and the first-class nature of lambda expressions in newLISP:
http://www.newlisp.org/index.cgi?Closures
General info about differences to Common Lisp and Scheme:
http://www.newlisp.org/index.cgi?page=D ... ther_LISPs
Also, 'apply' has a reduce option:
http://www.newlisp.org/downloads/newlis ... html#apply
There is also a 'curry':
http://www.newlisp.org/downloads/newlis ... html#curry
http://www.newlisp.org/index.cgi?Closures
General info about differences to Common Lisp and Scheme:
http://www.newlisp.org/index.cgi?page=D ... ther_LISPs
Also, 'apply' has a reduce option:
http://www.newlisp.org/downloads/newlis ... html#apply
There is also a 'curry':
http://www.newlisp.org/downloads/newlis ... html#curry
-
- Posts: 388
- Joined: Thu May 08, 2008 1:24 am
- Location: Croatia
- Contact:
Re: Function composition?
I wrote the post "Composition of functions and macros" on my blog.
((composition 'f1 ... 'fn) _ _ _) = (f1 (f2 ... (fn _ _ _)))
If there was no significant change from February 2010, you should be able to cut and paste whole post in your editor and it should work.
((composition 'f1 ... 'fn) _ _ _) = (f1 (f2 ... (fn _ _ _)))
If there was no significant change from February 2010, you should be able to cut and paste whole post in your editor and it should work.
Re: Function composition?
Thank you , Kazimir.
-
- Posts: 58
- Joined: Sat Jun 10, 2006 5:34 am
Re: Function composition?
These seem to work.
Thanks to Kazimir Majorinc for the idea of using expand.
Code: Select all
;; Compose two functions. Both accept only 1 argument.
(define (atop f g)
(expand (lambda (a) (f (g a))) 'f 'g))
;; Compose two functions. The first to be called accepts
;; any number of arguments.
(define (atop* f g)
(expand
(lambda () (f (apply g (args))))
'f 'g))