Before implementing import name resolution, then after fic macro imports

This commit is contained in:
Felix Brendel
2019-06-03 16:19:37 +02:00
parent 3fb2326dd3
commit f77e4c56b3
20 changed files with 295 additions and 3226 deletions
+36 -28
View File
@@ -53,7 +53,23 @@
(define-syntax (define-special name-and-args :rest body)
`(define ,(first name-and-args) (special-lambda ,(rest name-and-args) @body)))
(define-syntax (do-list :rest body)
(define-syntax (construct-list :rest body)
"
(construct-list
i <- '(1 2 3 4 5)
yield (* i i))
(construct-list
i <- '(1 2 3 4)
j <- '(A B)
yield (pair i j))
(construct-list
i <- '(1 2 3 4 5 6 7 8)
when (evenp i)
yield i)
"
(define (append-map f ll)
(unless (= ll ())
(define val (f (first ll)))
@@ -73,32 +89,29 @@
`(if ,(first (rest body)) ,(rec (rest (rest body)))))
((= (first body) 'yield)
(first (rest body)))
(t (error "Not a do-able expression: ~S" `(quote ,body))))
)
(else (error "Not a do-able expression"))))
(rec body))
(define-syntax (apply fun seq)
"Applies the funciton to the sequence, as in calls the function with
ithe sequence as arguemens."
`(eval (pair ,fun ,seq)))
;; (define (append-map f ll)
;; (unless (= ll ())
;; (define val (f (first ll)))
;; (if (= (first val) ())
;; (append-map f (rest ll))
;; (extend
;; val
;; (append-map f (rest ll))))))
;; (define-special (do-list :rest body)
;; (cond
;; ((= () body) ())
;; ((= () (rest body)) (first body))
;; ((= (first (rest body)) '<-)
;; `(,append-map (lambda (,(first body)) (list ,(eval `(do-list @(rest (rest (rest body))))))) ,(first (rest (rest body)))))
;; ((= (first body) 'when)
;; `(if ,(first (rest body)) ,(eval `(do-list @(rest (rest body))))))
;; ((= (first body) 'yield)
;; (first (rest body)))
;; (t (error "Not a do-able expression: ~S" `(quote ,body))))
;; )
(define-syntax (define-package name :rest body)
`(define ,(string->symbol (concat-strings (symbol->string name) "->"))
((lambda ()
@body
(set-type
(special-lambda (:rest args)
(let ((op (first args))
(args (rest args)))
(cond ((= op 'pi) 3.14159265)
(else (try (apply op args)
(error "The package does not contain this operation"))))))
:package)))))
(define (nil? x)
"Checks if the argument is nil."
@@ -136,11 +149,6 @@
"Checks if the argument is a built-in function."
(= (type x) :built-in-function))
(define (apply fun seq)
"Applies the funciton to the sequence, as in calls the function with
ithe sequence as arguemens."
(eval (pair fun seq)))
(define (end seq)
"Returns the last pair in the sqeuence."
(if (or (nil? seq) (not (pair? (rest seq))))