From: Spiros Bousbouras
Subject: An example on the FUNCALL page
Date: 
Message-ID: <41e79822-6c29-4356-9507-218eaff92f07@m1g2000pre.googlegroups.com>
On the FUNCALL page of the HS the following example
appears:

 (flet ((cons (x y) `(kons ,x ,y)))
   (let ((cons (symbol-function '+)))
     (funcall #'cons
              (funcall 'cons 1 2)
              (funcall cons 1 2))))
=>  (KONS (1 . 2) 3)

On SBCL it causes an error. Is the code correct or is
redefining cons undefined behaviour ?

Would the point of the example be illustrated by the
following code ?

 (defun new-cons (x y) (cons x y))
 (flet ((new-cons (x y) `(kons ,x ,y)))
   (let ((new-cons (symbol-function '+)))
     (funcall #'new-cons
              (funcall 'new-cons 1 2)
              (funcall new-cons 1 2))))
=>  (KONS (1 . 2) 3)

From: Kaz Kylheku
Subject: Re: An example on the FUNCALL page
Date: 
Message-ID: <75f227f7-8c5e-4d66-8029-6e9e5316a1ed@w5g2000prd.googlegroups.com>
On Apr 8, 11:31 am, Spiros Bousbouras <······@gmail.com> wrote:
> On the FUNCALL page of the HS the following example
> appears:
>
>  (flet ((cons (x y) `(kons ,x ,y)))
>    (let ((cons (symbol-function '+)))
>      (funcall #'cons
>               (funcall 'cons 1 2)
>               (funcall cons 1 2))))
> =>  (KONS (1 . 2) 3)

Gack, this is undefined behavior. You can't redefine standard Lisp
functions, not even lexically with flet.

Standard CL macros are allowed to generate code which freely calls
standard library functions. (I.e. hygiene is not required).

If you redefine a function, particularly something as fundamental as
CONS, then all bets are off about any macros continuing to work
properly in that scope.
From: Kent M Pitman
Subject: Re: An example on the FUNCALL page
Date: 
Message-ID: <ubq4k0x4d.fsf@nhplace.com>
Kaz Kylheku <········@gmail.com> writes:

> On Apr 8, 11:31 am, Spiros Bousbouras <······@gmail.com> wrote:
> > On the FUNCALL page of the HS the following example
> > appears:
> >
> >  (flet ((cons (x y) `(kons ,x ,y)))
> >    (let ((cons (symbol-function '+)))
> >      (funcall #'cons
> >               (funcall 'cons 1 2)
> >               (funcall cons 1 2))))
> > =>  (KONS (1 . 2) 3)
> 
> Gack, this is undefined behavior. You can't redefine standard Lisp
> functions, not even lexically with flet.

Heh.  Yeah it does seem to violate 11.1.2.1.2.

But, well, that's why there's 1.4.3 ... I was quite afraid that I'd
make mistakes doing examples, and yet I thought examples were
important, so I lowered the bar for making examples correct so that if
I goofed up, people couldn't say the example somehow negated the
definition.

Probably what happened in this case is that we put in the restrictions
on the CL package after we put in the example, and no one reviewing it
caught the fact that there were already examples in conflict with that.
From: John Thingstad
Subject: Re: An example on the FUNCALL page
Date: 
Message-ID: <op.t9a2gxjaut4oq5@pandora.alfanett.no>
P� Tue, 08 Apr 2008 20:31:29 +0200, skrev Spiros Bousbouras  
<······@gmail.com>:

> On the FUNCALL page of the HS the following example
> appears:
>
>  (flet ((cons (x y) `(kons ,x ,y)))
>    (let ((cons (symbol-function '+)))
>      (funcall #'cons
>               (funcall 'cons 1 2)
>               (funcall cons 1 2))))
> =>  (KONS (1 . 2) 3)
>
> On SBCL it causes an error. Is the code correct or is
> redefining cons undefined behaviour ?
>
> Would the point of the example be illustrated by the
> following code ?
>
>  (defun new-cons (x y) (cons x y))
>  (flet ((new-cons (x y) `(kons ,x ,y)))
>    (let ((new-cons (symbol-function '+)))
>      (funcall #'new-cons
>               (funcall 'new-cons 1 2)
>               (funcall new-cons 1 2))))
> =>  (KONS (1 . 2) 3)

Redefining behaviour is generally bad practice.
However this works in LispWoks.

(defpackage my-user
   (shaddow cons))
  (flet ((cons (x y) `(kons ,x ,y)))
    (let ((cons (symbol-function '+)))
      (funcall #'cons
               (funcall 'cons 1 2)
               (funcall cons 1 2))))

I still seem to get a redefining cons in SBCL.
This seems to be contrary to the spec.

--------------
John Thingstad
From: John Thingstad
Subject: Re: An example on the FUNCALL page
Date: 
Message-ID: <op.t9a2mqesut4oq5@pandora.alfanett.no>
P� Tue, 08 Apr 2008 20:47:11 +0200, skrev John Thingstad  
<·······@online.no>:

> Redefining behaviour is generally bad practice.
> However this works in LispWoks.
>
> (defpackage my-user
>    (shaddow cons))
>   (flet ((cons (x y) `(kons ,x ,y)))
>     (let ((cons (symbol-function '+)))
>       (funcall #'cons
>                (funcall 'cons 1 2)
>                (funcall cons 1 2))))
>
> I still seem to get a redefining cons in SBCL.
> This seems to be contrary to the spec.

Don't know what happened when I pasted this..
:my-user and "cons"

--------------
John Thingstad