Posted by Anonymous Tue 27th Feb 2007 23:26 - Syntax is CSS - 32 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
-
-
(define-syntax state
-
(syntax-rules (else)
-
((_ (next-state test-case then-case)
-
...
-
(else
-
else-case))
-
(lambda (message)
-
(case message
-
((next-state)
-
(if test-case
-
then-case
-
else-case))
-
...
-
(else
-
else-case))))
-
((_ (next-state test-case then-case)
-
...)
-
(state
-
(next-state test-case then-case)
-
...
-
(else
-
#f)))))
-
-
(define-syntax states
-
(syntax-rules (else)
-
((_ (state-name
-
(next-state test-case then-case)
-
...)
-
...)
-
(begin
-
(define state-name
-
(state
-
(next-state test-case then-case)
-
...))
-
...))
-
((_ (state-name
-
(next-state test-case then-case)
-
...
-
(else
-
else-case))
-
...)
-
(begin
-
(define state-name
-
(state
-
(next-state test-case then-case)
-
...
-
(else
-
else-case)))
-
...))))
-
-
-
;;; Test the new programming structures from above.
-
-
-
(define available-power #t)
-
-
(states
-
(standby
-
(power available-power (begin (display "IDLE\n") idle))
-
(else
-
(begin (display "STANDBY\n") standby)))
-
-
(idle
-
(play #t (begin (display "PLAYING\n") playing))
-
(power #t (begin (display "STANDBY\n") standby))
-
(else
-
(begin (display "IDLE\n") idle)))
-
-
(playing
-
(stop #t (begin (display "IDLE\n") idle))
-
(power #t (begin (display "STANDBY\n") standby))
-
(else
-
(begin (display "PLAYING\n") playing))))
-
-
-
(define S standby)
-
-
(define S (S 'play))
-
(define S (S 'power))
-
(define S (S 'power))
-
(define S ((S 'power) 'play))
-
(define S (S 'stop))
-
(define S (S 'play))
-
(define S (S 'power))
-
(define S (S 'power))
-
PermaLink to this entry https://pastebin.co.uk/11095
Posted by Anonymous Tue 27th Feb 2007 23:26 - Syntax is CSS - 32 views
Download | New Post | Modify | Hide line numbers
Download | New Post | Modify | Hide line numbers
Comments: 0