renamed prog to begin and added basics for the manual
This commit is contained in:
+17
-17
@@ -1,20 +1,20 @@
|
||||
(define-syntax (when condition :rest body)
|
||||
"Doc String for 'when'"
|
||||
`(if ,condition ,(pair prog body) nil))
|
||||
`(if ,condition ,(pair begin body) nil))
|
||||
|
||||
(define-syntax (unless condition :rest body)
|
||||
`(if ,condition nil ,(pair prog body)))
|
||||
`(if ,condition nil ,(pair begin body)))
|
||||
|
||||
;; (define-syntax defun (name arguments :rest body)
|
||||
;; ;; (type-assert arguments :pair)
|
||||
;; ;; `(define ,name (lambda ,arguments ,body))
|
||||
;; ;; TODO(Felix: I think we do not need to wrap the body of the lamba
|
||||
;; ;; in a prog
|
||||
;; ;; in a begin
|
||||
|
||||
;; ;; see if we have a docstring
|
||||
;; (if (and (= (type (first body)) :string) (not (= (type (rest body)) :nil)))
|
||||
;; (list 'define name (list 'lambda arguments (first body) (pair 'prog (rest body))))
|
||||
;; (list 'define name (list 'lambda arguments (pair 'prog body)))))
|
||||
;; (list 'define name (list 'lambda arguments (first body) (pair 'begin (rest body))))
|
||||
;; (list 'define name (list 'lambda arguments (pair 'begin body)))))
|
||||
|
||||
|
||||
;; (define-syntax defspecial (name arguments :rest body)
|
||||
@@ -23,20 +23,20 @@
|
||||
|
||||
;; ;; see if we have a docstring
|
||||
;; (if (and (= (type (first body)) :string) (not (= (type (rest body)) :nil)))
|
||||
;; (list 'define name (list 'special-lambda arguments (first body) (pair 'prog (rest body))))
|
||||
;; (list 'define name (list 'special-lambda arguments (pair 'prog body)))))
|
||||
;; (list 'define name (list 'special-lambda arguments (first body) (pair 'begin (rest body))))
|
||||
;; (list 'define name (list 'special-lambda arguments (pair 'begin body)))))
|
||||
|
||||
;; (define (fib n))
|
||||
;; (define-syntax define (name :rest value)
|
||||
;; (print name)
|
||||
;; (print (type name))
|
||||
;; (if (= (type name) :pair)
|
||||
;; (prog
|
||||
;; (begin
|
||||
;; ;; (print `(define ,(first name) ,`(pair lambda (pair (rest name) value))))
|
||||
;; ;; (print rest)
|
||||
;; (print "\naa\n")
|
||||
;; (list 'define (first name) (pair 'lambda (pair (rest name) value))))
|
||||
;; (prog
|
||||
;; (begin
|
||||
;; ;; (print (pair 'define (pair name value)))
|
||||
;; (print "\nbb\n")
|
||||
;; (pair 'define (pair name value)))))
|
||||
@@ -47,12 +47,12 @@
|
||||
(if (= nil clauses)
|
||||
nil
|
||||
(if (= (first (first clauses)) 'else)
|
||||
(prog
|
||||
(begin
|
||||
(if (not (= () (rest clauses)))
|
||||
(error "There are additional clauses after the else clause!")
|
||||
(pair 'prog (rest (first clauses)))))
|
||||
(pair 'begin (rest (first clauses)))))
|
||||
(list 'if (first (first clauses))
|
||||
(pair 'prog (rest (first clauses)))
|
||||
(pair 'begin (rest (first clauses)))
|
||||
(rec (rest clauses))))))
|
||||
(rec clauses))
|
||||
|
||||
@@ -111,7 +111,7 @@ ithe sequence as arguemens."
|
||||
"Extends a list with the given element, by putting it in
|
||||
the (rest) of the last element of the sequence."
|
||||
(if (pair? seq)
|
||||
(prog
|
||||
(begin
|
||||
(define e (end seq))
|
||||
(mutate e (pair (first e) elem))
|
||||
seq)
|
||||
@@ -161,7 +161,7 @@ with (pair elem nil)."
|
||||
;; (macro-define @op nil)))
|
||||
;; (when @op
|
||||
;; (macro-define (eval @symbol) (eval @from))
|
||||
;; (eval (pair prog @for-body))
|
||||
;; (eval (pair begin @for-body))
|
||||
;; (eval (extend (list for @symbol (@op @from) @to) @for-body))))
|
||||
|
||||
(define (range :keys from :defaults-to 0 to)
|
||||
@@ -177,7 +177,7 @@ by the key 'from' and ends with the number defined in 'to'."
|
||||
(define head result)
|
||||
(mutate from (increment from))
|
||||
(while (< from to)
|
||||
(prog
|
||||
(begin
|
||||
(mutate head (pair (first head) (pair (copy from) nil)))
|
||||
(define head (rest head))
|
||||
(mutate from (increment from))))
|
||||
@@ -233,8 +233,8 @@ separators between the arguments and what should be printed after the
|
||||
las argument."
|
||||
(define printf-quoted (special-lambda (:keys @sep @end :rest @args)
|
||||
(if (nil? @args)
|
||||
(prog (print (eval @end)) nil)
|
||||
(prog
|
||||
(begin (print (eval @end)) nil)
|
||||
(begin
|
||||
(print (first @args))
|
||||
(unless (nil? (rest @args))
|
||||
(print (eval @sep)))
|
||||
|
||||
@@ -24,7 +24,7 @@ ithe sequence as arguemens." (eval (pair fun seq)))
|
||||
(define (last seq) "Returns the (first) of the last (pair) of the given sequence." (first (end seq)))
|
||||
|
||||
(define (extend seq elem) "Extends a list with the given element, by putting it in
|
||||
the (rest) of the last element of the sequence." (if (pair? seq) (prog (define e (end seq)) (mutate e (pair (first e) elem)) seq) elem))
|
||||
the (rest) of the last element of the sequence." (if (pair? seq) (begin (define e (end seq)) (mutate e (pair (first e) elem)) seq) elem))
|
||||
|
||||
(define (append seq elem) "Appends an element to a sequence, by extendeing the list
|
||||
with (pair elem nil)." (extend seq (pair elem nil)))
|
||||
@@ -39,7 +39,7 @@ with (pair elem nil)." (extend seq (pair elem nil)))
|
||||
by the key 'from' and ends with the number defined in 'to'." (if (< from to) ([C-function] (pair from (range :from (+ 1.000000 from) :to to))) nil))
|
||||
|
||||
(define (range-while :keys from :defaults-to 0.000000 to) "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) (mutate from (increment from)) (while (< from to) (prog (mutate head (pair (first head) (pair (copy from) nil))) (define head (rest head)) (mutate from (increment from)))) result)
|
||||
by the key 'from' and ends with the number defined in 'to'." (define result (list (copy from))) (define head result) (mutate from (increment from)) (while (< from to) (begin (mutate head (pair (first head) (pair (copy from) nil))) (define head (rest head)) (mutate from (increment from)))) result)
|
||||
|
||||
(define (map fun seq) "Takes a function and a sequence as arguments and returns a new
|
||||
sequence which contains the results of using the first sequences
|
||||
@@ -67,5 +67,5 @@ added to a list, which in the end is returned." (if seq ([C-function] (if (fun (
|
||||
" :rest args) "A wrapper for the built-in (print) that accepts a variable number
|
||||
of arguments and also provides keywords for specifying the printed
|
||||
separators between the arguments and what should be printed after the
|
||||
las argument." (define printf-quoted (special-lambda (:keys @sep @end :rest @args) (if (nil? @args) (prog (print (eval @end)) nil) (prog (print (first @args)) (if (nil? (rest @args)) nil ([C-function] (print (eval @sep)))) (eval (pair printf-quoted (extend (list :@sep (eval @sep) :@end (eval @end)) (rest @args)))))))) (eval (pair printf-quoted (extend (list :@sep (eval sep) :@end (eval end)) args))))
|
||||
las argument." (define printf-quoted (special-lambda (:keys @sep @end :rest @args) (if (nil? @args) (begin (print (eval @end)) nil) (begin (print (first @args)) (if (nil? (rest @args)) nil ([C-function] (print (eval @sep)))) (eval (pair printf-quoted (extend (list :@sep (eval @sep) :@end (eval @end)) (rest @args)))))))) (eval (pair printf-quoted (extend (list :@sep (eval sep) :@end (eval end)) args))))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user