-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrefal-runtime.lisp
68 lines (49 loc) · 1.36 KB
/
refal-runtime.lisp
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
55
56
57
58
59
60
61
62
63
64
65
66
67
68
;;;; Refal builtin functions & runtime
;;;; (c) paul7, 2010
(defpackage :net.paul7.refal.runtime
(:nicknames :rrt)
(:use :common-lisp
:net.paul7.utility
:net.paul7.refal.internal
:net.paul7.refal.parser)
(:export))
(in-package :net.paul7.refal.runtime)
;; define & register builtin function
(defmacro defbuiltin (name (scope)
&body body)
`(setf (refal-entry *global* ,name)
#'(lambda (,scope)
,@body)))
(defmacro defapply (name function)
(with-gensyms (scope)
`(defbuiltin ,name (,scope)
(data->scope (mklist (apply ,function (data ,scope)))))))
(defmacro defuncall (name function)
(with-gensyms (scope)
`(defbuiltin ,name (,scope)
(data->scope (mklist (funcall ,function (data ,scope)))))))
(reset-module *global*)
(defuncall "ident" #'identity)
(defapply "+" #'+)
(defapply "-" #'-)
(defapply "*" #'*)
(defapply "=" #'=)
(defuncall "Prout" #'prout)
(defuncall "Print" #'print-return)
(defbuiltin "Card" (scope)
(declare (ignore scope))
(string->scope (read-line)))
(defgeneric prout (object))
(defmethod prout ((basic-object t))
(format t "~a" basic-object))
(defmethod prout ((list cons))
(dolist (each list)
(prout each)
(format t " ")))
(defmethod prout ((scope refal-scope))
(format t "(")
(prout (data scope))
(format t ")"))
(defun print-return (object)
(prout object)
object)