[racket] (values) vs (void)
Most contexts expect one value, and you can easily define a macro that does the
(define-syntaxes ()
(begin0 (values) expr …))
or
(define-syntaxes ()
(begin expr … (values)))
for you.
The one that comes too my mind first is
(and (test-something-about x) (do-something-with x) (do-something-else-with x)),
where (do-something-with x) just returns void (which is a truthy value), but only if the test is true.
On Nov 23, 2014, at 9:17 PM, Roman Klochkov <kalimehtar at mail.ru> wrote:
> I can't imagine an example, where one need to use void function in context, that expects a single value.
> Moreover, in macro definition I had to write
>
> (define-syntaxes ()
> (begin0 (values)
> (save-fields! #'NAME (list 'ALL-FIELD ...))
>
> to make side effect work in expansion time. I cannot write simply (save-fields! #'NAME (list 'ALL-FIELD ...), because save-fields! is at phase-1.
> I prefer to write simply
>
> (define-syntaxes () (save-fields! #'NAME (list 'ALL-FIELD ...))
>
> but then save-fields! should return no values, not one void value.
>
> Can you bring an example, where one have to to use void function in a context that expects a single value?
>
>
> Sun, 23 Nov 2014 18:21:47 -0500 от "Alexander D. Knauth" <alexander at knauth.org>:
>
> On Nov 23, 2014, at 1:31 PM, Roman Klochkov <kalimehtar at mail.ru> wrote:
>
>> > void is a good placeholder in dummy functions/objects
>>
>> (define (foo) (values)) also works just fine.
>
> But then you can’t use (foo) in a context that expects a single value, but if you use (void) instead of (values), it will return one value (instead of zero values), and so you can use it in contexts that expect one value.
>
>>
>> > fill a gap, which is useful
>>
>> If function returns void?, then it is used as a procedure. I mean returned value never assigned to a variable.
>> So in what cases it is useful?
>>
>>
>> Sun, 23 Nov 2014 13:20:26 +0000 от Stephen De Gabrielle <spdegabrielle at gmail.com>:
>> void is a good placeholder in dummy functions/objects. It doesn't do anything, except for fill a gap, which is useful.
>>
>> Values is used to pass multiple values.
>>
>> Check the manual for details.
>>
>> Does that help?
>>
>> Stephen
>>
>> On Sun, 23 Nov 2014 at 12:56 Roman Klochkov <kalimehtar at mail.ru> wrote:
>> When I should use (void) and when (values)?
>>
>> They are both used to show, that there are no return values.
>> They are both not printable.
>>
>> What is intended use for (void) and (values) and when one should prefer one over other?
>>
>> --
>> Roman Klochkov
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>>
>>
>> --
>> Roman Klochkov
>> ____________________
>> Racket Users list:
>> http://lists.racket-lang.org/users
>
>
>
> --
> Roman Klochkov
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20141123/4f11eeef/attachment.html>