+
1
|
list
|
skin
|
login
|
editor
α-wwwiki
::
chainlisp
user:none
(4977 bytes)
_h1 chainlisp _p My ultimate goal is still to create an easy to use Lisp-like wiki-syntax built on a small and robust parser engine. A standard Lisp engines like [[alphalisp|?view=lisp_evaluator]] doesn't give an easy interface for a wiki context (HTML tags and extended ones), strings have to be quoted to avoid conflicts with symbols (maybe no, but I don't know how to do !). In the other side, the alphawiki parser, [[alphawiki|meca/JS.js]], fits well the needs of a wiki context and provides some useful functionalities for creating user functions, but it can't be considered as a good and clean Lisp environment. Some more work is still to be done to mix the both worlds. _p With [[stringlisp|?view=regexp_evaluator]], I began to rewrite the alphawiki parser (built on a single loop and a single RegExp) in a more coherent style. Following [[stringlisp|?view=regexp_evaluator]], {b chainlisp} is the last work in progress. The question is : the special forms (def, if, lambda, ...) must be handled in a pre-processing phase before the loop ; is it possible to avoid it and what is the cost for the unicity of the syntax ? _h3 the inline console _p Before the console is inline for real test, this is a first information about stringlisp's functionalities : {pre {@ style="white-space:pre-wrap;"}°° As stringlisp, chainlisp is built on a single loop using a regular expression evaluating a sequence of nested s-expressions {first rest} where first is a built-in name (operator or function) defined in a single dictionary, and rest is a string or an s-expression {first rest}. With stringlisp it shares the same functionalities. But it differs in the syntax of the lambda, def, if and @ operators, leading to a cleaner and more coherent internal code, a choice which was privileged in chainlisp. These operators are no more special forms, they belong to the dictionary and are evaluated the same way the others are without any specific pre-processing. The coder has the responsability to delay what has to be delayed ! Things are not hidden, the nested s-expressions are evaluated in one single loop from the leaves upto the root and when it is not suitable, when a delayed evaluation is needed, curly parenthesis are replaced by round or square parenthesis. So : 1) in a lambda's and a def's body curly parenthesis must be replaced by round parenthesis, 2) in an if's body curly parenthesis must be replaced by square parenthesis, 3) in an @'s CSS rules containing round parenthesis must be replaced by square parenthesis. 1) dictionary : 11) HTML : div, span, ul, ol, li, dl, dt, dd, table, tr, td, h1, h2, h3, h4, h5, h6, p, br, hr, b, i, u, a, img, sup, sub, del, pre, center, blockquote, code, note, note_start, note_end, show, lightbox, drag, .. , input, serie, map, reduce, lib 12) MATH : >, <, =, not, or, and, +, *, -, /, %, abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, min, pow, random, round, sin, sqrt, tan, PI, E, 13) SPECIAL FORMS : define, lambda, if, @ 2) extending the dictionary The dictionary is extended using the def and lambda operators, for instance : 21) defining a constant: > {def myPI 3.1416} -> myPI > {myPI} -> 3.1416 22) giving a name to an s-expression : > {def 2PI (* 2 (PI)} -> 2PI > {2PI} -> 6.283185307179586 23)defining & calling a function : > {lambda (:a :b) (+ :a :b)} -> lambda_1234 > {{lambda (:a :b) (+ :a :b)} 3 4} -> {lambda_1234 3 4} -> 5 24) giving a name to a function, then calling it : > {def hypo (lambda (:a :b) (sqrt (+ (* :a :a) (* :b :b))) ) } -> hypo > {hypo 3 4} -> 5 3) notes - lambdas' parameters must be prefixed by an hyphen : x -> :x - the input operator can be used for inline javascript coding - hiding any text : ooo comment ooo. - preventing evaluation of s-expressions : oo{* 1 2 3}oo > {* 1 2 3}. °°} _p With {b chainlisp}, this code : {pre °° {def equation (lambda (:a :b :c) (if [>= [delta :a :b :c] 0] then delta = [delta :a :b :c] x1 = [/ [+ [- :b] [sqrt [delta :a :b :c]]] [* 2 :a]] x2 = [/ [- [- :b] [sqrt [delta :a :b :c]]] [* 2 :a]] else delta = [delta :a :b :c] x1 = < [/ [- :b] [* 2 :a]] , [/ [sqrt [- [delta :a :b :c]]] [* 2 :a]] > x2 = < [/ [- :b] [* 2 :a]] ,-[/ [sqrt [- [delta :a :b :c]]] [* 2 :a]] > ) ) } {def delta (lambda (:a :b :c) (- (* :b :b) (* 4 :a :c)))} °°{sup o}{sup o}°°{equation 1 -1 -1}°°{sup o}{sup o}°° -> {equation 1 -1 -1} °°{sup o}{sup o}°°{equation 1 -1 1}°°{sup o}{sup o}°° -> {equation 1 -1 1} °°{sup o}{sup o}°°{equation 1 -2 1}°°{sup o}{sup o}°° -> {equation 1 -2 1} °°} _p displays : {pre equation delta {equation 1 -1 -1} -> delta = 5 x1 = 1.618033988749895 x2 = -0.6180339887498949 {equation 1 -1 1} -> delta = -3 x1 = < 0.5 , 0.8660254037844386 > x2 = < 0.5 ,-0.8660254037844386 > {equation 1 -2 1} -> delta = 0 x1 = 1 x2 = 1 }