From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.io!.POSTED.blaine.gmane.org!not-for-mail From: Tim Meehan Newsgroups: gmane.lisp.guile.user Subject: Re: Somehow I have got this "thunk" thing wrong. Date: Fri, 5 Mar 2021 21:40:29 -0600 Message-ID: References: <87k0qlnn40.fsf@cbaines.net> Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" Injection-Info: ciao.gmane.io; posting-host="blaine.gmane.org:116.202.254.214"; logging-data="39922"; mail-complaints-to="usenet@ciao.gmane.io" Cc: guile-user To: Christopher Baines Original-X-From: guile-user-bounces+guile-user=m.gmane-mx.org@gnu.org Sat Mar 06 04:41:02 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 1lINoL-000AHa-77 for guile-user@m.gmane-mx.org; Sat, 06 Mar 2021 04:41:01 +0100 Original-Received: from localhost ([::1]:50838 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1lINoK-0002Z6-3g for guile-user@m.gmane-mx.org; Fri, 05 Mar 2021 22:41:00 -0500 Original-Received: from eggs.gnu.org ([2001:470:142:3::10]:43366) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1lINo4-0002Yn-H6 for guile-user@gnu.org; Fri, 05 Mar 2021 22:40:44 -0500 Original-Received: from mail-qt1-x82c.google.com ([2607:f8b0:4864:20::82c]:40176) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1lINo2-0006zr-Kf for guile-user@gnu.org; Fri, 05 Mar 2021 22:40:44 -0500 Original-Received: by mail-qt1-x82c.google.com with SMTP id h9so3459119qtq.7 for ; Fri, 05 Mar 2021 19:40:41 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=HmbqMgurfW+IpwAPLLAOGdnISl/U1UIo1Z6aZ8845BI=; b=J8RYYCqwj3afAQLC97WpgpEB2hYA8Njx9eOo5dfqykkwQNwrQBlk3uEhvj2m+epWLF rZ+lg55A/ADCE2fnjzOb88dQr9u6ry91nKDE/CHxPp1SdqG0egH3HQFKgEQzxiAo8dEH b6QXOG37kJfZDNZgU9NSyqW5Hg2RAZHUbfye0g9XlK0pTDrQlLCGtkaH+6Lx9Nvtfmt3 bo4hckUfwxVw+7AYKljgGM3gszrFIGNRbyavE2hJblpvTxEYNdspTfrUpzC4QRwG0zRt s5VjDX/hESlKf83wViyWuSvxmbLqpaM5cR4SpJbEEglKhIeG+cqCoXX65daHU4jF3ekF Ueyg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=HmbqMgurfW+IpwAPLLAOGdnISl/U1UIo1Z6aZ8845BI=; b=SCzwfEJxoxpajGOibgh52t1N/GsgnEchKt0lRddjaYGpbjhU8WVuSQ5C4Q02R20O5o 1vVcaxjtdDVXxuf+WlmViuLQmi58rnUlGv74Z/J57LAkjUusZZOhL1km0ioVGdNIqAu5 +RRcL9+IWKymjZ1Vc1Is8pjoFC1X8xIyysFuW+TlrbSvhVlIVtFV0MI0mkFaoiJ/Fyxn ZC3BKMoO2SYs3Im7Mhez8kYPht5FdXLCNbNwPWe096Q67WgDjyLWhRJZren9YzwWTY+O iEhEgK+hJ9cFFs3sFLxQfi6/8EsCnINohNNEEJppsAkmMmTTThpdAQfnWk3mEXIxL1dG 76xw== X-Gm-Message-State: AOAM532tDifj1SFI3DjricTRXDMWjJdoofHKNQTiMRQK+R11VPj1bnN6 Mq/DFiSicum9K+nHe+GzQ3s/qBtyy+s1n4H/O2k= X-Google-Smtp-Source: ABdhPJy+guPnsH78gxuilicnWSy0WWcAAPoGXQ5jxYP7Qpe3ypoED75xxV/jgyQDTNGcoB32Kjz7SFGhqrQz74e4QWM= X-Received: by 2002:ac8:568d:: with SMTP id h13mr11535872qta.139.1615002040474; Fri, 05 Mar 2021 19:40:40 -0800 (PST) In-Reply-To: <87k0qlnn40.fsf@cbaines.net> Received-SPF: pass client-ip=2607:f8b0:4864:20::82c; envelope-from=btmeehan@gmail.com; helo=mail-qt1-x82c.google.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, FREEMAIL_FROM=0.001, HTML_MESSAGE=0.001, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Content-Filtered-By: Mailman/MimeDel 2.1.23 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:17340 Archived-At: Yes, that makes sense. The unquote is a neat way to fix that. One of these days, I will learn my lesson. Thanks Christopher! On Fri, Mar 5, 2021 at 6:26 PM Christopher Baines wrote: > > 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? >