From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Christopher Baines Newsgroups: gmane.lisp.guile.user Subject: Re: Somehow I have got this "thunk" thing wrong. Date: Sat, 06 Mar 2021 00:26:39 +0000 Message-ID: <87k0qlnn40.fsf@cbaines.net> References: Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha512; protocol="application/pgp-signature" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="593"; mail-complaints-to="usenet@ciao.gmane.io" User-Agent: mu4e 1.4.15; emacs 27.1 Cc: guile-user@gnu.org To: Tim Meehan Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Mar 06 01:26:58 2021 Return-path: Envelope-to: guile-user@m.gmane-mx.org Original-Received: from lists.gnu.org ([209.51.188.17]) by ciao.gmane.io with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.92) (envelope-from ) id 1lIKmY-000AcS-11 for guile-user@m.gmane-mx.org; Sat, 06 Mar 2021 01:26:58 +0100 Original-Received: from localhost ([::1]:48612 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIKmW-0001KO-O0 for guile-user@m.gmane-mx.org; Fri, 05 Mar 2021 19:26:56 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:41028) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lIKmL-0001K8-Ts for guile-user@gnu.org; Fri, 05 Mar 2021 19:26:45 -0500 Original-Received: from mira.cbaines.net ([212.71.252.8]:44898) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lIKmK-0002gV-8q for guile-user@gnu.org; Fri, 05 Mar 2021 19:26:45 -0500 Original-Received: from localhost (unknown [IPv6:2a02:8010:68c1:0:8ac0:b4c7:f5c8:7caa]) by mira.cbaines.net (Postfix) with ESMTPSA id D24D427BC46; Sat, 6 Mar 2021 00:26:42 +0000 (GMT) Original-Received: from capella (localhost [127.0.0.1]) by localhost (OpenSMTPD) with ESMTP id c5311e67; Sat, 6 Mar 2021 00:26:41 +0000 (UTC) In-reply-to: Received-SPF: pass client-ip=212.71.252.8; envelope-from=mail@cbaines.net; helo=mira.cbaines.net X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, SPF_HELO_PASS=-0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: General Guile related discussions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.io gmane.lisp.guile.user:17337 Archived-At: --=-=-= Content-Type: text/plain Tim Meehan writes: > 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")) The lambda bit you've written is quoted. So you're asking Guile to apply a list where the first element is the symbol 'lambda, the second is the empty list, ... You probably want something like this, where you're creating a list of pairs, where the car of the pair is a symbol, and the cdr is a procedure (rather than a list). (define stuff (alist->hash-table `((a . ,(lambda () (display "event a\n"))) (b . ,(lambda () (display "event b\n"))) (c . ,(lambda () (display "event c\n")))))) Does that make sense? --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQKlBAEBCgCPFiEEPonu50WOcg2XVOCyXiijOwuE9XcFAmBCzD9fFIAAAAAALgAo aXNzdWVyLWZwckBub3RhdGlvbnMub3BlbnBncC5maWZ0aGhvcnNlbWFuLm5ldDNF ODlFRUU3NDU4RTcyMEQ5NzU0RTBCMjVFMjhBMzNCMEI4NEY1NzcRHG1haWxAY2Jh aW5lcy5uZXQACgkQXiijOwuE9Xc+Bw//ftGzEHnM2tdR7HkYoP0MtknFn0IgcUR0 M8m1mIDRe2yfF/aRNZ/GviuJh0WXE9Payb4U+yTV4f+7K3BB3N2vfQABuu0+P9ib PKJYjG7ShKAp9AV1cMkeiPBfuURaRmyCmGO5r5c9eQY3xl4IKLUBxzldz6qzsJki Z0jrIyNerQi3DZuhJSVI7q/fT0VdcJBeuIJol9rybc433ip5J2pssWumxZJ5ArOV sb55xLiBA4W4vNYS1PcpESKKU61Q43hy7aMSeid8sNuzL1moySWpSrnqsRrdr62B j3IlWedSTi4qp018PhTbBXTUnqbQaOVt29BIRXhYJw8z6fhZq1YBqvKc+ah+LmVD ZHm2CcLdEZ5FcS+J6vGoFO3vIOKW5BlX7ly1/NO71GszZAJJu3ngxKYioEQTrPtR 6MB/DtaR0qdIR4ZeWAY0+gYv+xj3fdCa/6+3PCqHCoyhc5DZzP/0TpdK/xAkjIzt Ob0K3xiGU+0jsoErfHSc82yf138uw9SuYKCv/fMaKpuexxoPqq7usPVnLk5AAaCx JEULCWjUZUgBznzMn0nWySrMuFig1zJvvb0FYuSleP+gPWBOyM8nC07VsJgTLMGy 47TMjpKHcDwphfkB7MIhhpa16oKx7DzwhUrF63FJkAbRRUWHWVhbwy+Lmw7Odpj5 e6mc02gS+/w= =Pd/Q -----END PGP SIGNATURE----- --=-=-=--