+
2
|
list
|
skin
|
login
|
editor
α-wwwiki
::
amlisp
user:none
(4049 bytes)
_h1 amlisp _p This is a simple console to test {b amlisp}, a minimal and understandable lisp parser straight from Peter Norvig's Python [[code|http://norvig.com/lispy.html]], through a Javascript translation made by [[sreedathns|http://sreedathns.blogspot.in/]], [[sainamdar|https://bitbucket.org/sainamdar/]] and others good people. _ul 1) The amlisp dictionary contains a few basic operators : lib, +, *, -, /, ++, --, >, < , =, not, or, and, abs, acos, asin, atan, atan2, ceil, cos, exp, floor, log, max, min, random, round, sin, sqrt, tan, pow, mod, PI, E, a, img, show, lightbox, div, span, pre, table, tr, td, ul, ol, li, b, i, u, center, p, h1, h2, h3, h4, h5, h6, @, and more to come ... _ul 2) The amlisp evaluator accepts only a few special forms : - "define" - "lambda" - "if" _ul 3) The 360 lines of Javascript code are visible here : [[amlisp.js|plugins/amlisp.js]]. _p It's nothing but a workshop, a work in progress, there are no nested defines or lammbas, no set!, no car, cdr, cons ... _h3 well, now do something ! _ul 1) {b First of all, click on the "init amlisp" button}, _ul 2) Any text entered in the input editor frame will be displayed in real-time in the view frame, and any valid S-expression will be evaluated, {center YES, please, click on me : {input {@ type="submit" value="init amlisp" onclick="°° var js = document.createElement('script'); js.src = 'plugins/amlisp.js'; document.head.appendChild( js ); this.value = 'OK, amlisp is inited !'; this.disabled='disabled'; °°"}}} {textarea {@ id="input" onkeyup="display()" style="width:100%; height:300px; background:#eee; font:normal 1em courier; color:red; border:0; box-shadow:0 0 8px black"}} {div {@ id="infos" style="width:200px; text-align:center; margin:2px auto; font:normal 1em courier; color:red;"}} {div {@ id="output" style="border:1px solid; height:300px;background:#eee; font:normal 1em courier; color:red; border:0; box-shadow:0 0 8px black"}} _h3 examples _p You may copy/paste any example in the editor frame and edit it. {pre (h2 1> math expressions :) (sqrt (+ (* 3 3) (* 4 4))) (h2 2> define user functions :) (h3 some constant) (define 2PI (lambda () (* 2 3.14))) (2PI) (h3 square) (define square (lambda (x) (* x x))) (square 12) (h3 hypo) (define hypo (lambda (a b) (sqrt (+ (* a a) (* b b))))) (hypo 3 4) (h2 3> play with recursion :) (define fac (lambda (n) (if (< n 1) 1 (* n (fac (- n 1)))) ) ) (fac 6) (h2 4> play with some HTML tags :) (div (@ style="border:1px solid blue; color:red; box-shadow: 0 0 8px black; text-align:center;" ) Some red and (b bold text) in a blue shadowed frame. ) (ol (li item 1 (ul (li item 11 (ul (li item 111) (li item 111) ) ) (li item 12) ) ) (li item 1) (li item 1) ) (h3 links) (a (@ href="http://www.pixar.com/")PIXAR) (h3 a simple picture) (img (@ src="data/amelie_sepia.jpg" height="150" title="Amélie loves ze lambdaway" style="box-shadow: 0 0 8px black; padding:5px 5px 15px 5px;" ) ) (h3 a click-to-show picture) (show (@ data/amelie_sepia.jpg 150 400)Amélie loves ze lambdaway) (h3 a lightbox) (lightbox (@ 150 400 ) [data/amelie_sepia.jpg Amélie loves ze lambdaway] [data/montgomery_clift.jpg Montgomery tambien] ) (h3 some postits) (define fac (lambda (n) (if (= n 1) 1 (* n (fac (- n 1)))))) (define col (lambda (:c) (* 25 :c))) (define foo (lambda (:x) (div (@ style= "font:bold 2em courier new; background:rgb[(col :x),(- 255 (col :x)),0]; transform:rotate[:xdeg]; border:1px solid red; text-align:center;" ) :x! = (fac :x) ) )) (foo 1)(foo 2)(foo 3)(foo 4)(foo 5)(foo 6)(foo 7)(foo 8)(foo 9) (h3 and more to come …) }