unofficial mirror of guile-user@gnu.org 
 help / color / mirror / Atom feed
From: Tim Meehan <btmeehan@gmail.com>
To: guile-user <guile-user@gnu.org>
Subject: Somehow I have got this "thunk" thing wrong.
Date: Fri, 5 Mar 2021 18:05:20 -0600	[thread overview]
Message-ID: <CACgrOxL5X6fz9Ziohjn4hMSv_w=zUxaREVpetFdQ4xXZaGkEwg@mail.gmail.com> (raw)

I wanted to store a thunk in a hashtable so that I could look up its key
and then run it later. Something like this:

#! /usr/bin/guile
!#

(use-modules (ice-9 hash-table))

(define stuff (alist->hash-table
  '((a . (lambda () (display "event a\n")))
    (b . (lambda () (display "event b\n")))
    (c . (lambda () (display "event c\n"))))))

(define res (hash-ref stuff 'a))
(res)

But when I run it:
Wrong type to apply: (lambda () (display "event a\n"))


             reply	other threads:[~2021-03-06  0:05 UTC|newest]

Thread overview: 8+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-03-06  0:05 Tim Meehan [this message]
2021-03-06  0:26 ` Somehow I have got this "thunk" thing wrong Christopher Baines
2021-03-06  3:40   ` Tim Meehan
2021-03-06  3:43     ` Tim Meehan
2021-03-06  0:31 ` Olivier Dion via General Guile related discussions
2021-03-06  0:48   ` Aleix Conchillo Flaqué
2021-03-06 16:55   ` Taylan Kammer
2021-03-06 17:16     ` Olivier Dion via General Guile related discussions

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='CACgrOxL5X6fz9Ziohjn4hMSv_w=zUxaREVpetFdQ4xXZaGkEwg@mail.gmail.com' \
    --to=btmeehan@gmail.com \
    --cc=guile-user@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).