Macros are now properly getting baked in Modules bug still persists

This commit is contained in:
Felix Brendel
2020-03-10 00:30:27 +01:00
parent 3b85873039
commit aac3985a61
20 changed files with 593 additions and 508 deletions
+33 -33
View File
@@ -14,7 +14,7 @@
(define the-empty-stream ())
(define (stream-null? s) (if s t ()))
(define (stream-null? s) (when s t))
(define-syntax (delay expr)
`(,lambda () ,expr))
@@ -26,7 +26,7 @@
(define-syntax (add . args) (pair '+ args))
(define-syntax (when condition . body)
:doc "Special form for when multiple actions should be done if a
"Special form for when multiple actions should be done if a
condition is true.
{{{example_start}}}
@@ -46,14 +46,14 @@ condition is true.
(define-syntax (unless condition . body)
:doc "Special form for when multiple actions should be done if a
"Special form for when multiple actions should be done if a
condition is false."
(if (= (rest body) ())
`(if ,condition nil ,@body)
`(if ,condition nil (begin ,@body))))
(define-syntax (n-times times action)
:doc "Executes action times times."
"Executes action times times."
(define (repeat times elem)
(unless (> 1 times)
(pair elem (repeat (- times 1) elem))))
@@ -102,7 +102,7 @@ condition is false."
(rec clauses))
(define-syntax (construct-list . body)
:doc "
"
{{{example_start}}}
(construct-list
i <- '(1 2 3 4 5)
@@ -143,7 +143,7 @@ condition is false."
(rec body))
;; (define-syntax (apply fun seq)
;; :doc "Applies the function to the sequence, as in calls the function with
;; "Applies the function to the sequence, as in calls the function with
;; ithe sequence as arguemens."
;; `(eval (pair ,fun ,seq)))
@@ -160,9 +160,9 @@ condition is false."
,@body)))
(define-syntax (define-module module-name (:imports ()) :exports . body)
(define-syntax (define-module module-name (:imports ()) (:exports ()) . body)
(let ((module-prefix (concat-strings (symbol->string module-name) "::")))
(eval `(begin ,@(map (lambda (x) `(,import ,x)) imports) ,@body))
(eval `(,begin ,@(map (lambda (x) `(,import ,x)) imports) ,@body))
(pair 'begin
(map (lambda (orig-export-name)
((lambda (export-name)
@@ -235,11 +235,11 @@ condition is false."
)
(define (null? x)
:doc "Checks if the argument is =nil=."
"Checks if the argument is =nil=."
(= x ()))
(define (type=? obj typ)
:doc "Checks if the argument =obj= is of type =typ="
"Checks if the argument =obj= is of type =typ="
(= (type obj) typ))
(define (types=? . objs)
@@ -264,43 +264,43 @@ condition is false."
(inner objs))
(define (number? x)
:doc "Checks if the argument is a number."
"Checks if the argument is a number."
(type=? x :number))
(define (symbol? x)
:doc "Checks if the argument is a symbol."
"Checks if the argument is a symbol."
(type=? x :symbol))
(define (keyword? x)
:doc "Checks if the argument is a keyword."
"Checks if the argument is a keyword."
(type=? x :keyword))
(define (pair? x)
:doc "Checks if the argument is a pair."
"Checks if the argument is a pair."
(type=? x :pair))
(define (string? x)
:doc "Checks if the argument is a string."
"Checks if the argument is a string."
(type=? x :string))
(define (lambda? x)
:doc "Checks if the argument is a function."
"Checks if the argument is a function."
(type=? x :lambda))
(define (macro? x)
:doc "Checks if the argument is a macro."
"Checks if the argument is a macro."
(type=? x :macro))
(define (special-lambda? x)
:doc "Checks if the argument is a special-lambda."
"Checks if the argument is a special-lambda."
(type=? x :dynamic-macro))
(define (built-in-function? x)
:doc "Checks if the argument is a built-in function."
"Checks if the argument is a built-in function."
(type=? x :cfunction))
(define (continuation? x)
:doc "Checks if the argument is a continuation."
"Checks if the argument is a continuation."
(type=? x :continuation))
(define (procedure? x)
@@ -311,7 +311,7 @@ condition is false."
(continuation? x)))
(define (end seq)
:doc "Returns the last pair in the sqeuence.
"Returns the last pair in the sqeuence.
{{{example_start}}}
(define a (list 1 2 3 4))
@@ -323,7 +323,7 @@ condition is false."
(end (rest seq))))
(define (last seq)
:doc "Returns the (first) of the last (pair) of the given sequence.
"Returns the (first) of the last (pair) of the given sequence.
{{{example_start}}}
(define a (list 1 2 3 4))
@@ -333,7 +333,7 @@ condition is false."
(first (end seq)))
(define (extend seq elem)
:doc "Extends a list with the given element, by putting it in
"Extends a list with the given element, by putting it in
the (rest) of the last element of the sequence."
(if (pair? seq)
(begin
@@ -343,7 +343,7 @@ the (rest) of the last element of the sequence."
elem))
(define (extend2 seq elem)
:doc "Extends a list with the given element, by putting it in
"Extends a list with the given element, by putting it in
the (rest) of the last element of the sequence."
(print "addr of (end seq)" (addr-of (end seq)))
(if (pair? seq)
@@ -354,12 +354,12 @@ the (rest) of the last element of the sequence."
elem)
(define (append seq elem)
:doc "Appends an element to a sequence, by extendeing the list
"Appends an element to a sequence, by extendeing the list
with (pair elem nil)."
(extend seq (pair elem ())))
(define (length seq)
:doc "Returns the length of the given sequence."
"Returns the length of the given sequence."
(if (null? seq)
0
(+ 1 (length (rest seq)))))
@@ -384,21 +384,21 @@ with (pair elem nil)."
(else (pair (first seq) (list-without-index (rest seq) (- index 1))))))
(define (increment val)
:doc "Adds one to the argument."
"Adds one to the argument."
(+ val 1))
(define (decrement val)
:doc "Subtracts one from the argument."
"Subtracts one from the argument."
(- val 1))
(define (range (:from 0) :to)
:doc "Returns a sequence of numbers starting with the number defined
"Returns a sequence of numbers starting with the number defined
by the key =from= and ends with the number defined in =to=."
(when (< from to)
(pair from (range :from (+ 1 from) :to to))))
(define (range-while (:from 0) :to)
:doc "Returns a sequence of numbers starting with the number defined
"Returns a sequence of numbers starting with the number defined
by the key 'from' and ends with the number defined in 'to'."
(define result (list (copy from)))
(define head result)
@@ -420,7 +420,7 @@ elemens as argument to that function."
(map fun (rest seq)))))
(define (reduce fun seq)
:doc "Takes a function and a sequence as arguments and applies the
"Takes a function and a sequence as arguments and applies the
function to the argument sequence. This only works correctly if the
given function accepts a variable amount of parameters. If your
funciton is limited to two arguments, use [[=reduce-binary=]]
@@ -428,7 +428,7 @@ instead."
(apply fun seq))
(define (reduce-binary fun seq)
:doc "Takes a function and a sequence as arguments and applies the
"Takes a function and a sequence as arguments and applies the
function to the argument sequence. reduce-binary applies the arguments
*pair-wise* which means it works with binary functions as compared to
[[=reduce=]]."
@@ -438,7 +438,7 @@ function to the argument sequence. reduce-binary applies the arguments
(reduce-binary fun (rest seq)))))
(define (filter fun seq)
:doc "Takes a function and a sequence as arguments and applies the
"Takes a function and a sequence as arguments and applies the
function to every value in the sequence. If the result of that
funciton application returns a truthy value, the original value is
added to a list, which in the end is returned."