(defun fif (a b &optional c)
'(lambda (x)
(if (funcall a x)
(funcall b x)
(unless (null c) (funcall c x)))))
I should be able to call it like this:
(mapcar (fif 'zerop '1+ 1-) '(0 1 2 3) => (1 0 1 2)
but i'm probably missing something that is differs from Common Lisp to
Elisp.
Thanks in advance,
weber
The code above doesn't work in Common Lisp either, but anyway, Emacs
Lisp doesn't have lexical closures (yet).
(info "(elisp) Extent")
--
Johan Bockgård
Hm. Does that snippet really depends on lexical closures?
I just need that function to expand to this:
(mapcar (lambda (x) (if (funcall 'zerop x) (funcall '1+ x) (funcall
'1- x)))
'(0 1 2 3))
... maybe I can solve it with a macro then?
-weber
Ok, i can.
Tks anyway.
(defmacro fif (a b &optional c)
`(lambda (x)
(if (funcall ,a x)
(funcall ,b x)
(unless (null ,c) (funcall ,c x)))))
-weber
Just needed to post a correct version:
(defmacro fif (a b &optional c)
`(lambda (x)
(if (funcall ,a x)
(funcall ,b x)
(if (null ,c) x (funcall ,c x)))))
-weber
(require 'cl)
(defun plus (x)
(+ x 1))
(defun minus (x)
(- x 1))
(defun fif (a b &optional c)
(lexical-let
((a-fn a)
(b-fn b)
(c-fn c))
(lambda (x)
(if (funcall a-fn x)
(funcall b-fn x)
(if (functionp c-fn) (funcall c-fn x))))))
(mapcar (fif 'zerop 'plus 'minus) '(0 1 2 3)) ;; => (1 0 1 2)
This works here.
Cheers,
Mike Mattie