In article <············@newsreader.mailgate.org>,
eugene kim <··········@hotmail.com> wrote:
> hi..
> -----------------------
> (defun f (g)
> (g 2))
>
> (defun square (n)
> (* n n))
>
> (f square)
> ------------------------
Yes, but the syntax is wrong for all existing languages :-)
In Scheme:
(define (f g)
(g 2))
(define (square n)
(* n n))
(f square)
In Common Lisp or emacs lisp:
(defun f (g)
(funcall g 2))
(defun square (n)
(* n n))
(f #'square)
-- Bruce
thank you..
how about returning procedure?
this is scheme version, but don't know how to convert to clisp
--------------------------------------
(define (cons x y)
(define (dispatch m)
(cond ((= m 0) x)
((= m 1) y)
(else (error "argument not 0 or 1 -- cons " m))))
dispatch)
(define (car z) (z 0))
(define (cdr z) (z 1))
---------------------------------------
thank you again..
In article <············@newsreader.mailgate.org>,
eugene kim <··········@hotmail.com> wrote:
> thank you..
>
> how about returning procedure?
>
> this is scheme version, but don't know how to convert to clisp
> --------------------------------------
> (define (cons x y)
> (define (dispatch m)
> (cond ((= m 0) x)
> ((= m 1) y)
> (else (error "argument not 0 or 1 -- cons " m))))
> dispatch)
>
> (define (car z) (z 0))
> (define (cdr z) (z 1))
> ---------------------------------------
> thank you again..
Note that you don't need the inner "define" in either Scheme or Common
Lisp -- a lambda will do just fine.
(defun cons (x y)
(lambda (m)
(cond ((= m 0) x)
((= m 1) y)
(t (error "argument not 0 or 1 -- cons " m)))))
(defun car (z) (funcall z 0))
(defun cdr (z) (funcall z 1))
Also, of course, this is cool for demonstrating the power of closures,
but in CL you can use classes/objects to do the same thing more
conveniently.
-- Bruce
Bruce Hoult <·····@hoult.org> wrote in message news:<···························@copper.ipg.tsnz.net>...
> In article <············@newsreader.mailgate.org>,
> eugene kim <··········@hotmail.com> wrote:
>
> > hi..
> > -----------------------
> > (defun f (g)
> > (g 2))
> >
> > (defun square (n)
> > (* n n))
> >
> > (f square)
> > ------------------------
>
> Yes, but the syntax is wrong for all existing languages :-)
Well, it's perfectly valid EuLisp, but I imagine that's not
what he's using.
--
T. Kurt Bond, ···@tkb.mpl.com
T. Kurt Bond <···@tkb.mpl.com> wrote:
> Well, it's perfectly valid EuLisp, [...]
It is probably valid in any single-namespace dialect of LISP.
Nils.
--
Nils M Holm <···@t3x.org> -- http://www.not-compatible.org/nmh/
* Bruce Hoult <·····@hoult.org>:
> In article <············@newsreader.mailgate.org>,
> eugene kim <··········@hotmail.com> wrote:
>
> > hi..
> > -----------------------
> > (defun f (g)
> > (g 2))
> >
> > (defun square (n)
> > (* n n))
> >
> > (f square)
> > ------------------------
>
> Yes, but the syntax is wrong for all existing languages :-)
It's valid rep, as in librep (which probably means that what you say is
correct (see Erik's comment elsewhere about language vs programming tool)).
--
Dave Pearson: | festival.jl - Make sawfish talk.
http://www.davep.org/ | keydrag.jl - Drag windows from keyboard.
Sawfish: | sawfish.el - Sawfish mode for emacs.
http://www.davep.org/sawfish/ | uptimes.jl - Record sawfish uptimes.