Thank you for your comment

Beau­tiful Racket / tuto­rials

sample.rkt
#lang basic
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5 rem ignored
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end
1
2
3
4
5
6
7
8
9
#lang basic
30 rem print 'ignored'
35
50 print "never gets here"
40 end
60 print 'three' : print 1.0 + 3
70 goto 11. + 18.5 + .5 rem ignored
10 print "o" ; "n" ; "e"
20 print : goto 60.0 : end
copy to clipboard
basic/expander.rkt
#lang br/quicklang
1
#lang br/quicklang
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  #'(define (NUM) (void) STATEMENT ...))
1
2
3
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  #'(define (NUM) (void) STATEMENT ...))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM)])
    #'(define (LINE-NUM) (void) STATEMENT ...)))
1
2
3
4
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM)])
    #'(define (LINE-NUM) (void) STATEMENT ...)))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
                                      #:source #'NUM)])
    #'(define (LINE-NUM) (void) STATEMENT ...)))
1
2
3
4
5
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
                                      #:source #'NUM)])
    #'(define (LINE-NUM) (void) STATEMENT ...)))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
                                      #:source #'NUM)])
    (syntax/loc caller-stx
      (define (LINE-NUM) (void) STATEMENT ...))))
1
2
3
4
5
6
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
                                      #:source #'NUM)])
    (syntax/loc caller-stx
      (define (LINE-NUM) (void) STATEMENT ...))))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  #'(#%module-begin
     LINE ...))
(provide (rename-out [b-module-begin #%module-begin]))
1
2
3
4
5
6
7
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  #'(#%module-begin
     LINE ...))
(provide (rename-out [b-module-begin #%module-begin]))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  #'(#%module-begin
     LINE ...
     (define line-table ···)
     (void (run line-table))))
(provide (rename-out [b-module-begin #%module-begin]))
1
2
3
4
5
6
7
8
9
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  #'(#%module-begin
     LINE ...
     (define line-table ···)
     (void (run line-table))))
(provide (rename-out [b-module-begin #%module-begin]))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  #'(#%module-begin
     LINE ...
     (define line-table
       (apply hasheqv (append (list NUM LINE-FUNC) ...)))
     (void (run line-table))))
(provide (rename-out [b-module-begin #%module-begin]))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  #'(#%module-begin
     LINE ...
     (define line-table
       (apply hasheqv (append (list NUM LINE-FUNC) ...)))
     (void (run line-table))))
(provide (rename-out [b-module-begin #%module-begin]))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([(NUM ...) ···]
       [(LINE-FUNC ...) ···])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([(NUM ...) ···]
       [(LINE-FUNC ...) ···])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([((b-line NUM STATEMENT ...) ...) #'(LINE ...)]
       [(LINE-FUNC ...) ···])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([((b-line NUM STATEMENT ...) ...) #'(LINE ...)]
       [(LINE-FUNC ...) ···])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([((b-line NUM STATEMENT ...) ...) #'(LINE ...)]
       [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([((b-line NUM STATEMENT ...) ...) #'(LINE ...)]
       [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(define (run line-table)
  ···)
1
2
3
4
5
6
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(define (run line-table)
  ···)
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  ···)
1
2
3
4
5
6
7
8
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  ···)
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (for/fold ([line-idx 0])
            ([i (in-naturals)]
            #:break (>= line-idx (vector-length line-vec)))
    (define line-num (vector-ref line-vec line-idx))
    (define line-func (hash-ref line-table line-num))
    (line-func)
    (add1 line-idx)))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (for/fold ([line-idx 0])
            ([i (in-naturals)]
            #:break (>= line-idx (vector-length line-vec)))
    (define line-num (vector-ref line-vec line-idx))
    (define line-func (hash-ref line-table line-num))
    (line-func)
    (add1 line-idx)))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (run line-table) ···)
1
2
3
4
5
6
7
8
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (run line-table) ···)
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table) ···)
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table) ···)
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (with-handlers ([end-program-signal? (λ (exn-val) (void))])
    (for/fold ([line-idx 0])
              ([i (in-naturals)]
               #:break (>= line-idx (vector-length line-vec)))
      (define line-num (vector-ref line-vec line-idx))
      (define line-func (hash-ref line-table line-num))
      (line-func)
      (add1 line-idx))))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (with-handlers ([end-program-signal? (λ (exn-val) (void))])
    (for/fold ([line-idx 0])
              ([i (in-naturals)]
               #:break (>= line-idx (vector-length line-vec)))
      (define line-num (vector-ref line-vec line-idx))
      (define line-func (hash-ref line-table line-num))
      (line-func)
      (add1 line-idx))))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (with-handlers ([end-program-signal? (λ (exn-val) (void))])
    (for/fold ([line-idx 0])
              ([i (in-naturals)]
               #:break (>= line-idx (vector-length line-vec)))
      (define line-num (vector-ref line-vec line-idx))
      (define line-func (hash-ref line-table line-num))
      (with-handlers
          ([change-line-signal?
            (λ (cls)
              (define clsv (change-line-signal-val cls))
              (or
               (and (exact-positive-integer? clsv)
                    (vector-member clsv line-vec))
               (error
                (format "error in line ~a: line ~a not found"
                        line-num clsv))))])
        (line-func)
        (add1 line-idx)))))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (with-handlers ([end-program-signal? (λ (exn-val) (void))])
    (for/fold ([line-idx 0])
              ([i (in-naturals)]
               #:break (>= line-idx (vector-length line-vec)))
      (define line-num (vector-ref line-vec line-idx))
      (define line-func (hash-ref line-table line-num))
      (with-handlers
          ([change-line-signal?
            (λ (cls)
              (define clsv (change-line-signal-val cls))
              (or
               (and (exact-positive-integer? clsv)
                    (vector-member clsv line-vec))
               (error
                (format "error in line ~a: line ~a not found"
                        line-num clsv))))])
        (line-func)
        (add1 line-idx)))))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table) ···)

(define (b-rem val) (void))
(define (b-print . vals)
  (displayln (string-append* (map ~a vals))))
(define (b-sum . nums) (apply + nums))
(define (b-expr expr)
  (if (integer? expr) (inexact->exact expr) expr))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
#lang br/quicklang
(define-macro (b-line NUM STATEMENT ...) ···)
(define-macro (b-module-begin (b-program LINE ...)) ···)

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table) ···)

(define (b-rem val) (void))
(define (b-print . vals)
  (displayln (string-append* (map ~a vals))))
(define (b-sum . nums) (apply + nums))
(define (b-expr expr)
  (if (integer? expr) (inexact->exact expr) expr))
copy to clipboard
basic/expander.rkt
#lang br/quicklang
(provide (matching-identifiers-out #rx"^b-" (all-defined-out)))

(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
                                      #:source #'NUM)])
    (syntax/loc caller-stx
      (define (LINE-NUM) (void) STATEMENT ...))))

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([((b-line NUM STMT ...) ...) #'(LINE ...)]
       [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (with-handlers ([end-program-signal? (λ (exn-val) (void))])
    (for/fold ([line-idx 0])
              ([i (in-naturals)]
               #:break (>= line-idx (vector-length line-vec)))
      (define line-num (vector-ref line-vec line-idx))
      (define line-func (hash-ref line-table line-num))
      (with-handlers
          ([change-line-signal?
            (λ (cls)
              (define clsv (change-line-signal-val cls))
              (or
               (and (exact-positive-integer? clsv)
                    (vector-member clsv line-vec))
               (error
                (format "error in line ~a: line ~a not found"
                        line-num clsv))))])
        (line-func)
        (add1 line-idx)))))

(define (b-rem val) (void))
(define (b-print . vals)
  (displayln (string-append* (map ~a vals))))
(define (b-sum . vals) (apply + vals))
(define (b-expr expr)
  (if (integer? expr) (inexact->exact expr) expr))
 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
#lang br/quicklang
(provide (matching-identifiers-out #rx"^b-" (all-defined-out)))

(define-macro (b-line NUM STATEMENT ...)
  (with-pattern ([LINE-NUM (prefix-id "line-" #'NUM
                                      #:source #'NUM)])
    (syntax/loc caller-stx
      (define (LINE-NUM) (void) STATEMENT ...))))

(define-macro (b-module-begin (b-program LINE ...))
  (with-pattern
      ([((b-line NUM STMT ...) ...) #'(LINE ...)]
       [(LINE-FUNC ...) (prefix-id "line-" #'(NUM ...))])
    #'(#%module-begin
       LINE ...
       (define line-table
         (apply hasheqv (append (list NUM LINE-FUNC) ...)))
       (void (run line-table)))))
(provide (rename-out [b-module-begin #%module-begin]))

(struct end-program-signal ())
(struct change-line-signal (val))

(define (b-end) (raise (end-program-signal)))
(define (b-goto expr) (raise (change-line-signal expr)))

(define (run line-table)
  (define line-vec
    (list->vector (sort (hash-keys line-table) <)))
  (with-handlers ([end-program-signal? (λ (exn-val) (void))])
    (for/fold ([line-idx 0])
              ([i (in-naturals)]
               #:break (>= line-idx (vector-length line-vec)))
      (define line-num (vector-ref line-vec line-idx))
      (define line-func (hash-ref line-table line-num))
      (with-handlers
          ([change-line-signal?
            (λ (cls)
              (define clsv (change-line-signal-val cls))
              (or
               (and (exact-positive-integer? clsv)
                    (vector-member clsv line-vec))
               (error
                (format "error in line ~a: line ~a not found"
                        line-num clsv))))])
        (line-func)
        (add1 line-idx)))))

(define (b-rem val) (void))
(define (b-print . vals)
  (displayln (string-append* (map ~a vals))))
(define (b-sum . vals) (apply + vals))
(define (b-expr expr)
  (if (integer? expr) (inexact->exact expr) expr))
copy to clipboard
← prev next →