From mboxrd@z Thu Jan 1 00:00:00 1970 Path: news.gmane.org!.POSTED!not-for-mail From: Chris Marusich Newsgroups: gmane.lisp.guile.user Subject: Re: Multiple values passed as single argument to procedure Date: Mon, 12 Jun 2017 01:19:48 -0700 Message-ID: <87mv9dy5wb.fsf@gmail.com> References: <87mv9fnejc.fsf@gmail.com> <87k24i2rev.fsf@netris.org> <87zidexdjw.fsf@gmail.com> <87a85d3k9n.fsf@netris.org> NNTP-Posting-Host: blaine.gmane.org Mime-Version: 1.0 Content-Type: multipart/signed; boundary="=-=-="; micalg=pgp-sha256; protocol="application/pgp-signature" X-Trace: blaine.gmane.org 1497255638 31821 195.159.176.226 (12 Jun 2017 08:20:38 GMT) X-Complaints-To: usenet@blaine.gmane.org NNTP-Posting-Date: Mon, 12 Jun 2017 08:20:38 +0000 (UTC) User-Agent: Gnus/5.13 (Gnus v5.13) Emacs/25.2 (gnu/linux) Cc: guile-user@gnu.org To: Mark H Weaver Original-X-From: guile-user-bounces+guile-user=m.gmane.org@gnu.org Mon Jun 12 10:20:32 2017 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 1dKKaN-0007wH-Ha for guile-user@m.gmane.org; Mon, 12 Jun 2017 10:20:31 +0200 Original-Received: from localhost ([::1]:36688 helo=lists.gnu.org) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKKaS-0007Po-OM for guile-user@m.gmane.org; Mon, 12 Jun 2017 04:20:36 -0400 Original-Received: from eggs.gnu.org ([2001:4830:134:3::10]:53708) by lists.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1dKKZr-0007OD-46 for guile-user@gnu.org; Mon, 12 Jun 2017 04:20:00 -0400 Original-Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1dKKZp-0004rW-Vu for guile-user@gnu.org; Mon, 12 Jun 2017 04:19:59 -0400 Original-Received: from mail-pg0-x241.google.com ([2607:f8b0:400e:c05::241]:33691) by eggs.gnu.org with esmtps (TLS1.0:RSA_AES_128_CBC_SHA1:16) (Exim 4.71) (envelope-from ) id 1dKKZp-0004qX-Om for guile-user@gnu.org; Mon, 12 Jun 2017 04:19:57 -0400 Original-Received: by mail-pg0-x241.google.com with SMTP id a70so13670212pge.0 for ; Mon, 12 Jun 2017 01:19:56 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=from:to:cc:subject:references:date:in-reply-to:message-id :user-agent:mime-version; bh=7ieQwQMrhavdxPcOwnzNwnB/dw2vECfu+2zSJWfupSg=; b=gwTiGgk3tRGLpbMR4JSM8+BY5jFJX1uXcXOwcm1ZEH7xrp7XrHrJ8l0d+4RNa+611v KCwrH3D+VO5i6784Qghcc6AQAOTyGQI8QUmDcrbCucdeVQTvCEtyeoYnqVhczu80Nh5F oE1yKw1efB5eRcDptqK6WfAWNXXErASex5GdNZSvqJnt1vtJX5vRsmQGR0B/Xd/Pm+3M iFxFp7FPabFnlxBtNz88WUi4kyPYi3U/621J04HhPolJfCiPkWus8GD4lfItaGlHe0GD WzYnt4MxbmAV9enV9IwxTSSUZY8deUuWdu2xo/U+VZLSmbTbQ4yZWqi9di5RmXUvZVHQ Xc0Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:references:date:in-reply-to :message-id:user-agent:mime-version; bh=7ieQwQMrhavdxPcOwnzNwnB/dw2vECfu+2zSJWfupSg=; b=PCiQ5WEuygYkm16FLyaGeKLA7VZrppnDoZ9voJp1jsqeREAn5CBN2AzzwDdZb83TiX +Jq89oxk4CtoCMUj1JSjgBo3dMh5wtLluFPcAZXxF3dtjov6r9SjV0wJyjEON6jPSV3p r6ZXjBsb/UpKTLBBbwWQZM/wYgB0Q7MOrR8e04H5eg+nZKlU9r+78mLH5xIkq3sSz0Y1 gdrzeAdgnOOxiCJi/uYndi/x1oLKEsPFHIQl+enV6tzSi7ftVHJe0MaCNh5IPottytiU HGP06qMeS0OLHiEeWcxqyegQD/3ijbshyOMncAcEsNXvwk2IFn6QbdXNS698AiJDKjY2 oZ0A== X-Gm-Message-State: AODbwcC/lZdSR5g4UGfHQxxltIIDF/wiE4pZEqcL9FMssRhTyrBvBiM7 irfw2yJ+lH/g1UYs X-Received: by 10.84.229.77 with SMTP id d13mr54910802pln.72.1497255594879; Mon, 12 Jun 2017 01:19:54 -0700 (PDT) Original-Received: from garuda ([2601:602:9d02:4725:4e0f:6eff:fef6:70b9]) by smtp.gmail.com with ESMTPSA id b14sm18397966pga.12.2017.06.12.01.19.52 (version=TLS1_2 cipher=ECDHE-RSA-CHACHA20-POLY1305 bits=256/256); Mon, 12 Jun 2017 01:19:53 -0700 (PDT) In-Reply-To: <87a85d3k9n.fsf@netris.org> (Mark H. Weaver's message of "Mon, 12 Jun 2017 00:25:08 -0400") X-detected-operating-system: by eggs.gnu.org: Genre and OS details not recognized. X-Received-From: 2607:f8b0:400e:c05::241 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:13822 Archived-At: --=-=-= Content-Type: text/plain Content-Transfer-Encoding: quoted-printable Hi Mark, Regarding the Guile-specific behavior where passing multiple values as an argument to a procedure causes only the first value to be used as the argument: > I would recommend against relying on this behavior, mainly because I > would consider it a bit sloppy. However, I also think it's very > unlikely that we would ever remove this extension, because I don't > anticipate a compelling reason to remove it, and it would surely break > existing code. > >> I was hoping to find this behavior documented in either >> "(guile) Multiple Values" or somewhere in "(guile) About Procedures". >> Perhaps there's a better location. In any case, I think it would be >> helpful if this were documented in the manual. > > Agreed. "(guile) Multiple Values" is probably the appropriate place. OK. I'll submit a patch later this week to update the manual with information taken from this email thread. Hopefully that will help clarify the behavior for others in the future. Regarding the behavior of composed procedures: > The problem is that you implemented your 'manual' composition in a way > that allows only one value to pass between the two procedures. Remember > that when a procedure call is made without 'call-with-values' (or some > macro that uses it), and is not in tail position, then all but the first > return value is discarded. That's what's happening in your call to 'f' > in (list (f)). The call (f) is neither in tail position nor called > using 'call-with-values', so only one of its values is kept. I think I'm missing something here. In (list (f)), the call to f certainly looks like it's happening at a position that one might intuitively call a "tail" position. So, in this case, what disqualifies f from being in tail position? Can you give me an example of a call to f that would be in tail position, so I can understand the difference? Sorry if you've already provided such an example; I appreciate your explanations, and I'm just trying to make sure I fully understand. > Try this instead: > > (let-values ((vals (f))) > (apply list vals)) > > Or, more simply in the case where 'f' takes no arguments: > > (call-with-values f list) Am I correct in understanding that in these cases, the two values returned by the 'f' procedure basically get "converted" into two separate arguments that get passed to the 'list' procedure, as if I had invoked (list 1 2)? > I suppose you are thinking of 'compose' as being implemented like >this: > > (define (compose f g) > (lambda (x) > (f (g x)))) Yes, that's what I assumed. I think I see now why my assumption was incorrect for the case where g returns multiple values. I think the problem here was that I didn't understand how multiple values would be handled under various situations, even after consulting the Guile manual. > The core Guile version of 'compose' is defined in ice-9/boot-9.scm. Thank you! It's helpful to see the implementation. I see that it's similar to one of the examples you gave for implementing 'compose' in a way that supports procedures of arbitrary arity that return an arbitrary number of values. =2D-=20 Chris --=-=-= Content-Type: application/pgp-signature; name="signature.asc" -----BEGIN PGP SIGNATURE----- iQIzBAEBCAAdFiEEy/WXVcvn5+/vGD+x3UCaFdgiRp0FAlk+TqUACgkQ3UCaFdgi Rp28fQ/9FCiGPsKB2n1xgJxEkXM5ObuTrWBA8MARVtGRDd7V7gUVRu5pUIPBQsyU pwHkNXvCZZDLc5ByL4Bq43xCWnCp9E3lYBVworWm/o+aset5iUBk0xDth8CLABnf srsgU81Sdk2EcFeVPmJRQ6xR8kj6yNk8PVBGvgrhPTBsjw/QiazsQ6vEy1OblqTP Ki9jC9w9808v9V0iGOwMDl+qt7/cazlnMCtriFscgiBA5FV0a33Ze4QsJaPcWCEh fip4qKkdoRx3xSFGIABmnKoFw1iufzwidE+7NxPOvhuiG7l7LdPzH7O6OmPQ/OYK xpiQlYUgOk4rp3cVRMNCCgH1Bdph3Ash/v1ebxehdIdsUys7fe5ZayMlaZN2SX3e TsTiUaQIJ/dSvMhryP0NNZqs0NLtMW659f14q9SqPQDbHSQFjZI5cZrzqcmz8+gz Xzg+9ClyE0EmUyQagm6caRrmgfELhH88lidA/CXshy9vuPImtTvmD6dBvI3YWCQf Ryc43nD9OUgVAUk9MWv52fVqBpOppspXyaxqAokZ6q8RosrPUBHNsKZSbl4dYrvX o0CIUvB5XsSGcTcDpaLdi+Y96IJd2ZEMhW7H2kXCQbP5b1Xw58PonAy+Qch2s++r ySY9Qn8wgDY6WOVCA8dK0pjEkJPAXeG6wzN9wDixU8hptMvnSbM= =pHdI -----END PGP SIGNATURE----- --=-=-=--