Re: [racket-dev] Make range cooperate with for loops?
> On Jan 4, 2017, at 2:47 PM, Gustavo Massaccesi wrote: > > I'm not sure that it's so easy. The transformation must ensure that > this program works correctly: Oh, I didn't say it was easy. Macro mischief: always with us. #lang racket (define-syntax-rule (range x ...) (reverse (for/list ([i (in-range x ...)]) i))) (for ([i (range 5)]) (displayln i)) -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscr...@googlegroups.com. To post to this group, send email to racket-dev@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/97DE32E7-B618-438E-8D2C-9A74510365CB%40mbtype.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-dev] Make range cooperate with for loops?
I'm not sure that it's so easy. The transformation must ensure that this program works correctly: #lang racket (define-syntax-rule (#%datum . x) '(2 2 2)) (for ([i 5]) (displayln i)) Gustavo On Wed, Jan 4, 2017 at 7:17 PM, Matthew Butterick wrote: > > On Jan 3, 2017, at 6:07 PM, Robby Findler > wrote: > > I think that people coming from python will expect that `in-range`s > name is `range`. So why not meet their expectations? > > > If you give a mouse a cookie ... > > > Though it does seem that exact nonnegative integers — which behave as > sequences when used in the iterator position — should also expand to > `in-range`. > > (for/list ([i (in-range 5)]) > i) > > (for/list ([i (range 5)]) > i) > > (for/list ([i 5]) > i) > > -- > You received this message because you are subscribed to the Google Groups > "Racket Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-dev+unsubscr...@googlegroups.com. > To post to this group, send email to racket-dev@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-dev/BEC9DAE3-FAEB-4412-82AD-67EDAD6245E1%40mbtype.com. > > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscr...@googlegroups.com. To post to this group, send email to racket-dev@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAPaha9MPibXtrL6xLR2rNYdr9O6bP_1sGbpR%2BAFXcm%2BQVwhu1Q%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-dev] Make range cooperate with for loops?
> On Jan 3, 2017, at 6:07 PM, Robby Findler wrote: > > I think that people coming from python will expect that `in-range`s > name is `range`. So why not meet their expectations? If you give a mouse a cookie ... Though it does seem that exact nonnegative integers — which behave as sequences when used in the iterator position — should also expand to `in-range`. (for/list ([i (in-range 5)]) i) (for/list ([i (range 5)]) i) (for/list ([i 5]) i) -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscr...@googlegroups.com. To post to this group, send email to racket-dev@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/BEC9DAE3-FAEB-4412-82AD-67EDAD6245E1%40mbtype.com. For more options, visit https://groups.google.com/d/optout.
Re: [racket-dev] Make range cooperate with for loops?
Go for it!! Robby On Tue, Jan 3, 2017 at 12:49 PM, Alexis King wrote: > A question[1] was asked on Stack Overflow today that used `range` from > racket/list in a for loop, then was baffled as to why it was so slow compared > to a manually written loop using named let. To some extent, confusion of this > sort is unavoidable, since it stems from a confusion about the difference > between lists and sequences, but this seems like a reasonably common mistake > to make. Is there any reason `range` cannot be adjusted to cooperate with for > loops so that it gets compiled like `in-range`? > > It seems like there would be two ways to do this: either make for loops > recognize `range` like `in-range`, or make `range` a macro using > define-sequence-syntax that just expands to the existing `range` procedure > when used in an expression context. Both of these could easily be made > backwards compatible, and it could only make things faster. Is there any > technical or philosophical reason to not do that before I attempt it? > > [1]: http://stackoverflow.com/q/41444129/465378 > > -- > You received this message because you are subscribed to the Google Groups > "Racket Developers" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to racket-dev+unsubscr...@googlegroups.com. > To post to this group, send email to racket-dev@googlegroups.com. > To view this discussion on the web visit > https://groups.google.com/d/msgid/racket-dev/4ED13FA1-45FC-4EAC-94EB-AFF15D91EAB0%40gmail.com. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscr...@googlegroups.com. To post to this group, send email to racket-dev@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/CAL3TdOMgfyyMGNNTP0qqt0NJ9dNF-rbzrsvceNpuMLEnf-ZswQ%40mail.gmail.com. For more options, visit https://groups.google.com/d/optout.
[racket-dev] Make range cooperate with for loops?
A question[1] was asked on Stack Overflow today that used `range` from racket/list in a for loop, then was baffled as to why it was so slow compared to a manually written loop using named let. To some extent, confusion of this sort is unavoidable, since it stems from a confusion about the difference between lists and sequences, but this seems like a reasonably common mistake to make. Is there any reason `range` cannot be adjusted to cooperate with for loops so that it gets compiled like `in-range`? It seems like there would be two ways to do this: either make for loops recognize `range` like `in-range`, or make `range` a macro using define-sequence-syntax that just expands to the existing `range` procedure when used in an expression context. Both of these could easily be made backwards compatible, and it could only make things faster. Is there any technical or philosophical reason to not do that before I attempt it? [1]: http://stackoverflow.com/q/41444129/465378 -- You received this message because you are subscribed to the Google Groups "Racket Developers" group. To unsubscribe from this group and stop receiving emails from it, send an email to racket-dev+unsubscr...@googlegroups.com. To post to this group, send email to racket-dev@googlegroups.com. To view this discussion on the web visit https://groups.google.com/d/msgid/racket-dev/4ED13FA1-45FC-4EAC-94EB-AFF15D91EAB0%40gmail.com. For more options, visit https://groups.google.com/d/optout.