From: ·······@trystan.org
Subject: Question on interpretation of higher order function calls
Date: 
Message-ID: <a2a826e3-58a1-4bf9-9a85-343c55e4d144@a9g2000prl.googlegroups.com>
Hi all, I'm fairly new to lisp but have some experience in other
languages supporting functions as first class values, higher order
functions, etc. Upon diving into Lisp, I expected the following to
work (where fun is some function).

(defun (fun)
   (fun)
)

However, I found that what I needed was.

(defun (fun)
   (funcall fun)
)

I'm guessing this has something to do with the chapter on symbols that
I didn't read carefully enough ;-) However, I'm having trouble seeing
a case where I would want to do something with 'fun' other than call
it, so why the extra syntax required by default?

Can someone shed some light on why funcall is needed rather than being
assumed?

Cheers,
Trystan

From: Rainer Joswig
Subject: Re: Question on interpretation of higher order function calls
Date: 
Message-ID: <joswig-3BFD0F.20402301072008@news-europe.giganews.com>
In article 
<····································@a9g2000prl.googlegroups.com>,
 ·······@trystan.org wrote:

> Hi all, I'm fairly new to lisp but have some experience in other
> languages supporting functions as first class values, higher order
> functions, etc. Upon diving into Lisp, I expected the following to
> work (where fun is some function).
> 
> (defun (fun)
>    (fun)
> )
> 
> However, I found that what I needed was.
> 
> (defun (fun)
>    (funcall fun)
> )

You really don't want to place the closing parenthesis on
a line. It feels so lonely there. ;-)


> I'm guessing this has something to do with the chapter on symbols that
> I didn't read carefully enough ;-) However, I'm having trouble seeing
> a case where I would want to do something with 'fun' other than call
> it, so why the extra syntax required by default?
> 
> Can someone shed some light on why funcall is needed rather than being
> assumed?

Common Lisp has separate namespaces for function names and
variable names. Since fun is a variable, you need FUNCALL
to call the value of it as a function.

Compare:

(defun foo () ...)

(defun bar (foo)
   (foo)
   (funcall foo))

BAR calls two different functions. The first is the global function
FOO and the second is the value of the local variabel foo.

See also:

Common Lisp has a LIST function:  (list 1 2 3)  -> (1 2 3)

(defun foo (list)
   (list list))

FOO calls the Common Lisp function LIST with the value of the local
variable LIST. In many other languages (Scheme, ...) you
would need to write

(defun foo (some-list)
   (list some-list)) 

to avoid name clashes. Not in Common Lisp.







> 
> Cheers,
> Trystan

-- 
http://lispm.dyndns.org/
From: Trystan
Subject: Re: Question on interpretation of higher order function calls
Date: 
Message-ID: <4e7fe8a9-bc09-4291-9284-1c7b9dfe429b@l28g2000prd.googlegroups.com>
Got it. Thanks for the clear explanation.

-Trystan
From: Pascal J. Bourguignon
Subject: Re: Question on interpretation of higher order function calls
Date: 
Message-ID: <87lk0lqu4q.fsf@hubble.informatimago.com>
·······@trystan.org writes:

> Hi all, I'm fairly new to lisp but have some experience in other
> languages supporting functions as first class values, higher order
> functions, etc. Upon diving into Lisp, I expected the following to
> work (where fun is some function).
>
> (defun (fun)
>    (fun)
> )
>
> However, I found that what I needed was.
>
> (defun (fun)
>    (funcall fun)
> )
>
> I'm guessing this has something to do with the chapter on symbols that
> I didn't read carefully enough ;-) However, I'm having trouble seeing
> a case where I would want to do something with 'fun' other than call
> it, so why the extra syntax required by default?

But that's exactly the point, given a symbol there is a lot of things
you can do with it in Common Lisp.  Here is all you can do with a
single symbol named HAHA:

                   
(defun haha () 1)
(defclass haha () ((haha :initform 2)))
(let ((haha 3))
  (let ((haha 33)) (declare (special haha))
   (flet ((haha () 4))
    (block haha
      (catch 'haha
        (tagbody
           (if (zerop haha) (go haha))
           (print '(it was not zero))
           (show (global-value 'haha) haha (symbol-value 'haha) 
                 (haha) (funcall (function haha)) (funcall 'haha)
                 (slot-value (make-instance 'haha) 'haha))
           (throw 'haha nil)
         haha
           (print '(it was  zero))
           (show haha (symbol-value 'haha)
                 (haha) (funcall (function haha)) (funcall 'haha)
                 (slot-value (make-instance 'haha) 'haha))
           (return-from haha t)))))))


A symbol such as HAHA denotes:
- a lexical variable,
- a special variable,
- a symbol macro,
- a global function (or macro),
- a local function (or macro),
- a block name,
- a catch tag,
- a tagbody label,
- a class and/or a type,
- a slot name,
- and more, I probably forgot a couple.



> Can someone shed some light on why funcall is needed rather than being
> assumed?

Because it's possible and very meaningful to do something else:

(defun foo () (print :global-function-foo))
(defun haha () (print :global-function-haha))
(flet ((haha () (print :local-function-haha)))
   (flet ((fun (haha) 
            (haha)
            (funcall haha)
            (funcall 'haha)))
    (fun (function foo))
    (values)))

prints:

:LOCAL-FUNCTION-HAHA 
:GLOBAL-FUNCTION-FOO 
:GLOBAL-FUNCTION-HAHA 



-- 
__Pascal Bourguignon__                     http://www.informatimago.com/

This is a signature virus.  Add me to your signature and help me to live.
From: Vassil Nikolov
Subject: Re: Question on interpretation of higher order function calls
Date: 
Message-ID: <snzskutnd80.fsf@luna.vassil.nikolov.name>
On Tue, 1 Jul 2008 11:15:29 -0700 (PDT), ·······@trystan.org said:
| ...
| Can someone shed some light on why funcall is needed rather than being
| assumed?

  Has nobody pointed to "Technical Issues of Separation in Function
  Cells and Value Cells" by Richard Gabriel and Kent Pitman yet?  It
  is practically required (advanced) reading on this matter in order
  to grasp it in depth.

  <http://www.dreamsongs.com/Separation.html> (Richard Gabriel's site)
  <http://www.nhplace.com/kent/Papers/Technical-Issues.html> (Kent Pitman's site)

  ---Vassil.


-- 
Peius melius est.  ---Ricardus Gabriel.
From: Rainer Joswig
Subject: Re: Question on interpretation of higher order function calls
Date: 
Message-ID: <joswig-C78E99.09142302072008@news-europe.giganews.com>
In article <···············@luna.vassil.nikolov.name>,
 Vassil Nikolov <···············@pobox.com> wrote:

> On Tue, 1 Jul 2008 11:15:29 -0700 (PDT), ·······@trystan.org said:
> | ...
> | Can someone shed some light on why funcall is needed rather than being
> | assumed?
> 
>   Has nobody pointed to "Technical Issues of Separation in Function
>   Cells and Value Cells" by Richard Gabriel and Kent Pitman yet?  It
>   is practically required (advanced) reading on this matter in order
>   to grasp it in depth.

Sure, but not every 'beginner' may want to grasp "TECHNICAL ISSUES of
Separation in Function Cells and Value Cells" in depth.

How about something like an FAQ entry: "When and why do I have to use FUNCALL?".

Unfortunately we don't have a maintained FAQ right now. I should be in some
(existing) wiki (ALU, CLIKI, ...) and could easily maintained.

There is an old FAQ:  http://www.faqs.org/faqs/lisp-faq/part2/section-5.html


> 
>   <http://www.dreamsongs.com/Separation.html> (Richard Gabriel's site)
>   <http://www.nhplace.com/kent/Papers/Technical-Issues.html> (Kent Pitman's site)
> 
>   ---Vassil.

-- 
http://lispm.dyndns.org/
From: Marco Antoniotti
Subject: LAMBDA-MACRO in Zetalisp (Re: Question on interpretation of higher 	order function calls)
Date: 
Message-ID: <d18bc3a5-474b-4f87-b713-2f923eb26005@m45g2000hsb.googlegroups.com>
Reading the papers (for the - how many? - nth time) I noticed the
reference to LAMBDA-MACRO.  The Liso Machine manual shed some light,
but not much.

Is there anybody who can provide a short and compelling tutorial?  (Of
course, I have in mind the usual suspects :) ).

Cheers
--
Marco




On Jul 2, 9:14 am, Rainer Joswig <······@lisp.de> wrote:
> In article <···············@luna.vassil.nikolov.name>,
>  Vassil Nikolov <···············@pobox.com> wrote:
>
> > On Tue, 1 Jul 2008 11:15:29 -0700 (PDT), ·······@trystan.org said:
> > | ...
> > | Can someone shed some light on why funcall is needed rather than being
> > | assumed?
>
> >   Has nobody pointed to "Technical Issues of Separation in Function
> >   Cells and Value Cells" by Richard Gabriel and Kent Pitman yet?  It
> >   is practically required (advanced) reading on this matter in order
> >   to grasp it in depth.
>
> Sure, but not every 'beginner' may want to grasp "TECHNICAL ISSUES of
> Separation in Function Cells and Value Cells" in depth.
>
> How about something like an FAQ entry: "When and why do I have to use FUNCALL?".
>
> Unfortunately we don't have a maintained FAQ right now. I should be in some
> (existing) wiki (ALU, CLIKI, ...) and could easily maintained.
>
> There is an old FAQ:  http://www.faqs.org/faqs/lisp-faq/part2/section-5.html
>
>
>
> >   <http://www.dreamsongs.com/Separation.html> (Richard Gabriel's site)
> >   <http://www.nhplace.com/kent/Papers/Technical-Issues.html> (Kent Pitman's site)
>
> >   ---Vassil.
>
> --http://lispm.dyndns.org/
From: Vassil Nikolov
Subject: Re: LAMBDA-MACRO in Zetalisp (Re: Question on interpretation of higher  order function calls)
Date: 
Message-ID: <snzod5go3d3.fsf@luna.vassil.nikolov.name>
On Wed, 2 Jul 2008 04:08:57 -0700 (PDT), Marco Antoniotti <·······@gmail.com> said:

| Reading the papers (for the - how many? - nth time) I noticed the
| reference to LAMBDA-MACRO.  The Liso Machine manual shed some light,
| but not much.

| Is there anybody who can provide a short and compelling tutorial?  (Of
| course, I have in mind the usual suspects :) ).

  Pending that, does what you found in that manual match the section
  starting with

    Date: Wednesday, 22 September 1982, 02:27-EDT
    From: Howard I. Cannon <HIC at SCRC-TENEX at MIT-MC>

  in <http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/doc/history/cl.txt>?

  (So it seems to me that, roughly speaking, a LAMBDA-MACRO is a macro
  facility for lambda expressions (and clearly unrelated from the
  LAMBDA macro---punctuation and font style (or letter case as a crude
  surrogate) matter!).)

  *        *        *

  By the way...  One always finds _something_ when searching; in this
  case, I found a patent in this broad subject area, whose description
  mentions "lambdamacro":
  <http://www.patentstorm.us/patents/5734907/description.html>#/lambdamacro/.

  ---Vassil.


-- 
Peius melius est.  ---Ricardus Gabriel.
From: Kent M Pitman
Subject: Re: LAMBDA-MACRO in Zetalisp (Re: Question on interpretation of higher  order function calls)
Date: 
Message-ID: <uwsjxqs1a.fsf@nhplace.com>
Vassil Nikolov <···············@pobox.com> writes:

> On Wed, 2 Jul 2008 04:08:57 -0700 (PDT), Marco Antoniotti <·······@gmail.com> said:
> 
> | Reading the papers (for the - how many? - nth time) I noticed the
> | reference to LAMBDA-MACRO.  The Liso Machine manual shed some light,
> | but not much.
> 
> | Is there anybody who can provide a short and compelling tutorial?  (Of
> | course, I have in mind the usual suspects :) ).
> 
>   Pending that, does what you found in that manual match the section
>   starting with
> 
>     Date: Wednesday, 22 September 1982, 02:27-EDT
>     From: Howard I. Cannon <HIC at SCRC-TENEX at MIT-MC>
> 
>   in <http://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/doc/history/cl.txt>?
> 
>   (So it seems to me that, roughly speaking, a LAMBDA-MACRO is a macro
>   facility for lambda expressions (and clearly unrelated from the
>   LAMBDA macro---punctuation and font style (or letter case as a crude
>   surrogate) matter!).)

Yes, sort of.  Specifically, it was a macro intended to apply to 
otherwise-syntactically-invalid expressions in the car of a form that
would expand them into expressions that were syntactically valid, just
as macros do the same for things in expression position (very loosely
speaking, in the cadr of forms).

I don't recall if lambda macros were expanded in the function special
form, but I sort of doubt it.

Note, btw, that the LispM had &quote and &eval as things that could be
in a bound variable list, so it was possible to implement even NLAMBDA
(the Interlisp variant of LAMBDA that did not evaluate its arguments)
using this facility.  However, as explained in my 1980 paper on fexprs,
fexprs (and &quote) were notoriously difficult to compile, so that was
perhaps overpowerful.

Nevertheless, assuming &quote is left out of it, I actually favored
(and perhaps even proposed, though if I did it was turned down--I
don't recall) having lambda macros in CL; it was thought to be just to
much featurism, I think, by some, where I personally didn't see it as
featurism so much as naturally required by the nature of the CL
language since the syntactic space is not completely programmable
without it.

It was the kind of thing you needed to be able to shadow LAMBDA with an
alternate LAMBDA in order to make things like ISLISP work in a truly
correct fashion in all cases.  Likewise, Scheme's notations like 
(LAMBDA (X . Y) ...) would have been possible to support straightforwardly
even in the car-of-form case if you had lambda macros.

Ah well...
From: Rainer Joswig
Subject: Re: LAMBDA-MACRO in Zetalisp (Re: Question on interpretation of higher order function calls)
Date: 
Message-ID: <joswig-6F2677.13365102072008@news-europe.giganews.com>
In article 
<····································@m45g2000hsb.googlegroups.com>,
 Marco Antoniotti <·······@gmail.com> wrote:

> Reading the papers (for the - how many? - nth time) I noticed the
> reference to LAMBDA-MACRO.  The Liso Machine manual shed some light,
> but not much.
> 
> Is there anybody who can provide a short and compelling tutorial?  (Of
> course, I have in mind the usual suspects :) ).

Haven't used it, but it seems that you can define your own variants
of the LAMBDA macro (hence the name).

The Symbolics doc gives the following example:

(lambda-macro ilisp (x)
  `(lambda (&optional ,@(second x) &rest ignore) . (cddr x)))

This defines ILISP as a variant of LAMBDA, where all args are optional and
extra arguments are ignore (like in Interlisp).

(funcall #'(ilisp (x y z) (list x y z)) 1 2)  -> (1 2 NIL)




> 
> Cheers
> --
> Marco
> 
> 
> 
> 
> On Jul 2, 9:14�am, Rainer Joswig <······@lisp.de> wrote:
> > In article <···············@luna.vassil.nikolov.name>,
> > �Vassil Nikolov <···············@pobox.com> wrote:
> >
> > > On Tue, 1 Jul 2008 11:15:29 -0700 (PDT), ·······@trystan.org said:
> > > | ...
> > > | Can someone shed some light on why funcall is needed rather than being
> > > | assumed?
> >
> > > � Has nobody pointed to "Technical Issues of Separation in Function
> > > � Cells and Value Cells" by Richard Gabriel and Kent Pitman yet? �It
> > > � is practically required (advanced) reading on this matter in order
> > > � to grasp it in depth.
> >
> > Sure, but not every 'beginner' may want to grasp "TECHNICAL ISSUES of
> > Separation in Function Cells and Value Cells" in depth.
> >
> > How about something like an FAQ entry: "When and why do I have to use FUNCALL?".
> >
> > Unfortunately we don't have a maintained FAQ right now. I should be in some
> > (existing) wiki (ALU, CLIKI, ...) and could easily maintained.
> >
> > There is an old FAQ: �http://www.faqs.org/faqs/lisp-faq/part2/section-5.html
> >
> >
> >
> > > � <http://www.dreamsongs.com/Separation.html> (Richard Gabriel's site)
> > > � <http://www.nhplace.com/kent/Papers/Technical-Issues.html> (Kent Pitman's site)
> >
> > > � ---Vassil.
> >
> > --http://lispm.dyndns.org/

-- 
http://lispm.dyndns.org/