[plt-scheme] (no subject)
On Thu, 19 Apr 2007, Shriram Krishnamurthi wrote:
> See Robby's message. But, in BASIC, I can also say
>
> 10 GOTO 20
> 20 PRINT "HELLO WORLD"
Hmmm... ok, would this more closely capture the feeling of what's going
on?
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
;; Trying to encode the spirit of
;;
;; 10 GOTO 20
;; 20 PRINT "HELLO WORLD"
;;
;; using Scheme's continuations.
(define (program-2 k-end)
(let ([line-10 #f] [line-20 #f] [line-end #f])
(let/cc def-k
(begin
(let/cc k (set! line-10 k) (def-k))
(line-20)))
(let/cc def-k
(begin
(let/cc k (set! line-20 k) (def-k))
(printf "hello world\n")
(line-end)))
(let/cc def-k
(begin
(let/cc k (set! line-end k) (def-k))
(k-end)))
line-10))
(define (run prog)
(let/ec end ((prog end))))
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I can start it up as:
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
> (run program-2)
hello world
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
I get the feeling, though, that this is all terribly evil.
One of the things that doesn't make me happy about this is the way I'm
doing the linkage between lines; I guess I could write a NEXT-LINE helper
to simulate the program counter more elegantly rather than hardcoding it.