help-gnu-emacs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: fif function from On Lisp


From: weber
Subject: Re: fif function from On Lisp
Date: Tue, 4 Mar 2008 06:07:36 -0800 (PST)
User-agent: G2/1.0

On Mar 4, 10:59 am, weber <hug...@gmail.com> wrote:
> On Mar 4, 9:53 am, bojohan+n...@dd.chalmers.se (Johan Bockgård) wrote:
>
>
>
> > weber <hug...@gmail.com> writes:
> > > Hi folks.
> > > For some reason this function from On Lisp doesn't work:
>
> > > (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.
>
> > 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


reply via email to

[Prev in Thread] Current Thread [Next in Thread]