aboutsummaryrefslogtreecommitdiff
path: root/racket/step1_read_print.rkt
blob: a5d8ac77616bc6a2737f107add530db8b2e6faa5 (plain)
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
#!/usr/bin/env racket
#lang racket

(require "readline.rkt" "types.rkt" "reader.rkt" "printer.rkt")

;; read
(define (READ str)
  (read_str str))

;; eval
(define (EVAL ast env)
  ast)

;; print
(define (PRINT exp)
  (pr_str exp true))

;; repl
(define (rep str)
  (PRINT (EVAL (READ str) "")))

(define (repl-loop)
  (let ([line (readline "user> ")])
    (when (not (eq? nil line))
      (with-handlers
        ([string? (lambda (exc) (printf "Error: ~a~n" exc))]
         [blank-exn? (lambda (exc) null)])
        (printf "~a~n" (rep line)))
      (repl-loop))))
(repl-loop)