From: Tj
Subject: Why isn't funcall/apply usually redundant?
Date: 
Message-ID: <ccc7084.0302191457.3eb6013d@posting.google.com>
Hi all, suppose I have:
(defun mapc-1 (f l) (dolist (x l) (FUNCALL f x)))

Why is the FUNCALL needed?  Isn't it sort of obvious if you put
something at the beginning of a list, it should be a function?  I
don't see what ambiguity is solved here.  Maybe there's a synapse not
firing straight.

Thanks for clearing my mind,
Tj

From: Paul Dietz
Subject: Re: Why isn't funcall/apply usually redundant?
Date: 
Message-ID: <3E540FCA.314D8C08@motorola.com>
Tj wrote:

> Why is the FUNCALL needed?  Isn't it sort of obvious if you put
> something at the beginning of a list, it should be a function?  I
> don't see what ambiguity is solved here.  Maybe there's a synapse not
> firing straight.

Ask yourself what this does:

(defun kar (x) (car x))

(let ((kar #'(lambda (y) (cdr y))))
  (kar '(a . b)))
==> ?

(Keywords: Lisp-1 vs. Lisp-2)

	Paul
From: Matthew Danish
Subject: Re: Why isn't funcall/apply usually redundant?
Date: 
Message-ID: <20030219181430.B22536@lain.cheme.cmu.edu>
On Wed, Feb 19, 2003 at 02:57:14PM -0800, Tj wrote:
> Hi all, suppose I have:
> (defun mapc-1 (f l) (dolist (x l) (FUNCALL f x)))
> 
> Why is the FUNCALL needed?  Isn't it sort of obvious if you put
> something at the beginning of a list, it should be a function?  I
> don't see what ambiguity is solved here.  Maybe there's a synapse not
> firing straight.
> 
> Thanks for clearing my mind,

You are right.  It is obvious that it should be a function.  And Lisp
will go looking for a function named F, and it won't find one (assuming
you haven't defined any functions named F).  The F parameter of your
function is a variable, not a function, but it is bound to a
function-value.  In order to obtain the value of the variable binding of
F, you cannot place it in a place where Lisp expects a function.
Therefore, FUNCALL.

Consider this arbitrary example:

(defun f (f n)
  (if (zerop n)
    (funcall f n)
    (funcall f (f f (1- n)))))

(f #'1+ 10)

Note the difference between F used as a function and F used as a
variable.

-- 
; Matthew Danish <·······@andrew.cmu.edu>
; OpenPGP public key: C24B6010 on keyring.debian.org
; Signed or encrypted mail welcome.
; "There is no dark side of the moon really; matter of fact, it's all dark."
From: Frode Vatvedt Fjeld
Subject: Re: Why isn't funcall/apply usually redundant?
Date: 
Message-ID: <2hznoruawc.fsf@vserver.cs.uit.no>
··········@yahoo.com (Tj) writes:

> Hi all, suppose I have:
> (defun mapc-1 (f l) (dolist (x l) (FUNCALL f x)))
>
> Why is the FUNCALL needed?

Funcall is needed so that you can rename the variable "f" to
"function" without having to worry about the presence of the special
operator function, or anything else that lives in the function
name-space.

-- 
Frode Vatvedt Fjeld
From: Tj
Subject: Re: Why isn't funcall/apply usually redundant?
Date: 
Message-ID: <ccc7084.0302200229.5e666daf@posting.google.com>
Thanks for everyone's fast responses!  FYI, I didn't realize that this
chnage would defeat the whole purpose of a lisp-2.  I guess I didn't
think through to consequences.

Tj


··········@yahoo.com (Tj) wrote in message news:<···························@posting.google.com>...
> [...]
> Why is the FUNCALL needed?  [...]
> 
> Thanks for clearing my mind,
> Tj