unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Christopher Cramer <crayc@pyro.net>
Subject: Re: functional hash operations
Date: Tue, 31 Dec 2002 18:48:36 -0600	[thread overview]
Message-ID: <20021231184836.A22199@kiwi.pyrotechnics.com> (raw)
In-Reply-To: <m3ptrhria4.fsf@multivac.cwru.edu>; from prj@po.cwru.edu on Tue, Dec 31, 2002 at 04:26:53PM -0500

On Tue, Dec 31, 2002 at 04:26:53PM -0500, Paul Jarc wrote:
> (define (hash-add table key val)
>   (let ((new-table (list->vector (vector->list table)))
>         (index (hash key (vector-length table))))
>     (vector-set! new-table index `((,key . ,val) . ,(vector-ref table index)))
>     new-table))
> 
> This shares the keys, the values, the association pairs, and the list
> pairs between the two tables.  (BTW, is there a better way to copy a
> vector?)

A better way would be to use vector-move-left! or vector-move-right!:

(define (vector-copy v)
    (let* ((len (vector-length v)) (new (make-vector len)))
	(vector-move-left! v 0 len new 0)
	new))

But I hope you aren't copying a hash table in time-critical code to
begin with.

-- 
Christopher Cramer <crayc@pyro.net> <http://www.pyro.net/~crayc/>
"All you have to do is tell them they are being attacked and denounce the
pacifists for lack of patriotism and exposing the country to danger. It
works the same way in any country." - Hermann Georing, 1946


_______________________________________________
Guile-user mailing list
Guile-user@gnu.org
http://mail.gnu.org/mailman/listinfo/guile-user


  reply	other threads:[~2003-01-01  0:48 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2002-12-30 23:29 functional hash operations Paul Jarc
2002-12-31  0:41 ` Thien-Thi Nguyen
2002-12-31 21:26   ` Paul Jarc
2003-01-01  0:48     ` Christopher Cramer [this message]
2003-01-02  6:18       ` Paul Jarc
2002-12-31 12:38 ` Christopher Cramer
2003-01-01 21:47 ` Marius Vollmer
2003-01-02 19:09   ` Paul Jarc

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=20021231184836.A22199@kiwi.pyrotechnics.com \
    --to=crayc@pyro.net \
    /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).