From: Svein Ove Aas
Subject: Destructuring setf?
Date: 
Message-ID: <c9qnbl$lji$1@services.kq.no>
The purpose of the following code should be reasonably obvious, but I'm
wondering: Is there a way to do it that doesn't involve me using loop for
something that clearly has nothing to do with looping?

(let ((left-rotated '((1 2 3) 4 5)))
   (loop for ((a b c) d e) on left-rotated
       return (list a b (list c d e))))

=> (1 2 (3 4 5))

From: Jeremy Yallop
Subject: Re: Destructuring setf?
Date: 
Message-ID: <slrncc1of9.osc.jeremy@gola.cl.cam.ac.uk>
Svein Ove Aas wrote:
> The purpose of the following code should be reasonably obvious, but I'm
> wondering: Is there a way to do it that doesn't involve me using loop for
> something that clearly has nothing to do with looping?
> 
> (let ((left-rotated '((1 2 3) 4 5)))
>    (loop for ((a b c) d e) on left-rotated
>        return (list a b (list c d e))))

  (let ((left-rotated '((1 2 3) 4 5)))
    (destructuring-bind ((a b c) d e)
        left-rotated
      (list a b (list c d e))))

Jeremy.
From: Svein Ove Aas
Subject: Re: Destructuring setf?
Date: 
Message-ID: <c9qo38$nnv$2@services.kq.no>
Jeremy Yallop wrote:

> Svein Ove Aas wrote:
>> The purpose of the following code should be reasonably obvious, but I'm
>> wondering: Is there a way to do it that doesn't involve me using loop
>> for something that clearly has nothing to do with looping?
>> 
>> (let ((left-rotated '((1 2 3) 4 5)))
>>    (loop for ((a b c) d e) on left-rotated
>>        return (list a b (list c d e))))
> 
>   (let ((left-rotated '((1 2 3) 4 5)))
>     (destructuring-bind ((a b c) d e)
>         left-rotated
>       (list a b (list c d e))))
> 
Ooh, thanks.

1 symbol down, only 950 to go...
From: Kalle Olavi Niemitalo
Subject: Re: Destructuring setf?
Date: 
Message-ID: <87wu2m5l9y.fsf@Astalo.kon.iki.fi>
Jeremy Yallop <······@jdyallop.freeserve.co.uk> writes:

> Svein Ove Aas wrote:
>>    (loop for ((a b c) d e) on left-rotated

>     (destructuring-bind ((a b c) d e)

There are some differences between these types of destructuring.

DESTRUCTURING-BIND should signal an error if a data list is too
short.  LOOP binds variables to NIL instead.

DESTRUCTURING-BIND recognizes lambda list keywords.  To LOOP,
they are just symbols.  I once wanted to

  (loop for (english-whole english-root foreign-parts foreign-whole
             &key lang ref obs arc) in *word-list*
        collect (make-instance 'word
                               :english-whole english-whole
                               :english-root english-root
                               :foreign-parts foreign-parts
                               :foreign-whole foreign-whole
                               :foreign-language lang
                               :references (designated-list ref)
                               :obsoletep obs
                               :archaicp arc)))

but had to do the destructuring with a separate DESTRUCTURING-BIND.
From: Svein Ove Aas
Subject: Re: Destructuring setf?
Date: 
Message-ID: <c9qo1r$nnv$1@services.kq.no>
Svein Ove Aas wrote:

> The purpose of the following code should be reasonably obvious, but I'm
> wondering: Is there a way to do it that doesn't involve me using loop
> for something that clearly has nothing to do with looping?
> 
> (let ((left-rotated '((1 2 3) 4 5)))
>    (loop for ((a b c) d e) on left-rotated
>        return (list a b (list c d e))))
> 
> => (1 2 (3 4 5))

I might add the following: Are there any gotchas with using backquote
instead of list, in this case?

Any sharing of structure with `(,a ,b (,c ,d ,e))?
From: Rahul Jain
Subject: Re: Destructuring setf?
Date: 
Message-ID: <87smda4yx1.fsf@nyct.net>
Svein Ove Aas <··············@brage.info> writes:

> I might add the following: Are there any gotchas with using backquote
> instead of list, in this case?
>
> Any sharing of structure with `(,a ,b (,c ,d ,e))?

There aren't any cons cells with both elements constant, so there can't be
any sharing.

-- 
Rahul Jain
·····@nyct.net
Professional Software Developer, Amateur Quantum Mechanicist