Getting the manual going
This commit is contained in:
+15
-34
@@ -5,26 +5,12 @@
|
||||
(define-syntax (unless condition :rest 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 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 'begin (rest body))))
|
||||
;; (list 'define name (list 'lambda arguments (pair 'begin body)))))
|
||||
|
||||
|
||||
;; (define-syntax defspecial (name arguments :rest body)
|
||||
;; ;; (type-assert arguments :pair)
|
||||
;; ;; `(define ,name (lambda ,arguments ,body))
|
||||
|
||||
;; ;; 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 'begin (rest body))))
|
||||
;; (list 'define name (list 'special-lambda arguments (pair 'begin body)))))
|
||||
(define-syntax (n-times times action)
|
||||
"Executes action times times."
|
||||
(define (repeat times elem)
|
||||
(unless (> 1 times)
|
||||
(pair elem (repeat (- times 1) elem))))
|
||||
(pair 'begin (repeat times action)))
|
||||
|
||||
;; (define (fib n))
|
||||
;; (define-syntax define (name :rest value)
|
||||
@@ -41,7 +27,6 @@
|
||||
;; (print "\nbb\n")
|
||||
;; (pair 'define (pair name value)))))
|
||||
|
||||
;; TODO(Felix): else symbol
|
||||
(define-syntax (cond :rest clauses)
|
||||
(define (rec clauses)
|
||||
(if (= nil clauses)
|
||||
@@ -122,13 +107,6 @@ the (rest) of the last element of the sequence."
|
||||
with (pair elem nil)."
|
||||
(extend seq (pair elem nil)))
|
||||
|
||||
(define-syntax (extend! seq elem)
|
||||
"test"
|
||||
`(mutate ,seq (extend ,seq ,elem)))
|
||||
|
||||
(define-syntax (append! seq elem)
|
||||
`(mutate ,seq (append ,seq ,elem)))
|
||||
|
||||
(define (length seq)
|
||||
"Returns the length of the given sequence."
|
||||
(if (nil? seq)
|
||||
@@ -143,11 +121,6 @@ with (pair elem nil)."
|
||||
"Subtracts one from the argument."
|
||||
(- val 1))
|
||||
|
||||
;; (defmacro n-times (@times @action)
|
||||
;; "Executes @action @times times."
|
||||
;; (unless (<= (eval @times) 0)
|
||||
;; (eval @action)
|
||||
;; (apply n-times (list (list - @times 1) @action))))
|
||||
|
||||
;; (defmacro for (@symbol @from @to :rest @for-body)
|
||||
;; "Designed to resemble a C style for loop. It takes a symbol as
|
||||
@@ -226,6 +199,14 @@ added to a list, which in the end is returned."
|
||||
nil
|
||||
(pair (list (first l1) (first l2)) (zip (rest l1) (rest l2)))))
|
||||
|
||||
(define (enumerate seq)
|
||||
(define (enumerate-inner seq next-num)
|
||||
(when seq
|
||||
(pair (list (first seq) next-num)
|
||||
(enumerate-inner (rest seq) (+ 1 next-num)))))
|
||||
(enumerate-inner seq 0))
|
||||
|
||||
|
||||
(define (printf :keys sep :defaults-to " " end :defaults-to "\n" :rest args)
|
||||
"A wrapper for the built-in (print) that accepts a variable number
|
||||
of arguments and also provides keywords for specifying the printed
|
||||
@@ -244,4 +225,4 @@ las argument."
|
||||
(eval (pair printf-quoted (extend (list :@sep (eval sep) :@end (eval end)) args))))
|
||||
|
||||
(define-syntax (pe expr)
|
||||
`(printf ',expr "evaluates to" ,(eval expr)))
|
||||
`(printf ',expr "evaluates to" ,expr))
|
||||
|
||||
Reference in New Issue
Block a user