experiments/bidi-generator-example.ss
author Tony Garnock-Jones <tonygarnockjones@gmail.com>
Wed, 16 Jan 2019 17:15:58 +0000
changeset 438 1fe179d53161
parent 283 94f780251884
permissions -rw-r--r--
Add missing primitive implementation for the plain interpreter.
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
283
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     1
#lang scheme
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     2
(require "bidi-generator.ss")
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     3
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     4
(define (print-all)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     5
  (display "FIRST")
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     6
  (newline)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     7
  (do ()
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     8
    (#f)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
     9
    (display (yield))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    10
    (newline)))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    11
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    12
(let ((pa (generator () (print-all))))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    13
  (pa)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    14
  (pa 1)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    15
  (pa 2)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    16
  (pa 3))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    17
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    18
(define (yield-four)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    19
  (generator ()
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    20
             (yield 1)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    21
             (yield 2)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    22
             (yield 3)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    23
             (yield 4)
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    24
             'final-value))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    25
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    26
(let ((x (yield-four)))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    27
  (display (x))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    28
  (display (x 'a))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    29
  (display (x 'b))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    30
  (display (x 'c))
94f780251884 Bidirectional generator for MzScheme.
Tony Garnock-Jones <tonygarnockjones@gmail.com>
parents:
diff changeset
    31
  (display (x 'd)))