From: meatlocket
Subject: Hello - I wonder about this. Please help if you can.
Date: 
Message-ID: <tdv7uusinc4smcr6aoseg7gporeagjtei7@4ax.com>
In LISP is it possible?
Can you specify functions as parameters?
Can you return functions as values?
Can you specify function types and declare variables of such types?
Provide example if so.

Its thanks you very much!

From: Tim Bradshaw
Subject: Re: Hello - I wonder about this. Please help if you can.
Date: 
Message-ID: <ey33cpnudl4.fsf@cley.com>
* meatlocket  wrote:
> In LISP is it possible?
> Can you specify functions as parameters?
> Can you return functions as values?
> Can you specify function types and declare variables of such types?

Yes

> Provide example if so.

No...
From: Kent M Pitman
Subject: Re: Hello - I wonder about this. Please help if you can.
Date: 
Message-ID: <sfwbs4bj4do.fsf@shell01.TheWorld.com>
meatlocket <··········@warcraft3.net> writes:

> In LISP is it possible?

Where did these questions come from??  If this is for a class, you should
have said so.  If it's not for a class, it certainly seems like a strange
set of first question for a novice.

> Can you specify functions as parameters?

(f #'f)                             ; specifying named function as parameter
(f #'(lambda (x y) (+ x (- y 3))))  ; specifying unnamed function as parameter

> Can you return functions as values?

Yes.  Same notation as above.

(defun f ()
  #'f)  ;returns itself

or

(defun f ()
  ;; Returns function of x,y that computes x+(y-3)
  #'(lambda (x y) (+ x (- y 3))))


> Can you specify function types and declare variables of such types?

Variables need not be declared in Lisp.  Types are manifest in the
objects themselves.  By default, all variables hold objects of any
kind, including functions.  You can restrict variables to objects
of a certain type if you want, but it only occasionally does any good.
In the case of restricting things to being functions, I doubt you'll
get any useful effect other than to make life harder for yourself.

> Provide example if so.

(defun do-n-times (n f initial-val)
  (declare (function f)) ;This line is optional and can be omitted.
  (let ((val initial-val))
    (dotimes (i n)
      (setq val (funcall f val)))
    val))

(do-n-times 3 #'(lambda (x) (+ x 2)) 0) => 6
From: Coby Beck
Subject: Re: Hello - I wonder about this. Please help if you can.
Date: 
Message-ID: <as11qg$6vs$1@otis.netspace.net.au>
"meatlocket" <··········@warcraft3.net> wrote in message
·······································@4ax.com...
> In LISP is it possible?

yes!
From: meatlocket
Subject: Re: Hello - I wonder about this. Please help if you can.
Date: 
Message-ID: <dp28uuc65a7bqrcgv15d3mfm6pj4tb4su2@4ax.com>
On Wed, 27 Nov 2002 11:00:22 +1100, "Coby Beck" <·····@mercury.bc.ca>
wrote:

>
>"meatlocket" <··········@warcraft3.net> wrote in message
>·······································@4ax.com...
>> In LISP is it possible?
>
>yes!
>
>

thankyou the answers. I am learning a programming language by name of
Ruby in my class in JAPAN. I am not well informed about Lisp. but
professor told me it is very good to have function as parameter. I
don't mean to offend the person who takes great offense as question.
It is not for class the question is asked, but for my general
information! thankyou for the answer! There is not a good place to
find the information at my area in JAPAN, for internet ability is
limited. I was asked to look here. Thanks again

????13,457??????????????(2002/02/14??)?
????�?????????What's NEW!??????????
From: Henrik Motakef
Subject: Re: Hello - I wonder about this. Please help if you can.
Date: 
Message-ID: <87el97u996.fsf@pokey.henrik-motakef.de>
meatlocket <·················@warcraft3.net> writes:

> I am not well informed about Lisp. but professor told me it is very
> good to have function as parameter.

He is right. Once you are used to it, it is a pain to use languages
that don't offer this.

For a simple example of where this is useful, you might want to look
at the SORT function. You pass it a sequence to be sorted, and a
function that tells SORT whether one item is to be considered less
than another. That way you can use it to sort sequences of arbitrary
objects by providing a custom comparison function.

> There is not a good place to find the information at my area in
> JAPAN, for internet ability is limited. 

If you have WWW access, you should have a look at
<http://www.lisp.org> (by the Association of Lisp Users, contains lots
of pointers to documentation and more), <http://ww.telent.net/cliki/>
(a wiki web mostly about free/open source CL stuff) and
<http://www.lispworks.com/reference/HyperSpec/Front/index.htm> (the CL
reference).

> I was asked to look here. Thanks again

You're welcome. However, newsgroups are probably not a good way to
learn the basics of a language - if you want to learn more about Lisp,
you should get a good tutorial, and work through it first (of course,
you can ask specific questions here). You will find pointers to both
online tutorials and books on the web pages I mentioned (and google
will find more).

Have fun
Henrik