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

From: Eli Barzilay (eli at barzilay.org)
Date: Thu Jun 21 04:24:37 EDT 2012

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!


Posted on the dev mailing list.