unofficial mirror of guile-devel@gnu.org 
 help / color / mirror / Atom feed
From: William ML Leslie <william.leslie.ttg@gmail.com>
To: Jan Nieuwenhuizen <janneke@gnu.org>
Cc: guile-devel <guile-devel@gnu.org>
Subject: Re: take! 0==1?
Date: Fri, 12 Jul 2013 17:42:02 +1000	[thread overview]
Message-ID: <CAHgd1hGXXWrH9hxDeP02v0oHvc4XD84w9sLCynSGM_G3Cg+ePA@mail.gmail.com> (raw)
In-Reply-To: <87fvvkz1ui.fsf@nlvehvbe01nb29b.ddns.nl-htc01.nxp.com>

On 12 July 2013 17:14, Jan Nieuwenhuizen <janneke@gnu.org> 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 <janneke@gnu.org> | GNU LilyPond http://lilypond.org
> Freelance IT http://JoyofSource.com | Avatar®  http://AvatarAcademy.nl

--
William Leslie

Notice:
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	other threads:[~2013-07-12  7:42 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-07-12  7:14 take! 0==1? Jan Nieuwenhuizen
2013-07-12  7:42 ` William ML Leslie [this message]
2013-07-12  7:57 ` William ML Leslie
2013-07-12 16:57   ` Resolved: ! often means may, not will [WAS: Re: take! 0==1?] Jan Nieuwenhuizen

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

  List information: https://www.gnu.org/software/guile/

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=CAHgd1hGXXWrH9hxDeP02v0oHvc4XD84w9sLCynSGM_G3Cg+ePA@mail.gmail.com \
    --to=william.leslie.ttg@gmail.com \
    --cc=guile-devel@gnu.org \
    --cc=janneke@gnu.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).