summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--examples/l-system-exemple.lisp8
-rw-r--r--src/l-system.lisp26
2 files changed, 19 insertions, 15 deletions
diff --git a/examples/l-system-exemple.lisp b/examples/l-system-exemple.lisp
index cbe4c99..bb16ecc 100644
--- a/examples/l-system-exemple.lisp
+++ b/examples/l-system-exemple.lisp
@@ -1,11 +1,11 @@
(in-package #:l-system-examples)
(-> f (x)
- '((f 1)
- (j 1)
- (f 1)))
+ (f 1)
+ (j 1)
+ (f 1))
(-> j (x)
- `((j ,(* 3 x))))
+ (j (* 3 x)))
(l-system '((f 1.0)) 2)
diff --git a/src/l-system.lisp b/src/l-system.lisp
index 80d6f81..d1f782f 100644
--- a/src/l-system.lisp
+++ b/src/l-system.lisp
@@ -6,11 +6,6 @@
(defparameter *l-system-clauses* (make-hash-table :test 'eq))
-(defun iterconcat (fn list)
- "Applies fn on each element of list, and concatenate a copy of the resulting lists."
- (iter (for item in list)
- (appending (funcall fn item))))
-
(defun l-system (axiom depth)
(iter (repeat depth)
(with result = axiom)
@@ -28,11 +23,20 @@
result))
(list clause))))))
-(defmacro -> (symbol vars &body body)
- `(def-l-system-clause ',symbol
- (lambda ,vars
- ,@body)))
-
-(defun def-l-system-clause (symbol lambda)
+(defun setf-l-system-rule (symbol lambda)
(setf (gethash symbol *l-system-clauses*)
lambda))
+
+(defun make-l-system-expr (item)
+ `(list ',(first item) ,(second item)))
+
+(defun make-l-system-list (rest)
+ (iter (for item in rest)
+ (collecting (make-l-system-expr item))))
+
+(defmacro make-l-system-rule (vars &body body)
+ `#'(lambda ,vars (list ,@(make-l-system-list body))))
+
+(defmacro -> (symbol vars &body body)
+ `(setf-l-system-rule ',symbol
+ (make-l-system-rule ,vars ,@body)))