[racket-dev] sequence syntax for (mlist #t #f …) ?

From: Robby Findler (robby at eecs.northwestern.edu)
Date: Thu Jun 21 04:34:48 EDT 2012

I usually in-naturals and zero? to do this.

I see that one example (that I didn't write is in base-render.rkt

    (define/public (render-nested-flow i part ri starting-item?)
      (for/list ([b (in-list (nested-flow-blocks i))]
                 [pos (in-naturals)])
        (render-block b part ri (and starting-item? (zero? pos)))))

Robby

On Thu, Jun 21, 2012 at 3:24 AM, Eli Barzilay <eli at barzilay.org> wrote:
> An hour and a half ago, John Clements wrote:
>> Reality check before I do something dumb and re-invent the wheel:
>>
>> I often want to write a for loop where the first element is treated
>> specially. In such cases, it would be nice to have a sequence that
>> had a #t and then an infinite number of #f's, so I could write
>>
>> (for ([s my-sequence] [first? <true-then-always-falses>]) …)
>
> What are you using it for?  (Out of curiosity, I wonder if there's any
> need for this that doesn't fall under what `add-between' does.)
>
>
>> I'd be sort of okay with writing
>>
>> (mcons #t #0=(mcons #f #0#))
>
> I don't think that I've seen any implementation that would be fine
> with that -- you'd want '(#t . #0=(#f . #0#)), which is not allowed
> either, but this still works:
>
>  (read (open-input-string "(#t . #0=(#f . #0#))"))
>
>
>> Yes, of course I can do it the ugly way:
>> [...]
>> (define p1 (mcons #f 'bogus))
>> (set-mcdr! p1 p1)
>> (define true-then-falses (mcons #t p1))
>
> What about
>
>  (shared ([fs (cons #f fs)]) (cons #t fs))
>  (cons #t (shared ([fs (cons #f fs)]) fs))
>
> (or in lazy:
>
>  (letrec ([fs (cons #t (cons #f (cdr fs)))]) fs)
>
> )
>
> And if you want to use a for loop with that, you can do this:
>
>  (in-sequences (in-value #t) (in-cycle (in-value #f)))
>
> --
>          ((lambda (x) (x x)) (lambda (x) (x x)))          Eli Barzilay:
>                    http://barzilay.org/                   Maze is Life!
>
> _________________________
>  Racket Developers list:
>  http://lists.racket-lang.org/dev


Posted on the dev mailing list.