summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno Cichon <ebrasca.ebrasca@openmailbox.org>2017-02-19 22:38:38 +0100
committerBruno Cichon <ebrasca.ebrasca@openmailbox.org>2017-02-19 22:38:38 +0100
commitb94d84cf431e3ca480d01ff277bf40463da09224 (patch)
treeac1cf0baea0d16fdbf19133174370209f55350a0
parente28171df2caa910eb194750f70bdfe9272f85f6d (diff)
Add some documentation.
-rw-r--r--README.org9
-rw-r--r--README.txt11
-rw-r--r--examples/l-system-example.lisp14
-rw-r--r--src/l-system.lisp9
4 files changed, 30 insertions, 13 deletions
diff --git a/README.org b/README.org
new file mode 100644
index 0000000..0c8ffa7
--- /dev/null
+++ b/README.org
@@ -0,0 +1,9 @@
+* L-system
+** L-system is a rewriting system and a type of formal grammar.
+** The purpose of l-system is representation of realistic models of natural patterns.
+** For an example, see 'examples/l-system-example.lisp'.
+** At the moment you can use it like:
+ Lindenmayer's original L-system
+ Parametric grammars
+ Context sensitive grammars
+** It is based on [[https://en.wikipedia.org/wiki/L-system#Variations][Wikipedia link]].
diff --git a/README.txt b/README.txt
deleted file mode 100644
index 9dcec19..0000000
--- a/README.txt
+++ /dev/null
@@ -1,11 +0,0 @@
-#l-system
-
-This is based on Lindenmayer system, with lists instead of strings.
-The main goal of this proyect is flexibility.
-
-At the moment, this includes the following functionality:
-
-*Parametric grammars.
-*Context sensitive grammars.
-
-For an example, see 'examples/l-system-example.lisp'.
diff --git a/examples/l-system-example.lisp b/examples/l-system-example.lisp
index 4d8a53a..37d5cc3 100644
--- a/examples/l-system-example.lisp
+++ b/examples/l-system-example.lisp
@@ -1,5 +1,15 @@
(in-package #:l-system-examples)
+;;Lindenmayer's original L-system
+;;Example 1: Algae
+(-> a ()
+ (a) (b))
+
+(-> b ()
+ (a))
+
+(l-system #'parametric-grammar '((a)) 3)
+
;;;Parametric grammars
(-> f ()
(f 1)
@@ -9,10 +19,10 @@
(-> j (x)
(j (* 3 x)))
-(l-system #'parametric-grammar '((f 1.0)) 2)
+(l-system #'parametric-grammar '((f 1.0)) 3)
;;;Context sensitive grammars
(-> (f j f) (x)
(j (* 2 x)))
-(l-system #'context-sensitive-grammar '((f 1.0)) 2)
+(l-system #'context-sensitive-grammar '((f 1.0)) 3)
diff --git a/src/l-system.lisp b/src/l-system.lisp
index c3f47d0..1ea07fe 100644
--- a/src/l-system.lisp
+++ b/src/l-system.lisp
@@ -7,6 +7,8 @@
(defparameter *l-system-clauses* (make-hash-table :test 'equal))
(defun l-system (fn axiom depth)
+ "Expand axiom into some larger list of symbols.
+It can expand to parametric grammar or to context sensitive grammar."
(iter (repeat depth)
(with result = axiom)
(setf result
@@ -14,6 +16,7 @@
(finally (return result))))
(defun parametric-grammar (elements)
+ "Handle parametric grammar."
(iter (for (symbol . parameters) in elements)
(for func = (gethash symbol *l-system-clauses*))
(appending (if (functionp func)
@@ -21,6 +24,7 @@
(list `(,symbol ,@parameters))))))
(defun context-sensitive-grammar (elements)
+ "Handle context sensitive grammar and parametric grammar."
(iter (for elt on elements)
(with symbol0 = nil)
(for (symbol1 . parameters1) = (first elt))
@@ -33,21 +37,26 @@
(setf symbol0 (first (first elt)))))
(defmacro setf-l-system-rule (symbol lambda)
+ "Set rules to grammar."
`(setf (gethash ,symbol *l-system-clauses*)
,lambda))
(defun make-l-system-expr (item)
+ "(Symbol . paremetes)"
`(list ',(first item) ,@(rest item)))
(defun make-l-system-list (rest)
+ "Make rule conversion part."
(iter (for item in rest)
(collecting (make-l-system-expr item))))
(defmacro make-l-system-rule (vars &body body)
+ "Define rule for grammar."
`#'(lambda ,(append vars '(&rest rest))
(declare (ignorable rest))
(list ,@(make-l-system-list body))))
(defmacro -> (symbol vars &body body)
+ "Define and set rules to grammar."
`(setf-l-system-rule ',symbol
(make-l-system-rule ,vars ,@body)))