Re: [racket-dev] for loop singleton optimization

2012-11-29 Thread J. Ian Johnson
That's not free-identifier=? so it wouldn't be optimized.
-Ian
- Original Message -
From: "Tobias Hammer" 
To: "Matthew Flatt" , "J. Ian Johnson" 
Cc: "dev" 
Sent: Thursday, November 29, 2012 4:49:15 AM GMT -05:00 US/Canada Eastern
Subject: Re: [racket-dev] for loop singleton optimization

What about

(let ([set (lambda (a) (set 1 2 a))])
   (for/list ([x (in-set (set 3))])
 x))

?

Tobias


On Wed, 28 Nov 2012 19:24:12 +0100, J. Ian Johnson   
wrote:

> Cool. I submitted a pull request with this change since it's always an  
> improvement.
> Thanks,
> -Ian
> - Original Message -
> From: "Matthew Flatt" 
> To: "J. Ian Johnson" 
> Cc: "dev" 
> Sent: Wednesday, November 28, 2012 12:58:09 PM GMT -05:00 US/Canada  
> Eastern
> Subject: Re: [racket-dev] for loop singleton optimization
>
> I think that would be an ad hoc optimization in each `in-'. For example,
>
> (define-sequence-syntax *in-set
>   (lambda () #'in-set)
>   (lambda (stx)
> (syntax-case stx ()
>   [[(id) (_ st)]
>
>
> in `racket/set' could change to
>
> (define-sequence-syntax *in-set
>   (lambda () #'in-set)
>   (lambda (stx)
> (syntax-case stx (set)
>   [[(id) (_ (set v))]
>#`[(id) (in-value v)]]
>   [[(id) (_ st)]
>
>
>
> At Wed, 28 Nov 2012 12:50:49 -0500 (EST), "J. Ian Johnson" wrote:
>> It would be great to optimize singletons out of comprehensions, since I  
>> (and
>> probably others) have macros that expand into singleton constructors  
>> that are
>> much better suited to just be a rebinding.
>>
>> > (time (for ([n (in-range 1 100)]) (for ([k (in-set (set n))])  
>> (random
>> k
>> cpu time: 340 real time: 338 gc time: 16
>> > (time (for ([n (in-range 1 100)]) (for ([k (in-value n)]) (random  
>> k
>> cpu time: 120 real time: 118 gc time: 0
>>
>> Is this easily added to for.rkt?
>>
>> -Ian
>> _
>>   Racket Developers list:
>>   http://lists.racket-lang.org/dev
> _
>   Racket Developers list:
>   http://lists.racket-lang.org/dev


-- 
-
Tobias Hammer
DLR / Institute of Robotics and Mechatronics
Muenchner Str. 20, D-82234 Wessling
Tel.: 08153/28-1487
Mail: tobias.ham...@dlr.de
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] for loop singleton optimization

2012-11-29 Thread Matthew Flatt
That works fine (i.e., does not get changed to `in-value').

Matching `set' as a literal in `syntax-case' works by identifier
binding, not symbolically. If `set' has a different binding than the
one exported by the module, then the optimizing case doesn't match.

At Thu, 29 Nov 2012 10:49:15 +0100, Tobias Hammer wrote:
> What about
> 
> (let ([set (lambda (a) (set 1 2 a))])
>(for/list ([x (in-set (set 3))])
>  x))
> 
> ?
> 
> Tobias
> 
> 
> On Wed, 28 Nov 2012 19:24:12 +0100, J. Ian Johnson   
> wrote:
> 
> > Cool. I submitted a pull request with this change since it's always an  
> > improvement.
> > Thanks,
> > -Ian
> > - Original Message -
> > From: "Matthew Flatt" 
> > To: "J. Ian Johnson" 
> > Cc: "dev" 
> > Sent: Wednesday, November 28, 2012 12:58:09 PM GMT -05:00 US/Canada  
> > Eastern
> > Subject: Re: [racket-dev] for loop singleton optimization
> >
> > I think that would be an ad hoc optimization in each `in-'. For example,
> >
> > (define-sequence-syntax *in-set
> >   (lambda () #'in-set)
> >   (lambda (stx)
> > (syntax-case stx ()
> >   [[(id) (_ st)]
> >
> >
> > in `racket/set' could change to
> >
> > (define-sequence-syntax *in-set
> >   (lambda () #'in-set)
> >   (lambda (stx)
> > (syntax-case stx (set)
> >   [[(id) (_ (set v))]
> >#`[(id) (in-value v)]]
> >   [[(id) (_ st)]
> >
> >
> >
> > At Wed, 28 Nov 2012 12:50:49 -0500 (EST), "J. Ian Johnson" wrote:
> >> It would be great to optimize singletons out of comprehensions, since I  
> >> (and
> >> probably others) have macros that expand into singleton constructors  
> >> that are
> >> much better suited to just be a rebinding.
> >>
> >> > (time (for ([n (in-range 1 100)]) (for ([k (in-set (set n))])  
> >> (random
> >> k
> >> cpu time: 340 real time: 338 gc time: 16
> >> > (time (for ([n (in-range 1 100)]) (for ([k (in-value n)]) (random  
> >> k
> >> cpu time: 120 real time: 118 gc time: 0
> >>
> >> Is this easily added to for.rkt?
> >>
> >> -Ian
> >> _
> >>   Racket Developers list:
> >>   http://lists.racket-lang.org/dev
> > _
> >   Racket Developers list:
> >   http://lists.racket-lang.org/dev
> 
> 
> -- 
> -
> Tobias Hammer
> DLR / Institute of Robotics and Mechatronics
> Muenchner Str. 20, D-82234 Wessling
> Tel.: 08153/28-1487
> Mail: tobias.ham...@dlr.de
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] for loop singleton optimization

2012-11-29 Thread Tobias Hammer

What about

(let ([set (lambda (a) (set 1 2 a))])
  (for/list ([x (in-set (set 3))])
x))

?

Tobias


On Wed, 28 Nov 2012 19:24:12 +0100, J. Ian Johnson   
wrote:


Cool. I submitted a pull request with this change since it's always an  
improvement.

Thanks,
-Ian
- Original Message -
From: "Matthew Flatt" 
To: "J. Ian Johnson" 
Cc: "dev" 
Sent: Wednesday, November 28, 2012 12:58:09 PM GMT -05:00 US/Canada  
Eastern

Subject: Re: [racket-dev] for loop singleton optimization

I think that would be an ad hoc optimization in each `in-'. For example,

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
(syntax-case stx ()
  [[(id) (_ st)]
   

in `racket/set' could change to

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
(syntax-case stx (set)
  [[(id) (_ (set v))]
   #`[(id) (in-value v)]]
  [[(id) (_ st)]
   


At Wed, 28 Nov 2012 12:50:49 -0500 (EST), "J. Ian Johnson" wrote:
It would be great to optimize singletons out of comprehensions, since I  
(and
probably others) have macros that expand into singleton constructors  
that are

much better suited to just be a rebinding.

> (time (for ([n (in-range 1 100)]) (for ([k (in-set (set n))])  
(random

k
cpu time: 340 real time: 338 gc time: 16
> (time (for ([n (in-range 1 100)]) (for ([k (in-value n)]) (random  
k

cpu time: 120 real time: 118 gc time: 0

Is this easily added to for.rkt?

-Ian
_
  Racket Developers list:
  http://lists.racket-lang.org/dev

_
  Racket Developers list:
  http://lists.racket-lang.org/dev



--
-
Tobias Hammer
DLR / Institute of Robotics and Mechatronics
Muenchner Str. 20, D-82234 Wessling
Tel.: 08153/28-1487
Mail: tobias.ham...@dlr.de
_
 Racket Developers list:
 http://lists.racket-lang.org/dev


Re: [racket-dev] for loop singleton optimization

2012-11-28 Thread J. Ian Johnson
Cool. I submitted a pull request with this change since it's always an 
improvement.
Thanks,
-Ian
- Original Message -
From: "Matthew Flatt" 
To: "J. Ian Johnson" 
Cc: "dev" 
Sent: Wednesday, November 28, 2012 12:58:09 PM GMT -05:00 US/Canada Eastern
Subject: Re: [racket-dev] for loop singleton optimization

I think that would be an ad hoc optimization in each `in-'. For example,

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
(syntax-case stx ()
  [[(id) (_ st)]
   

in `racket/set' could change to

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
(syntax-case stx (set)
  [[(id) (_ (set v))]
   #`[(id) (in-value v)]]
  [[(id) (_ st)]
   


At Wed, 28 Nov 2012 12:50:49 -0500 (EST), "J. Ian Johnson" wrote:
> It would be great to optimize singletons out of comprehensions, since I (and 
> probably others) have macros that expand into singleton constructors that are 
> much better suited to just be a rebinding.
> 
> > (time (for ([n (in-range 1 100)]) (for ([k (in-set (set n))]) (random 
> k
> cpu time: 340 real time: 338 gc time: 16
> > (time (for ([n (in-range 1 100)]) (for ([k (in-value n)]) (random k
> cpu time: 120 real time: 118 gc time: 0
> 
> Is this easily added to for.rkt?
> 
> -Ian
> _
>   Racket Developers list:
>   http://lists.racket-lang.org/dev
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


Re: [racket-dev] for loop singleton optimization

2012-11-28 Thread Matthew Flatt
I think that would be an ad hoc optimization in each `in-'. For example,

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
(syntax-case stx ()
  [[(id) (_ st)]
   

in `racket/set' could change to

(define-sequence-syntax *in-set
  (lambda () #'in-set)
  (lambda (stx)
(syntax-case stx (set)
  [[(id) (_ (set v))]
   #`[(id) (in-value v)]]
  [[(id) (_ st)]
   


At Wed, 28 Nov 2012 12:50:49 -0500 (EST), "J. Ian Johnson" wrote:
> It would be great to optimize singletons out of comprehensions, since I (and 
> probably others) have macros that expand into singleton constructors that are 
> much better suited to just be a rebinding.
> 
> > (time (for ([n (in-range 1 100)]) (for ([k (in-set (set n))]) (random 
> k
> cpu time: 340 real time: 338 gc time: 16
> > (time (for ([n (in-range 1 100)]) (for ([k (in-value n)]) (random k
> cpu time: 120 real time: 118 gc time: 0
> 
> Is this easily added to for.rkt?
> 
> -Ian
> _
>   Racket Developers list:
>   http://lists.racket-lang.org/dev
_
  Racket Developers list:
  http://lists.racket-lang.org/dev


[racket-dev] for loop singleton optimization

2012-11-28 Thread J. Ian Johnson
It would be great to optimize singletons out of comprehensions, since I (and 
probably others) have macros that expand into singleton constructors that are 
much better suited to just be a rebinding.

> (time (for ([n (in-range 1 100)]) (for ([k (in-set (set n))]) (random 
> k
cpu time: 340 real time: 338 gc time: 16
> (time (for ([n (in-range 1 100)]) (for ([k (in-value n)]) (random k
cpu time: 120 real time: 118 gc time: 0

Is this easily added to for.rkt?

-Ian
_
  Racket Developers list:
  http://lists.racket-lang.org/dev