public inbox for kawa@sourceware.org
 help / color / mirror / Atom feed
From: Philippe de Rochambeau <phiroc@free.fr>
To: kawa mailing list <kawa@sourceware.org>
Subject: Re: values
Date: Sun, 26 Sep 2021 18:19:51 +0200	[thread overview]
Message-ID: <5EC715FC-1C6F-4DF5-9AAB-B7B513E08C2E@free.fr> (raw)
In-Reply-To: <11BE00BD-0D11-4F6A-9314-A7C4FFEF33D6@free.fr>

… and here’s a solution with a local halve procedure:

(let* ((n0 39)
    (halve (lambda (n)
            (div-and-mod n 2))))
            (let-values (((a b) (halve n0)))
                (display a)))

> 
> I found a solution:
> 
> (define (halve n)
> 	(let-values (((a b) (div-and-mod n 2)))
> 	a))
> 
>> 
>> 
>> Hi Arvydas,
>> thanks you for your feedback.
>> I’ve managed to retrieve the 19 from div-and-mod using let-values.
>> Now, how do I add a procedure called « (halve n) » which when passed a value such as 39, returns 19?
>> Many thanks.
>> Philippe
>> 
>> (display (let-values (((a b) (div-and-mod 39 2)))
>> a))
>> 
>> 
>> 
>>> Le 26 sept. 2021 à 14:33, Arvydas Silanskas <nma.arvydas.silanskas@gmail.com <mailto:nma.arvydas.silanskas@gmail.com>> a écrit :
>>> 
>>> Hi
>>> 
>>> generally you would use constructs like define-values or let-values to declare multiple variables which will be bound to the received multiple values. There is also a more primitive call-with-values construct for piping those values as arguments to some procedure. To get a list, you could use `(call-with-values (lambda () (values 1 3)) list)`.
>>> 
>>> Arvydas
>>> 
>>> 
>>> Hello,
>>> how do you retrieve the first item returned by the values procedure?
>>> I’ve tried (first (values 1 3)), but to no avail, because values doesn’t return a list.
>>> Many thanks.
>>> Philippe


      reply	other threads:[~2021-09-26 16:19 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2021-09-26 11:56 values Philippe de Rochambeau
2021-09-26 12:33 ` values Arvydas Silanskas
2021-09-26 13:25   ` values Philippe de Rochambeau
2021-09-26 13:37     ` values Philippe de Rochambeau
2021-09-26 16:19       ` Philippe de Rochambeau [this message]

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

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=5EC715FC-1C6F-4DF5-9AAB-B7B513E08C2E@free.fr \
    --to=phiroc@free.fr \
    --cc=kawa@sourceware.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).