unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Stephen Compall <s11@member.fsf.org>
To: Jon Wilson <j85wilson@fastmail.fm>
Cc: Guile Users <guile-user@gnu.org>
Subject: Re: hash-get-handle and hash-ref redundant
Date: Fri, 29 Jun 2007 22:16:04 -0500	[thread overview]
Message-ID: <1183173364.11558.61.camel@nocandy.dyndns.org> (raw)
In-Reply-To: <46857077.7080808@fastmail.fm>


[-- Attachment #1.1: Type: text/plain, Size: 1635 bytes --]

On Fri, 2007-06-29 at 16:49 -0400, Jon Wilson wrote:
> The procedure hash-get-handle seems to be a less useful version of hash-ref.

Not exactly true:

guile> (define my-ht (make-hash-table))
guile> (hash-set! my-ht 'x 'y)
y
guile> (eq? (hash-get-handle my-ht 'x) (hash-get-handle my-ht 'x))
#t
guile> (set-cdr! (hash-get-handle my-ht 'x) 'z)
guile> (hash-ref my-ht 'x)
z

Their nature is explained in prose at the top of (guile)Hash Table
Reference.

> Perhaps one is meant to be used only internally?  I'm guessing that 
> hash-get-handle should not be visible.  If the developers concur, let's 
> make this change before 1.8.2.

You can use it either to cache HT lookups for faster writes, or use them
as variable bindings similarly to how traditional Smalltalk-80 systems
use Dictionary Associations to represent global and pool variables, or:

(define (make-hash-list)
  "Answer a hash-list, an HT that defaults all values to '() and
makes it easy to add values."
  (make-hash-table))

(define (hash-list-add! ht key item)
  (let ((assoc (hash-create-handle! ht key '())))
    (set-cdr! assoc (cons item (cdr assoc)))))

(define (hash-list-ref ht key)
  (hash-ref ht key '()))

;; I recently wrote a script that would have seriously benefited
;; in clarity from such a structure.

-- 
;;; Stephen Compall ** http://scompall.nocandysw.com/blog **
"Peta" is Greek for fifth; a petabyte is 10 to the fifth power, as
well as fifth in line after kilo, mega, giga, and tera.
  -- Lee Gomes, performing every Wednesday in his tech column
     "Portals" on page B1 of The Wall Street Journal

[-- Attachment #1.2: This is a digitally signed message part --]
[-- Type: application/pgp-signature, Size: 189 bytes --]

[-- Attachment #2: Type: text/plain, Size: 140 bytes --]

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

  reply	other threads:[~2007-06-30  3:16 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2007-06-29 20:49 hash-get-handle and hash-ref redundant Jon Wilson
2007-06-30  3:16 ` Stephen Compall [this message]
2007-06-30  3:21   ` Jon Wilson

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=1183173364.11558.61.camel@nocandy.dyndns.org \
    --to=s11@member.fsf.org \
    --cc=guile-user@gnu.org \
    --cc=j85wilson@fastmail.fm \
    /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).