# [racket] Finite State Machines of Arbitrary Size using Racket's composable control

 From: Galler (lzgaller at optonline.net) Date: Thu May 24 14:15:34 EDT 2012 Previous message: [racket] Finite State Machines of Arbitrary Size using Racket's composable control Next message: [racket] Bindings for libgsl (GNU Scientific Library) Messages sorted by: [date] [thread] [subject] [author]

```So am I eligible for some kind of reinventing the wheel award at Rackcon
2012?

On Thu, May 24, 2012 at 1:53 PM, Eli Barzilay wrote:

> 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!
```

 Posted on the users mailing list. Previous message: [racket] Finite State Machines of Arbitrary Size using Racket's composable control Next message: [racket] Bindings for libgsl (GNU Scientific Library) Messages sorted by: [date] [thread] [subject] [author]