From: Burton Samograd
Subject: set-car!/cdr! in CL
Date: 
Message-ID: <87y910fhjm.fsf@kruhft.vc.shawcable.net>
Hi,

I can't seem to find the names of the functions for setting 
car and cdr of a list cell in CL (like there is in scheme).  Could
somebody enlighten me?

TIA

-- 
burton samograd
······@kruhft.dyndns.org
http://kruhftwerk.dyndns.org

From: Dorai Sitaram
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <bag6qq$l0n$1@news.gte.com>
In article <··············@kruhft.vc.shawcable.net>,
Burton Samograd  <······@hotmail.com> wrote:
>Hi,
>
>I can't seem to find the names of the functions for setting 
>car and cdr of a list cell in CL (like there is in scheme).  Could
>somebody enlighten me?

(setf (car a-list) new-car)
(setf (cdr a-list0 new-cdr)

are the CL equivalent of Scheme's

(set-car! a-list new-car)
(set-cdr! a-list new-cdr)

One could also use (in CL)

(rplaca a-list new-car)
(rplacd a-list new-cdr)

but they seem less recommended these days.
From: Burton Samograd
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <87u1bofghx.fsf@kruhft.vc.shawcable.net>
Burton Samograd <······@hotmail.com> writes:

> I can't seem to find the names of the functions for setting 
> car and cdr of a list cell in CL (like there is in scheme).  Could
> somebody enlighten me?

Thanks for the quick responses.  I actually figured it out a couple of
minutes after I posted...it's still early and I haven't finished my
coffee :)

-- 
burton samograd
······@kruhft.dyndns.org
http://kruhftwerk.dyndns.org
From: Alexander Schmolck
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <yfsn0hggv3r.fsf@black132.ex.ac.uk>
Burton Samograd <······@hotmail.com> writes:

> Hi,
> 
> I can't seem to find the names of the functions for setting 
> car and cdr of a list cell in CL (like there is in scheme).  Could
> somebody enlighten me?
> 
> TIA

rplaca and rplacd I guess, but why not just use (setf (car list) 'bar)?

'as
From: Nils Goesche
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <lyvfw4b8zj.fsf@cartan.de>
Burton Samograd <······@hotmail.com> writes:

> I can't seem to find the names of the functions for setting car and
> cdr of a list cell in CL (like there is in scheme).  Could somebody
> enlighten me?

RPLACA and RPLACD.  But normally you use SETF:

CL-USER 1 > (let ((foo (cons 2 3)))
              (setf (car foo) 42)
              foo)
(42 . 3)

Regards,
-- 
Nils G�sche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x0655CFA0
From: Raymond Wiker
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <868yt0uww6.fsf@raw.grenland.fast.no>
Burton Samograd <······@hotmail.com> writes:

> Hi,
> 
> I can't seem to find the names of the functions for setting 
> car and cdr of a list cell in CL (like there is in scheme).  Could
> somebody enlighten me?

        rplaca/rplacd

        or

        (setf (car cell) whatever)
        (setf (cdr cell) whatever)

-- 
Raymond Wiker                        Mail:  ·············@fast.no
Senior Software Engineer             Web:   http://www.fast.no/
Fast Search & Transfer ASA           Phone: +47 23 01 11 60
P.O. Box 1677 Vika                   Fax:   +47 35 54 87 99
NO-0120 Oslo, NORWAY                 Mob:   +47 48 01 11 60

Try FAST Search: http://alltheweb.com/
From: Frode Vatvedt Fjeld
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <2hd6icl2vc.fsf@vserver.cs.uit.no>
Burton Samograd <······@hotmail.com> writes:

> I can't seem to find the names of the functions for setting car and
> cdr of a list cell in CL (like there is in scheme).  Could somebody
> enlighten me?

They are called (setf car) and (setf cdr). This naming symmetry holds
for most accessor-like operators in CL.

-- 
Frode Vatvedt Fjeld
From: Erann Gat
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <gat-2105031143220001@k-137-79-50-101.jpl.nasa.gov>
In article <··············@vserver.cs.uit.no>, Frode Vatvedt Fjeld
<······@cs.uit.no> wrote:

> Burton Samograd <······@hotmail.com> writes:
> 
> > I can't seem to find the names of the functions for setting car and
> > cdr of a list cell in CL (like there is in scheme).  Could somebody
> > enlighten me?
> 
> They are called (setf car) and (setf cdr).

Hm, are they really?

? (function car)
#<Compiled-function CAR #x94C1D6>
? (function (setf car))
> Error: Undefined function: SETF::|COMMON-LISP::CAR|

That was MCL 5.0.  CLisp does the same thing.

E.
From: Joe Marshall
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <k7ckf7de.fsf@ccs.neu.edu>
···@jpl.nasa.gov (Erann Gat) writes:

> ? (function car)
> #<Compiled-function CAR #x94C1D6>
> ? (function (setf car))
> > Error: Undefined function: SETF::|COMMON-LISP::CAR|
> 
> That was MCL 5.0.  CLisp does the same thing.

Corman Lisp 1.5

?(function (setf car))
#< COMPILED-FUNCTION: #xE34010 >
From: Erann Gat
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <gat-2105031456240001@k-137-79-50-101.jpl.nasa.gov>
In article <············@ccs.neu.edu>, Joe Marshall <···@ccs.neu.edu> wrote:

> ···@jpl.nasa.gov (Erann Gat) writes:
> 
> > ? (function car)
> > #<Compiled-function CAR #x94C1D6>
> > ? (function (setf car))
> > > Error: Undefined function: SETF::|COMMON-LISP::CAR|
> > 
> > That was MCL 5.0.  CLisp does the same thing.
> 
> Corman Lisp 1.5
> 
> ?(function (setf car))
> #< COMPILED-FUNCTION: #xE34010 >

Lispworks:

CL-USER 1 > (function (setf car))

Error: Undefined function (SETF CAR) in form (FUNCTION (SETF CAR)).

So far I'm ahead 3 to 1.  ;-)

Seriously though, my reading of the standard seems to indicate that this
ought to work, but can three implementations all have the same bug?

E.
From: Wade Humeniuk
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <qQTya.11750$FC2.4377016@news1.telusplanet.net>
"Erann Gat" <···@jpl.nasa.gov> wrote in message
·························@k-137-79-50-101.jpl.nasa.gov...
> > > That was MCL 5.0.  CLisp does the same thing.
> >
> > Corman Lisp 1.5
> >
> > ?(function (setf car))
> > #< COMPILED-FUNCTION: #xE34010 >
>
> Lispworks:
>
> CL-USER 1 > (function (setf car))
>
> Error: Undefined function (SETF CAR) in form (FUNCTION (SETF CAR)).
>
> So far I'm ahead 3 to 1.  ;-)
>
> Seriously though, my reading of the standard seems to indicate that this
> ought to work, but can three implementations all have the same bug?

Lispworks,

CL-USER 23 > (defmacro functionf (func)
               (typecase func
                 (symbol `(function ,func))
                 (cons
                  (ecase (first func)
                    (setf `(symbol-function (getf (symbol-plist ',(second func))
                                                  'setf::setf-method)))))
                 (t `(function ,func))))
FUNCTIONF

CL-USER 24 > (functionf car)
#<function CAR 200CF8B2>

CL-USER 25 > (functionf (setf car))
#<function SEQ::SET-CAR 200CFA52>

CL-USER 26 > (describe 'car)

CAR is a SYMBOL
NAME          "CAR"
VALUE         #<unbound value>
FUNCTION      #<function CAR 200CF8B2>
PLIST         (SYSTEM:UNDERLYING-SETF-NAME SETF::\"COMMON-LISP\"\ \"CAR\" PKG::SYMBOL-NAME-STRING
"CAR" COMPILER::PC-FNDEFS #<COMPILER::FUNCTION-DESCRIPTOR CAR> SETF::SETF-METHOD SEQ::SET-CAR)
PACKAGE       #<PACKAGE COMMON-LISP>

CL-USER 27 >

Wade
From: Kent M Pitman
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <sfwn0hfetao.fsf@shell01.TheWorld.com>
"Wade Humeniuk" <····@nospam.nowhere> writes:

> "Erann Gat" <···@jpl.nasa.gov> wrote in message
> ·························@k-137-79-50-101.jpl.nasa.gov...
> > > > That was MCL 5.0.  CLisp does the same thing.
> > >
> > > Corman Lisp 1.5
> > >
> > > ?(function (setf car))
> > > #< COMPILED-FUNCTION: #xE34010 >
> >
> > Lispworks:
> >
> > CL-USER 1 > (function (setf car))
> >
> > Error: Undefined function (SETF CAR) in form (FUNCTION (SETF CAR)).

My reading of the language says it's non-conforming for there not to be
a (SETF CAR) function.  Probably you should send a bug report and see
what the vendor says.

As long as you've raised the issue here, though--why does it matter?  Is
there really a case where you're planning to funcall this, or are
you just caring because it's part of some test suite?  I'm not sure I've
ever seen a case where anyone wanted to funcall or map this so I'm just idly 
curious what sort of program does need to...
From: Erann Gat
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <gat-2105032154110001@192.168.1.52>
In article <···············@shell01.TheWorld.com>, Kent M Pitman
<······@world.std.com> wrote:

> "Wade Humeniuk" <····@nospam.nowhere> writes:
> 
> > "Erann Gat" <···@jpl.nasa.gov> wrote in message
> > ·························@k-137-79-50-101.jpl.nasa.gov...
> > > > > That was MCL 5.0.  CLisp does the same thing.
> > > >
> > > > Corman Lisp 1.5
> > > >
> > > > ?(function (setf car))
> > > > #< COMPILED-FUNCTION: #xE34010 >
> > >
> > > Lispworks:
> > >
> > > CL-USER 1 > (function (setf car))
> > >
> > > Error: Undefined function (SETF CAR) in form (FUNCTION (SETF CAR)).
> 
> My reading of the language says it's non-conforming for there not to be
> a (SETF CAR) function.  Probably you should send a bug report and see
> what the vendor says.
> 
> As long as you've raised the issue here, though--why does it matter?  Is
> there really a case where you're planning to funcall this, or are
> you just caring because it's part of some test suite?  I'm not sure I've
> ever seen a case where anyone wanted to funcall or map this so I'm just idly 
> curious what sort of program does need to...

This question was posed as a followup to Wade's posting, but you excised
all of Wade's text so I assume the question was addressed to me.  My
interest in this issue is purely pedagogical.

E.
From: Kent M Pitman
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <sfwn0hft37t.fsf@shell01.TheWorld.com>
···@jpl.nasa.gov (Erann Gat) writes:

> In article <···············@shell01.TheWorld.com>, Kent M Pitman
> <······@world.std.com> wrote:
> 
> > As long as you've raised the issue here, though--why does it
> > matter?  Is there really a case where you're planning to funcall
> > this, or are you just caring because it's part of some test suite?
> > I'm not sure I've ever seen a case where anyone wanted to funcall
> > or map this so I'm just idly curious what sort of program does
> > need to...
> 
> This question was posed as a followup to Wade's posting, but you excised
> all of Wade's text so I assume the question was addressed to me.  My
> interest in this issue is purely pedagogical.

Sorry.  A quirk of Unix posting.  I was just trying to reduce the redundancy
of what I posted, focusing on the text that was driving my query.  I 
appreciate your responding, but my question was open to anyone who might
answer, whether involved in the thread or not.
From: Henrik Motakef
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <87llwzdhi1.fsf@interim.henrik-motakef.de>
···@jpl.nasa.gov (Erann Gat) writes:

>> > ? (function (setf car))
>> > > Error: Undefined function: SETF::|COMMON-LISP::CAR|
>> > 
>> > That was MCL 5.0.  CLisp does the same thing.
>> 
>> Corman Lisp 1.5
>> 
>> ?(function (setf car))
>> #< COMPILED-FUNCTION: #xE34010 >
>
> Lispworks:
>
> CL-USER 1 > (function (setf car))
>
> Error: Undefined function (SETF CAR) in form (FUNCTION (SETF CAR)).
>
> So far I'm ahead 3 to 1.  ;-)

CMUCL:

* (function (setf car))
#<Function (SETF CAR) {103D36D1}>

SBCL:

* (function (setf car))
#<FUNCTION "top level local call (SETF CAR)" {106E8B05}>
From: Paul F. Dietz
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <bqWdnZ1DEeXiZFajXTWcqA@dls.net>
Erann Gat wrote:

>>They are called (setf car) and (setf cdr).
> 
> 
> Hm, are they really?
> 
> ? (function car)
> #<Compiled-function CAR #x94C1D6>
> ? (function (setf car))
> 
>>Error: Undefined function: SETF::|COMMON-LISP::CAR|
> 
> 
> That was MCL 5.0.  CLisp does the same thing.

Section 5.1.1.2:

     For each standardized accessor function F, unless it is explicitly documented
     otherwise, it is implementation-dependent whether the ability to use an F form
     as a setf place is implemented by a setf expander or a setf function. Also, it
     follows from this that it is implementation-dependent whether the name (setf F)
     is fbound.

	Paul
From: Steven M. Haflich
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <3ED2A3B2.4080403@alum.mit.edu>
Paul F. Dietz wrote:

> Section 5.1.1.2:
> 
 > For each standardized accessor function F, unless it is explicitly
 > documented otherwise, it is implementation-dependent whether the
 > ability to use an F form as a setf place is implemented by a setf
 > expander or a setf function. Also, it follows from this that it is
 > implementation-dependent whether the name (setf F) is fbound.

Precisely.  If one actually needs the function version to pass
as a functional argument somewhere there is no prohibition against
creating it, although there is a prohibition against binding it to
the name (setf car).  The lambda here is the standard idiom to
functionify a setf expansion, although the example is contrived:

     (let ((lst (mapcar #'cons '(a b c) '(1 2 3))))
       (mapc (lambda (v x) (setf (car x) v)) '(x y z) lst)
       lst)
     ==> ((x . 1) (y . 2) (z . 3))

The reason one doesn't see this so often is that it is rare to pass
a setf function as a functional argument.
From: Henrik Motakef
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <87fzn8e1nr.fsf@interim.henrik-motakef.de>
Burton Samograd <······@hotmail.com> writes:

> I can't seem to find the names of the functions for setting 
> car and cdr of a list cell in CL (like there is in scheme).  Could
> somebody enlighten me?

Use setf:

* (defvar *list* (list 1 2 3 4))
*LIST*
* (setf (car *list*) 5)
5
* *list*
(5 2 3 4)
* (setf (cdr *list*) '(6))
(6)
* *list*
(5 6)

Setf works with lots of other places as well.
From: Michael Livshin
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <s3of1wz4li.fsf@laredo.verisity.com.cmm>
Burton Samograd <······@hotmail.com> writes:

> I can't seem to find the names of the functions for setting 
> car and cdr of a list cell in CL (like there is in scheme).  Could
> somebody enlighten me?

read up on `setf' and become enlightened.

-- 
This program posts news to billions of machines throughout the galaxy.  Your
message will cost the net enough to bankrupt your entire planet.  As a result
your species will be sold into slavery.  Be sure you know what you are doing.
Are you absolutely sure you want to do this? [yn] y
From: Christopher Browne
Subject: Re: set-car!/cdr! in CL
Date: 
Message-ID: <bahg6l$sd9t3$2@ID-125932.news.dfncis.de>
After a long battle with technology,Burton Samograd <······@hotmail.com>, an earthling, wrote:
> I can't seem to find the names of the functions for setting 
> car and cdr of a list cell in CL (like there is in scheme).  Could
> somebody enlighten me?

What you need to look up is the notion of "places."

If you need to set the car of a list cell, you would typically do
something like:

> (defvar our-list '(a b c))   ;;; Set up the list
OUR-LIST
> (setf (car our-list) 1)      ;;; Set the CAR of the list to 1
1
> our-list                     ;;; New Value of list?
(1 B C)
> (setf (cdr our-list) 251)    ;;; Assign the cdr
251
> our-list                     ;;; New Value of list?
(1 . 251)

You'd more likely want to set the second value to something new...
> (setf our-list '(a b c))     ;;; Reset the list to be a list
(A B C)
> (setf (second our-list) 251)
251
> our-list
(A 251 C)

It is common for you to be able to SETF things and have it do "the
right thing."  You'd update an array element via:
 (setf (aref some-array 5) new-value-for-element-5)

Behind the scenes, this will transform into something analagous to the
Scheme vector-set! function, but you more often than not never need to
worry about such behind-the-scene details as the CL macros do it all
for you.
-- 
select 'aa454' || ·@' || 'freenet.carleton.ca';
http://cbbrowne.com/info/x.html
"I still maintain the point that designing a monolithic kernel in 1991
is  a fundamental error.   Be thankful  you are  not my  student.  You
would not get a high grade  for such a design :-)" -- Andrew Tanenbaum
to Linus Torvalds