* fif function from On Lisp
@ 2008-03-04 12:31 weber
2008-03-04 12:53 ` Johan Bockgård
2008-03-06 0:34 ` Mike Mattie
0 siblings, 2 replies; 6+ messages in thread
From: weber @ 2008-03-04 12:31 UTC (permalink / raw)
To: help-gnu-emacs
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.
Thanks in advance,
weber
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fif function from On Lisp
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-06 0:34 ` Mike Mattie
1 sibling, 1 reply; 6+ messages in thread
From: Johan Bockgård @ 2008-03-04 12:53 UTC (permalink / raw)
To: help-gnu-emacs
weber <hugows@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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fif function from On Lisp
2008-03-04 12:53 ` Johan Bockgård
@ 2008-03-04 13:59 ` weber
2008-03-04 14:07 ` weber
0 siblings, 1 reply; 6+ messages in thread
From: weber @ 2008-03-04 13:59 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fif function from On Lisp
2008-03-04 13:59 ` weber
@ 2008-03-04 14:07 ` weber
2008-03-04 14:12 ` weber
0 siblings, 1 reply; 6+ messages in thread
From: weber @ 2008-03-04 14:07 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fif function from On Lisp
2008-03-04 14:07 ` weber
@ 2008-03-04 14:12 ` weber
0 siblings, 0 replies; 6+ messages in thread
From: weber @ 2008-03-04 14:12 UTC (permalink / raw)
To: help-gnu-emacs
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
^ permalink raw reply [flat|nested] 6+ messages in thread
* Re: fif function from On Lisp
2008-03-04 12:31 fif function from On Lisp weber
2008-03-04 12:53 ` Johan Bockgård
@ 2008-03-06 0:34 ` Mike Mattie
1 sibling, 0 replies; 6+ messages in thread
From: Mike Mattie @ 2008-03-06 0:34 UTC (permalink / raw)
To: help-gnu-emacs
[-- Attachment #1: Type: text/plain, Size: 924 bytes --]
On Tue, 4 Mar 2008 04:31:19 -0800 (PST)
weber <hugows@gmail.com> wrote:
> 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.
>
> Thanks in advance,
> 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
[-- Attachment #2: signature.asc --]
[-- Type: application/pgp-signature, Size: 189 bytes --]
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2008-03-06 0:34 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
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
2008-03-06 0:34 ` Mike Mattie
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.