unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
* make-hash-table: Wrong type argument
@ 2008-07-09  8:34 Shakthi Kannan
  2008-07-10  7:35 ` Ludovic Courtès
  0 siblings, 1 reply; 2+ messages in thread
From: Shakthi Kannan @ 2008-07-09  8:34 UTC (permalink / raw
  To: guile-user

Hi,

Newbie here. I am trying to pass key/value to a procedure to add it to
the hash-table. It fails at:

"you"ERROR: In procedure hash_fn_create_handle_x:
ERROR: Wrong type argument in position 1: "foo"

=== BEGIN ===

#!/usr/local/bin/guile -s
-e main -s
!#
(use-modules (ice-9 rdelim))

(define make-dictionary
  (lambda (name size)
    (lambda ()
      (define name (make-hash-table size)))))

(define add-to-dictionary
  (lambda (table key value)
      (write value)
      (hash-set! table key value)))

(define (main args)
     (make-dictionary "foo" 4)
    (add-to-dictionary "foo" 'u "you")
    )

=== END ===

What am I missing? Is this abstraction ok?

Thanks!

SK

-- 
Shakthi Kannan
http://www.shakthimaan.com




^ permalink raw reply	[flat|nested] 2+ messages in thread

* Re: make-hash-table: Wrong type argument
  2008-07-09  8:34 make-hash-table: Wrong type argument Shakthi Kannan
@ 2008-07-10  7:35 ` Ludovic Courtès
  0 siblings, 0 replies; 2+ messages in thread
From: Ludovic Courtès @ 2008-07-10  7:35 UTC (permalink / raw
  To: guile-user

Hi,

"Shakthi Kannan" <shakthimaan@gmail.com> writes:

> Newbie here. I am trying to pass key/value to a procedure to add it to
> the hash-table. It fails at:
>
> "you"ERROR: In procedure hash_fn_create_handle_x:
> ERROR: Wrong type argument in position 1: "foo"

Note: If you run Guile with `--debug', you should get a nice backtrace
here.

The problem is that you pass `hash-set!' the string "foo" as its first
argument, while it expects a hash table (as returned by
`make-hash-table').

I think there is some confusion:

> (define make-dictionary
>   (lambda (name size)
>     (lambda ()
>       (define name (make-hash-table size)))))

`define' here is an "internal define", i.e., it defines a variable
that's local to the lambda where it occurs.  Furthermore, `name' is
taken literally, it's not substituted by the actual parameter passed to
`make-dictionary'.

Hope this helps,
Ludovic.





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2008-07-10  7:35 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2008-07-09  8:34 make-hash-table: Wrong type argument Shakthi Kannan
2008-07-10  7:35 ` Ludovic Courtès

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).