From: Bob Felts
Subject: Question about constantly
Date: 
Message-ID: <1i5mrbo.1uqtjuqfsviogN%wrf3@stablecross.com>
Suppose I define *foo* as follows:

  (defparameter *foo* (lambda (&rest args) (values 1 2)))

Then (funcall *foo*) => 1, 2

Now, suppose I define *bar* as:

  (defparameter *bar* (constantly (values 1 2)))

Then (funcall *bar*) => 1

Can someone explain why there is a difference between the two?

From: Kent M Pitman
Subject: Re: Question about constantly
Date: 
Message-ID: <ud4vql225.fsf@nhplace.com>
····@stablecross.com (Bob Felts) writes:

> Suppose I define *foo* as follows:
> 
>   (defparameter *foo* (lambda (&rest args) (values 1 2)))
> 
> Then (funcall *foo*) => 1, 2
> 
> Now, suppose I define *bar* as:
> 
>   (defparameter *bar* (constantly (values 1 2)))
> 
> Then (funcall *bar*) => 1
> 
> Can someone explain why there is a difference between the two?

CONSTANTLY is a function.  It never even sees the 2 because the
2 has been discarded by the function call mechanism before CONSTANTLY
is ever called.  In that regard, it's no different than any other
function.  Consider:

(+ (values 1 2) (values 3 'banana)) => 4

LAMBDA is a special form that has a well-defined evaluation-delaying
behavior that defers evaluation of the expression until runtime, when
arguments are known and the function has been called.  This also
affects WHEN the evaluation occurs and in fact how many times the 
evaluation occurs.  Every time a LAMBDA is called, the body is executed,
where as the expression (values 1 2) given in the argument position to
CONSTANTLY is evaluated only once (prior to calling constantly) and
never again. Consider:

 (defvar *x* 3)

 (defparameter *foo* (lambda (&rest args) *x*))

 (defvar *y* 3)

 (defparameter *bar* (constantly *x*))

 (funcall *foo*) => 3
 (funcall *bar*) => 3

 (setq *x* 4)
 (setq *y* 4)

 (funcall *foo*) => 4
 (funcall *bar*) => 3
From: Bob Felts
Subject: Re: Question about constantly
Date: 
Message-ID: <1i5nrn9.1oz83sn1ntjchaN%wrf3@stablecross.com>
Kent M Pitman <······@nhplace.com> wrote:

> ····@stablecross.com (Bob Felts) writes:
> 
> > Suppose I define *foo* as follows:
> > 
> >   (defparameter *foo* (lambda (&rest args) (values 1 2)))
> > 
> > Then (funcall *foo*) => 1, 2
> > 
> > Now, suppose I define *bar* as:
> > 
> >   (defparameter *bar* (constantly (values 1 2)))
> > 
> > Then (funcall *bar*) => 1
> > 
> > Can someone explain why there is a difference between the two?
> 
> CONSTANTLY is a function.  It never even sees the 2 because the
> 2 has been discarded by the function call mechanism before CONSTANTLY
> is ever called.  In that regard, it's no different than any other
> function.  Consider:
> 
> (+ (values 1 2) (values 3 'banana)) => 4
> 

Thanks, Kent.