[Top][All Lists]

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: take! 0==1?

From: William ML Leslie
Subject: Re: take! 0==1?
Date: Fri, 12 Jul 2013 17:42:02 +1000

On 12 July 2013 17:14, Jan Nieuwenhuizen <address@hidden> wrote:
> Hi,
> Reading the documentation of take!
>     -- Scheme Procedure: take lst i
>     -- Scheme Procedure: take! lst i
>         Return a list containing the first I elements of LST.
>         `take!' may modify the structure of the argument list LST in order
>         to produce the result.
> its behaviour surpsises me.
> For list LST, (take! lst 0) leaves LST in the same state
> as (take! lst 1) does.  Worse, the return value suggests
> that it worked

Well, there's no pair that can be mutated in (take! lst 0), and (take!
lst n) where n is the length of the list is just like setting the nth
cdr to nil, which it already is.  Have I understood this correctly?

>     scheme@(guile-user)> (use-modules (srfi srfi-1))
>     scheme@(guile-user)> (define lst '(a))
>     scheme@(guile-user)> (take! lst 0)
>     $4 = ()
>     scheme@(guile-user)> lst
>     $5 = (a)
>     scheme@(guile-user)> (take! lst 1)
>     $6 = (a)
>     scheme@(guile-user)> lst
>     $7 = (a)
>     scheme@(guile-user)>
> How are you doing such things?  Is anyone using take! at all to reduce a
> list to n elements?  Using list-cdr-set! and set!/list-set! also seems a bit
> clumsy.
> Greetings, Jan
> --
> Jan Nieuwenhuizen <address@hidden> | GNU LilyPond
> Freelance IT | AvatarĀ®

William Leslie

Likely much of this email is, by the nature of copyright, covered
under copyright law.  You absolutely may reproduce any part of it in
accordance with the copyright law of the nation you are reading this
in.  Any attempt to deny you those rights would be illegal without
prior contractual agreement.

reply via email to

[Prev in Thread] Current Thread [Next in Thread]