Re: [racket-dev] PLaneT Library of Iterations/Comprehensions

2010-08-24 Thread Will M. Farr
Dave,

Thanks a bunch for pointing out the untyped code!  I have a few questions 
below, mostly trying to understand the behavior of the macros and reconcile it 
with their names.

I'm not sure that I understand for/foldl and friends.  I think of the functions 
foldl (and foldr) as taking *one* accumulator, and filtering it through a 
function applied to each of the members of a sequence or sequences---that is, 
there are many function arguments, but only one accumulator.  But, the foldl 
here looks like 

(define-syntax (for/foldl stx)
  (syntax-case stx ()
((for/foldl accums (for-clause ...) body ...)
 (syntax/loc stx
   (call-with-values 
   (lambda ()
 (for/fold accums (for-clause ...) body ...))
 (lambda args (car args)))

That is, it has many accumulators, but returns only the first.  (I tried 
defining the code you linked to at the REPL, and it barfed on some of the 
...'s, so I wasn't able to test this assertion.  I'm sure that I'm just missing 
some libraries.)  Am I confused?  This sounds more like for/fold/head, or 
for/fold/first, or something like that?

I'm similarly a bit unhappy with the name for for/filter.  The filter procedure 
takes a predicate, and removes any items from its list argument that don't 
satisfy the predicate.  The for/filter macro is like a (hypothetical) 
for/lists, followed by a removal of the false elements.  Is there possible a 
better name for this?  How often do you find yourself using the multi-valued 
version (i.e. could we have a single-valued for/not-false or something, that 
gets most of the use cases)?

I like for/append without reservation, and have added it to my local iteration 
branch, and I'll forward it to Sam once I've built the code and it passes some 
tests.  Thanks again for suggesting these forms, Dave.

Will

On Aug 24, 2010, at 2:55 AM, Dave Gurnell wrote:

> I use these guys all the time:
> 
>   http://github.com/untyped/unlib/blob/master/for.ss
> 
> No guarantees that I'm not duplicating other peoples' efforts.
> 
> Cheers,
> 
> -- Dave
> 
> On 22 Aug 2010, at 07:26, Noel Welsh wrote:
> 
>> Hi Will,
>> 
>> My "numerics" package on Github has for/vector with some slight
>> extensions to yours. I think it also has more error checking so you
>> might want to look at it. I also have for/fold/vector and some
>> sequence abstractions. The code is all parameterised at expansion time
>> by the vector representation.
>> 
>> http://github.com/noelwelsh/numeric
>> 
>> N.
>> 
>> 
>> On Wed, Aug 18, 2010 at 5:02 PM, Will M. Farr  wrote:
>>> Hello all,
>>> 
>>> I've been thinking for a while about putting together a PLaneT library of 
>>> some iteration/comprehension forms that I often use that are not found in 
>>> the racket core.  Right now, I have a small it-comp.plt local PLaneT 
>>> package that contains
>>> 
>>> for/vector
>>> for/flvector
>>> in-flvector
>>> 
>>> The for/... forms have the option of having a first expression that gives 
>>> the length of the resulting object (similar to srfi-42's 
>>> vector-of-length-ec form) to allow generating more efficient code:
>>> 
>>> (for/vector ((x (in-range 3))) x) => (vector 0 1 2)
>>> (for/vector 3 ((x (in-range 3))) x) => (vector 0 1 2) ; but more efficiently
>>> 
>>> I'll be adding more forms from time to time, as I need them.  Eventually, 
>>> I'll release this to PLaneT, but I thought I might ask the community two 
>>> questions first:
>>> 
>>> 1. Am I duplicating the functionality of some library?  (If so, I'll just 
>>> contribute to that instead.)
>>> 2. Do you have any iteration "favorites" that I should include in the 
>>> library?  (Code welcome, but I'm also happy to implement suggestions 
>>> myself.)
>>> 
>>> Alternately, if you guys want to add these to the core, I'd be happy to 
>>> contribute code and tests
>>> 
>>> Thanks,
>>> Will
>>> _
>>> For list-related administrative tasks:
>>> http://lists.racket-lang.org/listinfo/dev
>>> 
>> _
>> For list-related administrative tasks:
>> http://lists.racket-lang.org/listinfo/dev
> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] PLaneT Library of Iterations/Comprehensions

2010-08-24 Thread Dave Gurnell
I use these guys all the time:

http://github.com/untyped/unlib/blob/master/for.ss

No guarantees that I'm not duplicating other peoples' efforts.

Cheers,

-- Dave

On 22 Aug 2010, at 07:26, Noel Welsh wrote:

> Hi Will,
> 
> My "numerics" package on Github has for/vector with some slight
> extensions to yours. I think it also has more error checking so you
> might want to look at it. I also have for/fold/vector and some
> sequence abstractions. The code is all parameterised at expansion time
> by the vector representation.
> 
> http://github.com/noelwelsh/numeric
> 
> N.
> 
> 
> On Wed, Aug 18, 2010 at 5:02 PM, Will M. Farr  wrote:
>> Hello all,
>> 
>> I've been thinking for a while about putting together a PLaneT library of 
>> some iteration/comprehension forms that I often use that are not found in 
>> the racket core.  Right now, I have a small it-comp.plt local PLaneT package 
>> that contains
>> 
>> for/vector
>> for/flvector
>> in-flvector
>> 
>> The for/... forms have the option of having a first expression that gives 
>> the length of the resulting object (similar to srfi-42's vector-of-length-ec 
>> form) to allow generating more efficient code:
>> 
>> (for/vector ((x (in-range 3))) x) => (vector 0 1 2)
>> (for/vector 3 ((x (in-range 3))) x) => (vector 0 1 2) ; but more efficiently
>> 
>> I'll be adding more forms from time to time, as I need them.  Eventually, 
>> I'll release this to PLaneT, but I thought I might ask the community two 
>> questions first:
>> 
>> 1. Am I duplicating the functionality of some library?  (If so, I'll just 
>> contribute to that instead.)
>> 2. Do you have any iteration "favorites" that I should include in the 
>> library?  (Code welcome, but I'm also happy to implement suggestions myself.)
>> 
>> Alternately, if you guys want to add these to the core, I'd be happy to 
>> contribute code and tests
>> 
>> Thanks,
>> Will
>> _
>>  For list-related administrative tasks:
>>  http://lists.racket-lang.org/listinfo/dev
>> 
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev

_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] PLaneT Library of Iterations/Comprehensions

2010-08-21 Thread Noel Welsh
Hi Will,

My "numerics" package on Github has for/vector with some slight
extensions to yours. I think it also has more error checking so you
might want to look at it. I also have for/fold/vector and some
sequence abstractions. The code is all parameterised at expansion time
by the vector representation.

http://github.com/noelwelsh/numeric

N.


On Wed, Aug 18, 2010 at 5:02 PM, Will M. Farr  wrote:
> Hello all,
>
> I've been thinking for a while about putting together a PLaneT library of 
> some iteration/comprehension forms that I often use that are not found in the 
> racket core.  Right now, I have a small it-comp.plt local PLaneT package that 
> contains
>
> for/vector
> for/flvector
> in-flvector
>
> The for/... forms have the option of having a first expression that gives the 
> length of the resulting object (similar to srfi-42's vector-of-length-ec 
> form) to allow generating more efficient code:
>
> (for/vector ((x (in-range 3))) x) => (vector 0 1 2)
> (for/vector 3 ((x (in-range 3))) x) => (vector 0 1 2) ; but more efficiently
>
> I'll be adding more forms from time to time, as I need them.  Eventually, 
> I'll release this to PLaneT, but I thought I might ask the community two 
> questions first:
>
> 1. Am I duplicating the functionality of some library?  (If so, I'll just 
> contribute to that instead.)
> 2. Do you have any iteration "favorites" that I should include in the 
> library?  (Code welcome, but I'm also happy to implement suggestions myself.)
>
> Alternately, if you guys want to add these to the core, I'd be happy to 
> contribute code and tests
>
> Thanks,
> Will
> _
>  For list-related administrative tasks:
>  http://lists.racket-lang.org/listinfo/dev
>
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] PLaneT Library of Iterations/Comprehensions

2010-08-19 Thread Will M. Farr
Sam,

On Aug 18, 2010, at 1:39 PM, Sam Tobin-Hochstadt wrote:

>> 
>> The for/... forms have the option of having a first expression that gives 
>> the length of the resulting object (similar to srfi-42's vector-of-length-ec 
>> form) to allow generating more efficient code:
>> 
>> (for/vector ((x (in-range 3))) x) => (vector 0 1 2)
>> (for/vector 3 ((x (in-range 3))) x) => (vector 0 1 2) ; but more efficiently
> 
> What does this do if the specified length is wrong?

If the length is too short, then there will be a vector access error with the 
correct syntax location (though it may be a bit cryptic); if the length is too 
long, then the returned vector will have some slots at the end that are 
undefined (i.e. filled with whatever (make-vector NN) produces).  I think this 
kinda sucks, but I don't see any way to grab the length of a (for ...) form 
before it's run to check for consistency (in fact, I'm pretty sure you can't, 
since for loops can have #:while clauses that turn computation of the length 
into the halting problem).  In my opinion, offering the fast path (the slow 
path makes a list first, then calls (list->vector ...) on the result, so the 
fast path should be a big win both in memory and speed) is worth the risk, but 
I'd be interested to hear what you think.

I'm currently preparing the patch you requested; I'll let you know when it 
compiles and passes the tests on my system (which takes a while, since I have 
to build the whole racket environment).

Will
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


Re: [racket-dev] PLaneT Library of Iterations/Comprehensions

2010-08-18 Thread Sam Tobin-Hochstadt
On Wed, Aug 18, 2010 at 12:02 PM, Will M. Farr  wrote:
> Hello all,
>
> I've been thinking for a while about putting together a PLaneT library of 
> some iteration/comprehension forms that I often use that are not found in the 
> racket core.  Right now, I have a small it-comp.plt local PLaneT package that 
> contains
>
> for/vector
> for/flvector
> in-flvector

Great!

> The for/... forms have the option of having a first expression that gives the 
> length of the resulting object (similar to srfi-42's vector-of-length-ec 
> form) to allow generating more efficient code:
>
> (for/vector ((x (in-range 3))) x) => (vector 0 1 2)
> (for/vector 3 ((x (in-range 3))) x) => (vector 0 1 2) ; but more efficiently

What does this do if the specified length is wrong?

> Alternately, if you guys want to add these to the core, I'd be happy to 
> contribute code and tests

If you prepare a patch (with tests/docs) I'll get it committed.
-- 
sam th
sa...@ccs.neu.edu
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev


[racket-dev] PLaneT Library of Iterations/Comprehensions

2010-08-18 Thread Will M. Farr
Hello all,

I've been thinking for a while about putting together a PLaneT library of some 
iteration/comprehension forms that I often use that are not found in the racket 
core.  Right now, I have a small it-comp.plt local PLaneT package that contains

for/vector
for/flvector
in-flvector

The for/... forms have the option of having a first expression that gives the 
length of the resulting object (similar to srfi-42's vector-of-length-ec form) 
to allow generating more efficient code:

(for/vector ((x (in-range 3))) x) => (vector 0 1 2)
(for/vector 3 ((x (in-range 3))) x) => (vector 0 1 2) ; but more efficiently

I'll be adding more forms from time to time, as I need them.  Eventually, I'll 
release this to PLaneT, but I thought I might ask the community two questions 
first:

1. Am I duplicating the functionality of some library?  (If so, I'll just 
contribute to that instead.)
2. Do you have any iteration "favorites" that I should include in the library?  
(Code welcome, but I'm also happy to implement suggestions myself.)

Alternately, if you guys want to add these to the core, I'd be happy to 
contribute code and tests

Thanks,
Will
_
  For list-related administrative tasks:
  http://lists.racket-lang.org/listinfo/dev