From: eugene kim
Subject: can i do this?
Date: 
Message-ID: <acs9rv$8sc$1@newsreader.mailgate.org>
hi..
-----------------------
(defun f (g)
  (g 2))

(defun square (n)
  (* n n))

(f square)
------------------------
thank you

From: Bruce Hoult
Subject: Re: can i do this?
Date: 
Message-ID: <bruce-3D0739.15593527052002@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 :-)

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
From: eugene kim
Subject: Re: can i do this?
Date: 
Message-ID: <acsd94$b0v$1@newsreader.mailgate.org>
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..
From: Bruce Hoult
Subject: Re: can i do this?
Date: 
Message-ID: <bruce-DD29A2.16590127052002@copper.ipg.tsnz.net>
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
From: T. Kurt Bond
Subject: Re: can i do this?
Date: 
Message-ID: <a3db6b24.0205271122.6f33d7fd@posting.google.com>
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
From: Nils M Holm
Subject: Re: can i do this?
Date: 
Message-ID: <3cf2ac05$0$14318$9b622d9e@news.freenet.de>
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/
From: Dave Pearson
Subject: Re: can i do this?
Date: 
Message-ID: <slrnaf6hh1.csj.davep.news@hagbard.davep.org>
* 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.