From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: "Thompson, David" Newsgroups: gmane.lisp.guile.user Subject: Re: Guile equivalent to JS promises? Date: Mon, 10 Dec 2018 09:37:07 -0500 Message-ID: References: NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: text/plain; charset="UTF-8" X-Trace: blaine.gmane.org 1544452539 14720 195.159.176.226 (10 Dec 2018 14:35:39 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 10 Dec 2018 14:35:39 +0000 (UTC) Cc: Guile User To: swedebugia@riseup.net Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Dec 10 15:35:34 2018 Return-path: Envelope-to: guile-user@m.gmane.org Original-Received: from lists.gnu.org ([208.118.235.17]) by blaine.gmane.org with esmtp (Exim 4.84_2) (envelope-from ) id 1gWMek-0003hm-1v for guile-user@m.gmane.org; Mon, 10 Dec 2018 15:35:34 +0100 Original-Received: from localhost ([::1]:33120 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWMgq-0007Co-33 for guile-user@m.gmane.org; Mon, 10 Dec 2018 09:37:44 -0500 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:55623) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1gWMgU-0007CX-CB for guile-user@gnu.org; Mon, 10 Dec 2018 09:37:23 -0500 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1gWMgT-0007To-GQ for guile-user@gnu.org; Mon, 10 Dec 2018 09:37:22 -0500 Original-Received: from mail-wm1-x32e.google.com ([2a00:1450:4864:20::32e]:34792) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1gWMgT-0007T0-3E for guile-user@gnu.org; Mon, 10 Dec 2018 09:37:21 -0500 Original-Received: by mail-wm1-x32e.google.com with SMTP id y185so6781907wmd.1 for ; Mon, 10 Dec 2018 06:37:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=worcester-edu.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=eQCiXxF7TP5YUQixUClSJGsBjRtmJxEtcZijTMKxA8A=; b=RfTx8H0nEP8M50rA/NGwSE4Ac25SA+BMsWL26YwQ1rXm5BhHHSNbbZUNU34DvfEbaJ R8IDF/4ILch4P3XYmt3IRUGORDaf8dj7tGy4tM6m7E1Bgduaosqu0PK8q7J8x2ffV/OZ l9rTk8/TjGns6Xp6eA8Zb125rMEjooKl+pNewTDGPbzMqz/wk553ikaKcgofZ9uE1Bdm EC/On3nClvrX8DHW8FDZOLXMh8faFStJygQGh41i4sFJeiMAFBQX4Lc9Qb+nThPOAy/5 pAsPvZrNMNjyoj5pyDTjuxd0xhT1vh3TfOCXnultJcASvzFmwdXPKjBPczbiLJCWtet0 7HIg== 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=eQCiXxF7TP5YUQixUClSJGsBjRtmJxEtcZijTMKxA8A=; b=Yx1/pVJ97Ri8Ab0LR2BmsydRFn/k09C+gz09w6kD9EnJpCA6tyFfGpZxzGUfoVHLnQ NOaAQzMCfcFIBc+q+E1zlg+k2ofjM0PFPU7iOsroQPDjltSVn0lgWYVo89S0zYw+PcIs 7iLokXWnjW8F6J736SOWpCXSJPGeHSRpJ4NfEEWC2aLQGcvZO5TvABxg+CrR3wXiknPl MDAoeJ/sOYRnweUPP8xrdJlwCHAOiE3KVywPdw731sdLd6h16N3SAxo8C9io1SMdbUZR EWM0JUgFyZ8bSD4weLcOqlyhTTWBBweGaa7VbM3ChMtj0ZaVcefMyMlieU+bNV5B6Ciz fr9g== X-Gm-Message-State: AA+aEWZlGXlzuS0DFr8CuHkLSiqmxS/UgtTa5rsKmGzKv4VmfkDRA/vx od8upDJSpbmls6okhJ7dePwEAF/Nc2o/DVeqvJNTlA== X-Google-Smtp-Source: AFSGD/XJbf7LY6GLr4+ZR0P8+qXdnoQ5QKP70zjjjha69Ygzvjp4KgWE70HTINOWpCfLNx0Rydt1/+rOv9EG87SBeAA= X-Received: by 2002:a1c:7d54:: with SMTP id y81mr10726237wmc.106.1544452639190; Mon, 10 Dec 2018 06:37:19 -0800 (PST) In-Reply-To: X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2a00:1450:4864:20::32e X-BeenThere: guile-user@gnu.org X-Mailman-Version: 2.1.21 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.org@gnu.org Original-Sender: "guile-user" Xref: news.gmane.org gmane.lisp.guile.user:15041 Archived-At: Hello! On Sun, Dec 9, 2018 at 5:52 AM wrote: > > Hi > > I'm trying to understand JS promises. > > Are promises relevant in Guile? > > According to https://www.promisejs.org/ they seem to be a tool to > read/write JSON in a nonblocking way. > > Is this related to threading where the JS dev want multiple threads to > read stuff asynchroniusly at the same time? So, promises are basically just callback functions + error handling + a way to compose them together in a chain. I don't know of any existing Guile library that implements this API, but it wouldn't take much code to make a Scheme equivalent. However, I am hesitant to recommend promises for writing asynchronous programs for a variety of reasons. [1] Fortunately, Guile is pretty neat and provides a low-level feature that allows for much nicer asynchronous programming models: delimited continuations. I won't go into much detail about them here (see call-with-prompt in the manual), but Andy Wingo's guile-fibers [2] project is a really neat asynchronous programming library built on top of delimited continuations. And here's my favorite guile-user post of all time in which Andy drops a 13 line coroutine implementation (this blew my mind many years ago): https://lists.gnu.org/archive/html/guile-user/2011-02/msg00031.html tl;dr - use a system based on delimited continuations or write your own! Hope this helps! - Dave [1] http://wingolog.org/archives/2016/10/12/an-incomplete-history-of-language-facilities-for-concurrency [2] https://github.com/wingo/fibers