* values
@ 2021-09-26 11:56 Philippe de Rochambeau
2021-09-26 12:33 ` values Arvydas Silanskas
0 siblings, 1 reply; 5+ messages in thread
From: Philippe de Rochambeau @ 2021-09-26 11:56 UTC (permalink / raw)
To: kawa
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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: values
2021-09-26 11:56 values Philippe de Rochambeau
@ 2021-09-26 12:33 ` Arvydas Silanskas
2021-09-26 13:25 ` values Philippe de Rochambeau
0 siblings, 1 reply; 5+ messages in thread
From: Arvydas Silanskas @ 2021-09-26 12:33 UTC (permalink / raw)
To: Philippe de Rochambeau; +Cc: kawa mailing list
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
2021-09-26, sk, 14:57 Philippe de Rochambeau via Kawa <kawa@sourceware.org>
rašė:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: values
2021-09-26 12:33 ` values Arvydas Silanskas
@ 2021-09-26 13:25 ` Philippe de Rochambeau
2021-09-26 13:37 ` values Philippe de Rochambeau
0 siblings, 1 reply; 5+ messages in thread
From: Philippe de Rochambeau @ 2021-09-26 13:25 UTC (permalink / raw)
To: kawa mailing list
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> 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
>
> 2021-09-26, sk, 14:57 Philippe de Rochambeau via Kawa <kawa@sourceware.org <mailto:kawa@sourceware.org>> rašė:
> 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
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: values
2021-09-26 13:25 ` values Philippe de Rochambeau
@ 2021-09-26 13:37 ` Philippe de Rochambeau
2021-09-26 16:19 ` values Philippe de Rochambeau
0 siblings, 1 reply; 5+ messages in thread
From: Philippe de Rochambeau @ 2021-09-26 13:37 UTC (permalink / raw)
To: kawa mailing list
I found a solution:
(define (halve n)
(let-values (((a b) (div-and-mod n 2)))
a))
> Le 26 sept. 2021 à 15:25, Philippe de Rochambeau <phiroc@free.fr> a écrit :
>
> 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
>>
>> 2021-09-26, sk, 14:57 Philippe de Rochambeau via Kawa <kawa@sourceware.org <mailto:kawa@sourceware.org>> rašė:
>> 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
>
^ permalink raw reply [flat|nested] 5+ messages in thread
* Re: values
2021-09-26 13:37 ` values Philippe de Rochambeau
@ 2021-09-26 16:19 ` Philippe de Rochambeau
0 siblings, 0 replies; 5+ messages in thread
From: Philippe de Rochambeau @ 2021-09-26 16:19 UTC (permalink / raw)
To: kawa mailing list
… 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
^ permalink raw reply [flat|nested] 5+ messages in thread
end of thread, other threads:[~2021-09-26 16:19 UTC | newest]
Thread overview: 5+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
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 ` values Philippe de Rochambeau
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).