all messages for Emacs-related lists mirrored at yhetil.org
 help / color / mirror / code / Atom feed
From: weber <hugows@gmail.com>
To: help-gnu-emacs@gnu.org
Subject: Re: fif function from On Lisp
Date: Tue, 4 Mar 2008 06:12:35 -0800 (PST)	[thread overview]
Message-ID: <df8374a1-e777-4766-b849-18ad6960fc1e@q78g2000hsh.googlegroups.com> (raw)
In-Reply-To: 1580ffe1-31a9-402c-8064-0add67805cac@d62g2000hsf.googlegroups.com

On Mar 4, 11:07 am, weber <hug...@gmail.com> wrote:
> 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

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


  reply	other threads:[~2008-03-04 14:12 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2008-03-04 12:31 fif function from On Lisp weber
2008-03-04 12:53 ` Johan Bockgård
2008-03-04 13:59   ` weber
2008-03-04 14:07     ` weber
2008-03-04 14:12       ` weber [this message]
2008-03-06  0:34 ` Mike Mattie

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=df8374a1-e777-4766-b849-18ad6960fc1e@q78g2000hsh.googlegroups.com \
    --to=hugows@gmail.com \
    --cc=help-gnu-emacs@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this external index

	https://git.savannah.gnu.org/cgit/emacs.git
	https://git.savannah.gnu.org/cgit/emacs/org-mode.git

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.