[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: [Chicken-users] lambda's in a hash table
From: |
Thomas Chust |
Subject: |
Re: [Chicken-users] lambda's in a hash table |
Date: |
Sat, 05 Apr 2014 02:23:32 +0200 |
User-agent: |
Mozilla/5.0 (X11; Linux x86_64; rv:24.0) Gecko/20100101 Thunderbird/24.4.0 |
On 2014-04-05 01:54, Claude Marinier wrote:
> [...]
> I would like to have the compiler do some of this for me. I probably
> cannot write a literal hash table but I expected to be able to write a
> literal association list. I have tried this but it does not work.
> [...]
> (define a-list
> `(
> (dot . ,(lambda () (display "dot\n")))
> (dash . ,(lambda () (display "dash\n")))
> ))
> [...]
Hello,
what you have written down here is not a literal list, but a
quasiquotation, which is just syntactic sugar that expands to an
expression dynamically constructing a list.
Nevertheless, the program you posted works just fine as it is. The only
problem I can see with it is that nothing visible happens because
> [...]
> (let ((func-dot (hash-table-ref dict 'dot))
> (func-dash (hash-table-ref dict 'dash)))
> func-dot
> func-dash)
> [...]
doesn't call the two procedures. To actually run the procedures, you
would have to write something like
(let ((func-dot (hash-table-ref dict 'dot))
(func-dash (hash-table-ref dict 'dash)))
(func-dot)
(func-dash))
Ciao,
Thomas
--
When C++ is your hammer, every problem looks like your thumb.