How do I turn values() into a list? 
Author Message
 How do I turn values() into a list?

Hi,

One of my little projects is to write a little package implementing a
lazy evaluation package for Dylan (akin to delay/force in SICP). It's
been easy and fun, except for one niggle: how do I capture an unknown
number of multiple return values into a sequence?

Ideally, I'd like something like this:

  listify(values(5,9)) => (5, 9) // a list with two elements

  listify(values(1,2,3)) => (1, 2, 3) // a list with 3 elements

  listify(values()) => #() // a list with no elements

but I can't figure out how. Any ideas?

Neel



Sun, 19 May 2002 03:00:00 GMT  
 How do I turn values() into a list?


Quote:
> Hi,

> One of my little projects is to write a little package implementing a
> lazy evaluation package for Dylan (akin to delay/force in SICP). It's
> been easy and fun, except for one niggle: how do I capture an unknown
> number of multiple return values into a sequence?

> Ideally, I'd like something like this:

>   listify(values(5,9)) => (5, 9) // a list with two elements

>   listify(values(1,2,3)) => (1, 2, 3) // a list with 3 elements

>   listify(values()) => #() // a list with no elements

> but I can't figure out how. Any ideas?

not sure if Dylan supports something like this more directly (i'm not a
Dylan expert)... but general OOP would lead me to just return a growable
collection...
i'm sure Dylan has a growable collection class :)

Maxwell Sayles



Mon, 20 May 2002 03:00:00 GMT  
 How do I turn values() into a list?

Quote:

> Hi,

> One of my little projects is to write a little package implementing a
> lazy evaluation package for Dylan (akin to delay/force in SICP). It's
> been easy and fun, except for one niggle: how do I capture an unknown
> number of multiple return values into a sequence?

> Ideally, I'd like something like this:

>   listify(values(5,9)) => (5, 9) // a list with two elements

>   listify(values(1,2,3)) => (1, 2, 3) // a list with 3 elements

>   listify(values()) => #() // a list with no elements

> but I can't figure out how. Any ideas?

OK, I think I'm confused about what you want.

listify is trivial to write:

   define method listify(#rest args)
      args;
   end method;

You can't pass the result of values() to it -- it wants actual arguments.

You can capture the results of values() into a list with:

   let (#rest x) = values(1,2,3,4);

If you do this then you don't need listify().

-- Bruce



Mon, 20 May 2002 03:00:00 GMT  
 How do I turn values() into a list?

Quote:


> > ... how do I capture an unknown
> > number of multiple return values into a sequence?  [e.g.]

> >   listify(values(5,9)) => (5, 9) // a list with two elements

> >   listify(values(1,2,3)) => (1, 2, 3) // a list with 3 elements

> >   listify(values()) => #() // a list with no elements

> OK, I think I'm confused about what you want.

> listify is trivial to write:

>    define method listify(#rest args)
>       args;
>    end method;

You mean

  define method listify (#rest args)
    as(<list>, args)
  end;

since IIRC the type of the #rest argument is <sequence>, not necessarly
<list>.

Quote:
> You can't pass the result of values() to it -- it wants actual arguments.

> You can capture the results of values() into a list with:

>    let (#rest x) = values(1,2,3,4);

> If you do this then you don't need listify().

Right, so may be listify should be

  define macro listify
    { listify ( ?vals:expression ) }
   => { let (#rest temp) = ?vals;
        as(<list>, temp) }
  end;

?

Hugh



Mon, 20 May 2002 03:00:00 GMT  
 How do I turn values() into a list?

Quote:

>Um, right up there above, Neel asked "how do I capture an unknown number
>of multiple return values into a sequence?".

>He pretty clearly mostly just wanted them in a single variable, and when
>he said "list" I read it as being used in the English sense of the word.
>and he actually said "sequance" too.

This is what I meant. Thanks to all of you who helped me out, though.
Immediately after all of you answered I found it explained in the DRM,
though I could have sworn it wasn't there before. I guess that's how
it always works. :)

Neel



Tue, 21 May 2002 03:00:00 GMT  
 
 [ 5 post ] 

 Relevant Pages 

1. Turning a list value in a parameter into a list for eval without quasiquote/unquote

2. Multiple-value-list with no values.

3. Removing the values from a list from another list

4. CW55 turn off list control marking

5. LOGO-L> (turn a list);butitem

6. Read a line from a file, turn into a list of numbers

7. fast way of turning a list of integers<256 into a string

8. strings turning to lists ??

9. As400 Slow when doing joins in browse list

10. Relevance of lists (Was: I'm not doing a good job)

11. ok, so how do I return a sorted list without doing it in place

12. Error when doing [.list delete active]--HELP!!

 

 
Powered by phpBB® Forum Software