A relevant side-comment is that this is a popular way for implementing tail-calls:
http://en.wikipedia.org/wiki/Tail_call#Through_trampolining 20 minutes ago, Galler wrote: > Y, that's closer to what I had in mind. > > > On Thu, May 24, 2012 at 1:18 PM, Eli Barzilay wrote: > > > Just now, Galler wrote: > >> Eli, > >> > >> I fully agree with you that any FSM is equivalent to functional > >> composition and can be implemented in the manner you show. > >> > >> However , in the way you've implemented the signal-handlers > >> > >> (define (B i) > >>> (if (= 0 (get i)) > >>> (begin (printf "~s)" (sub1 i)) > >>> (next A i)) > >> > >> I believe you have the signal handler B both reading the signal (get > >> i) and advancing to the next position in the signal-stream (next A i) > > > > IIUC, you could do that with something like this: > > > > (define (encode v) > > (define (get i) (vector-ref v i)) > > (define last (sub1 (vector-length v))) > > (define (next S i) (when (< i last) (S (add1 i)))) > > (define (B signal i) > > (if (= 0 signal) > > (begin (printf "~s)" (sub1 i)) > > A) > > B)) > > (define (A signal i) > > (if (= 0 signal) > > A > > (begin (printf "(~s " i) > > B))) > > (for/fold ([state A]) ([signal (in-vector v)] [i (in-naturals)]) > > (state signal i))) > > > > But it seems redundant since the abstraction was practically there in > > `next'. > > > > -- > > ((lambda (x) (x x)) (lambda (x) (x x))) Eli > > Barzilay: > > http://barzilay.org/ Maze is > > Life! -- ((lambda (x) (x x)) (lambda (x) (x x))) Eli Barzilay: http://barzilay.org/ Maze is Life! ____________________ Racket Users list: http://lists.racket-lang.org/users