mirror of
https://github.com/kanaka/mal.git
synced 2024-11-13 01:43:50 +03:00
31 lines
577 B
Racket
31 lines
577 B
Racket
|
#!/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)
|