From: Rob Browning <rlb@defaultvalue.org>
Cc: guile-devel@gnu.org
Subject: Re: srfi-1 take and drop
Date: Thu, 08 May 2003 11:35:10 -0500 [thread overview]
Message-ID: <874r45s8g1.fsf@raven.i.defaultvalue.org> (raw)
In-Reply-To: <m31xz9h0y6.fsf@multivac.cwru.edu> (Paul Jarc's message of "Thu, 08 May 2003 12:12:11 -0400")
prj@po.cwru.edu (Paul Jarc) writes:
> Rob Browning <rlb@defaultvalue.org> wrote:
>> Yep, I have a "take" I haven't committed yet that avoids both stack
>> growth and reverse! by tracking the end pair...
>
> Are you using (ice-9 q)? It seems to be the right tool for that job.
Nope. Didn't even know that was there. I had just done this as a
first pass:
(define (take lst k)
;; avoid a reverse! or stack growth -- easy on the cache,
;; hard on the eyes...
(cond
((zero? k) '())
((negative? k) (error "negative count in call to take."))
(else
(let ((result (cons (car lst) '())))
(let lp ((n (- k 1)) (rest (cdr lst)) (end-pair result))
(if (zero? n)
result
(let ((new-end (cons (car rest) '())))
(set-cdr! end-pair new-end)
(lp (- n 1) (cdr rest) new-end))))))))
though thanks for pointing out (ice-9 q). That might be a better idea...
--
Rob Browning
rlb @defaultvalue.org, @linuxdevel.com, and @debian.org
Previously @cs.utexas.edu
GPG starting 2002-11-03 = 14DD 432F AE39 534D B592 F9A0 25C8 D377 8C7E 73A4
_______________________________________________
Guile-devel mailing list
Guile-devel@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-devel
prev parent reply other threads:[~2003-05-08 16:35 UTC|newest]
Thread overview: 10+ messages / expand[flat|nested] mbox.gz Atom feed top
2003-05-05 23:14 srfi-1 take and drop Kevin Ryde
2003-05-06 1:30 ` Rob Browning
2003-05-06 1:58 ` Kevin Ryde
2003-05-06 3:02 ` Rob Browning
2003-05-06 3:04 ` Rob Browning
2003-05-08 0:00 ` Kevin Ryde
2003-05-08 16:37 ` Rob Browning
2003-05-09 22:38 ` Kevin Ryde
2003-05-08 16:12 ` Paul Jarc
2003-05-08 16:35 ` Rob Browning [this message]
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=874r45s8g1.fsf@raven.i.defaultvalue.org \
--to=rlb@defaultvalue.org \
--cc=guile-devel@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).