[plt-scheme] How do I convert (values ...) to something I can do something with?
I use multiple value returns _a lot_.
I try to never overload lists or pairs and instead always make
structs. I try to limit myself to structs that "make sense" in the
wild as opposed to ones that will only be produced/consumed by a
single function; I find that in those cases I really want multiple
values.
However, multiple values have a problem that when you get more than a
few it is complicated to remember which is which because all you have
is positions. At least with function calls you can have keyword args.
In those cases, I let myself use a struct, but I feel bad about it.
My two gil,
Jay
On Tue, Mar 9, 2010 at 9:38 PM, Todd O'Bryan <toddobryan at gmail.com> wrote:
> Stylistically, is one better/more idiomatic than the other? I thought
> about returning a list, but I have this aversion to complex nested
> structures that aren't self-descriptive. (Yeah, I know--if
> s-expressions freak me out, I'm looking for trouble coding in Scheme.)
> I could define a struct so that the parts have names; maybe that's the
> best thing to do.
>
> I guess I decided to return multiple-values because it forces me to
> check myself. I can't just assign the return value from the function
> to a single variable, so if I screw up and forget that it returns
> multiple values, I should get an error fairly early. Within my code,
> the multiple-value thing isn't a problem at all. It's just when I was
> trying to write test cases that it became annoying.
>
> Does anyone else sometimes feel like you're learning a foreign
> language by listening to tapes? I have this constant worry that, while
> I think I'm speaking Scheme, when I finally start talking to native
> speakers, they're going to find my accent either incomprehensible or
> really funny.
>
> Todd
>
> On Tue, Mar 9, 2010 at 11:26 PM, Matthias Felleisen
> <matthias at ccs.neu.edu> wrote:
>>
>> Sure, return a list instead of multiple values. -- Matthias
>>
>>
>>
>>
>> On Mar 9, 2010, at 11:14 PM, Todd O'Bryan wrote:
>>
>>> Thanks. I saw those, but they didn't register...
>>>
>>> If (foo 'x) returns multiple values, is there any easier way than
>>>
>>> (call-with-values (lambda () (foo 'x)) list)
>>>
>>> to convert it to a list?
>>>
>>> On Tue, Mar 9, 2010 at 11:05 PM, Carl Eastlund <cce at ccs.neu.edu> wrote:
>>>> On Tue, Mar 9, 2010 at 11:02 PM, Todd O'Bryan <toddobryan at gmail.com> wrote:
>>>>> I've written a function that returns multiple values. But now I can't
>>>>> figure out how to check the silly thing.
>>>>>
>>>>> Sorry if this is a stupid question, but how do I convert a (values
>>>>> ...) expression into something I can wrap my parentheses around?
>>>>>
>>>>> Todd
>>>>
>>>> If you know exactly how many values you'll be getting, use let-values
>>>> or define-values. If you don't, use call-with-values. They're all in
>>>> the Help Desk.
>>>>
>>>> --Carl
>>>>
>>> _________________________________________________
>>> For list-related administrative tasks:
>>> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>>
>>
> _________________________________________________
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
--
Jay McCarthy <jay at cs.byu.edu>
Assistant Professor / Brigham Young University
http://teammccarthy.org/jay
"The glory of God is Intelligence" - D&C 93