Permalink
Browse files

repl: boolean,char,string

  • Loading branch information...
1 parent 5cb6a0f commit 2028268b35a3c4bcd3835992212a2e655c8bb62a @sile committed May 7, 2012
Showing with 37 additions and 0 deletions.
  1. BIN plc/stdlib/eval.bc
  2. +17 −0 plc/stdlib/eval.lisp
  3. BIN plc/stdlib/print.bc
  4. +20 −0 plc/stdlib/print.lisp
View
Binary file not shown.
View
@@ -1,7 +1,11 @@
(begin
(define __int__ 1)
+ (define __string__ 2)
+ (define __char__ 3)
(define __symbol__ 4)
(define __nil__ 5)
+ (define __true__ 6)
+ (define __false__ 7)
(define __undef__ 9)
(define __apply__ 101)
(define __symget__ 50)
@@ -54,6 +58,16 @@
(define !cp-symbol (lambda (sym env)
(!cp-symbol-value sym env)))
+ (define !cp-char (lambda (ch)
+ (flat-list __char__ (int->list (char->integer ch)))))
+
+ (define !cp-string (lambda (str)
+ (let ((str (map char->integer (string->list str))))
+ (flat-list __string__ (int->list (length str)) str))))
+
+ (define !cp-boolean (lambda (bool)
+ (if bool (flat-list __true__) (flat-list __false__))))
+
(define !init-env (lambda ()
'(
(quote . #f)
@@ -70,6 +84,9 @@
(case (type-of exp)
((null) (!cp-null))
((number) (!cp-number exp))
+ ((boolean)(!cp-boolean exp))
+ ((char) (!cp-char exp))
+ ((string) (!cp-string exp))
((pair) (!cp-pair exp env))
((symbol) (if (!env-quote? env)
(!cp-symbol-self exp env)
View
Binary file not shown.
View
@@ -37,11 +37,31 @@
(!write-pair-impl pair)
(write-string ")")))
+ (define !write-boolean (lambda (bool)
+ (if bool (write-string "#t") (write-string "#f"))))
+
+ (define !write-char (lambda (ch)
+ (write-char #\#)
+ (write-char #\\)
+ (write-char ch)))
+
+ (define !write-string (lambda (str)
+ (write-char #\")
+ (for-each (lambda (ch)
+ (case ch
+ ((#\\ #\") (write-char #\\) (write-char ch))
+ (else (write-char ch))))
+ (string->list str))
+ (write-char #\")))
+
(define write-no-nl (lambda (x)
(case (type-of x)
((null) (write-string "()"))
((number) (!write-number x))
((symbol) (!write-symbol x))
+ ((boolean)(!write-boolean x))
+ ((char) (!write-char x))
+ ((string) (!write-string x))
((pair) (!write-pair x))
((procedure) (!write-procedure x))
(else (if (eq x (undef))

0 comments on commit 2028268

Please sign in to comment.