From 143a45807efd8c4670ae8a796c98e7f42a4ed105 Mon Sep 17 00:00:00 2001 From: Quentin Leonetti Date: Sat, 20 Jul 2019 17:13:40 +0200 Subject: [PATCH] update examples with no global ( ) --- desktop/sources/scripts/lisp.js | 2 +- examples/animate.lisp | 32 +++++------ examples/arrays.lisp | 36 +++++------- examples/basics.lisp | 14 ++--- examples/benchmark.fs.lisp | 26 ++++----- examples/benchmark.lisp | 4 +- examples/crop.lisp | 8 +-- examples/dejong.lisp | 58 ++++++++++--------- examples/glitch.lisp | 34 +++++------ examples/gradient.lisp | 4 +- examples/guides.lisp | 99 ++++++++++++++++----------------- examples/import.lisp | 4 +- examples/include.lisp | 5 +- examples/lambda.lisp | 2 +- examples/open.lisp | 14 ++--- examples/pixels.lisp | 12 ++-- examples/random.file.lisp | 26 ++++----- examples/random.lisp | 32 +++++------ examples/recursive.lisp | 30 +++++----- examples/resize.lisp | 8 +-- examples/shapes.lisp | 39 +++++++------ examples/spiral.lisp | 4 +- examples/svg.lisp | 16 +++--- examples/theme.lisp | 74 ++++++++++++------------ 24 files changed, 279 insertions(+), 304 deletions(-) diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js index 1f9b40f..2d8f16e 100644 --- a/desktop/sources/scripts/lisp.js +++ b/desktop/sources/scripts/lisp.js @@ -146,7 +146,7 @@ function Lisp (input, lib) { } this.parse = function (input) { - return parenthesize(tokenize(input)) + return parenthesize(tokenize(`(${input})`)) } this.toPixels = async function () { diff --git a/examples/animate.lisp b/examples/animate.lisp index 4adaf64..9621338 100644 --- a/examples/animate.lisp +++ b/examples/animate.lisp @@ -1,17 +1,17 @@ ; animate -( - (clear) - (def t - (sin - (div - (time) 100))) - (def pos - (add 200 30 - (mul 30 t))) - (defn square - (a) - (rect a a a a)) - (stroke - (square pos) 1 "red") - ; set false to stop - (animate true)) \ No newline at end of file + +(clear) +(def t + (sin + (div + (time) 100))) +(def pos + (add 200 30 + (mul 30 t))) +(defn square + (a) + (rect a a a a)) +(stroke + (square pos) 1 "red") +; set false to stop +(animate true) \ No newline at end of file diff --git a/examples/arrays.lisp b/examples/arrays.lisp index e6c7db1..76c2054 100644 --- a/examples/arrays.lisp +++ b/examples/arrays.lisp @@ -1,9 +1,7 @@ (echo (map (lambda (a) (add a 1)) (1 2 3))) -( - (echo (first (1 2 3))) - (echo (rest (1 2 3))) -) +(echo (first (1 2 3))) +(echo (rest (1 2 3))) (echo (filter @@ -11,21 +9,17 @@ (1 2 3 4 5)) ) -( - (clear) - (map (lambda (a) - (stroke (rect (mul a 30) 20 50 50) - 1 "red")) - (range 0 20 5)) -) +(clear) +(map (lambda (a) + (stroke (rect (mul a 30) 20 50 50) +1 "red")) +(range 0 20 5)) -( - (clear) - (map (lambda (a) - (stroke - (rect - (mul a 10) - (add 50 (mul (sin a) 40)) - a - (add 20 (mul (cos a) 50))) 1 "red")) - (range 0 200 5))) \ No newline at end of file +(map (lambda (a) + (stroke + (rect + (mul a 10) + (add 50 (mul (sin a) 40)) + a + (add 20 (mul (cos a) 50))) 1 "red")) + (range 0 200 5)) \ No newline at end of file diff --git a/examples/basics.lisp b/examples/basics.lisp index c1832ea..997be5d 100644 --- a/examples/basics.lisp +++ b/examples/basics.lisp @@ -1,9 +1,9 @@ ; basics -( - ; define a variable - (def a 25) - (echo a) - ; define a function - (defn add-two (a) (add 2 a)) - (echo (add-two 4))) \ No newline at end of file +; define a variable +(def a 25) +(echo a) + +; define a function +(defn add-two (a) (add 2 a)) +(echo (add-two 4)) \ No newline at end of file diff --git a/examples/benchmark.fs.lisp b/examples/benchmark.fs.lisp index cd80cef..7867c03 100644 --- a/examples/benchmark.fs.lisp +++ b/examples/benchmark.fs.lisp @@ -1,14 +1,14 @@ ; filesystem -( - ; print path - (echo - (filepath)) - ; print folder path - (echo - (dirpath)) - ; print file content - (echo - (file)) - ; print folder content - (echo - (dir))) \ No newline at end of file + +; print path +(echo + (filepath)) +; print folder path +(echo + (dirpath)) +; print file content +(echo + (file)) +; print folder content +(echo + (dir)) \ No newline at end of file diff --git a/examples/benchmark.lisp b/examples/benchmark.lisp index 1e0d5da..e0b698e 100644 --- a/examples/benchmark.lisp +++ b/examples/benchmark.lisp @@ -1,6 +1,5 @@ ; benchmark -( ; Basics (test "add" (add 8 4 2) 14) @@ -57,5 +56,4 @@ ; Interop (test "interop" ((of (of (js) "Math") "max") 2 4) 4) - (test "recursive key selector" ((of (js) "Math" "max") 2 4) 4) -) \ No newline at end of file + (test "recursive key selector" ((of (js) "Math" "max") 2 4) 4) \ No newline at end of file diff --git a/examples/crop.lisp b/examples/crop.lisp index 0a8168a..771a7c6 100644 --- a/examples/crop.lisp +++ b/examples/crop.lisp @@ -1,7 +1,5 @@ ; crop -( - (clear) - (open "../static/crystal.jpg") - (crop (rect 100 100 400 400)) -) \ No newline at end of file +(clear) +(open "../static/crystal.jpg") +(crop (rect 100 100 400 400)) \ No newline at end of file diff --git a/examples/dejong.lisp b/examples/dejong.lisp index b446040..654271c 100644 --- a/examples/dejong.lisp +++ b/examples/dejong.lisp @@ -1,35 +1,33 @@ ; dejong attractor -( - (clear) - (defn point (x y color) - (fill (rect x y 1 1) color)) +(clear) +(defn point (x y color) + (fill (rect x y 1 1) color)) - (defn _dejong (x y a b c d) - (rest ((point - (add 300 (mul 100 x)) - (add 400 (mul 100 y)) - "red") - (add (sin (mul a y)) (mul x (cos (mul b x)))) - (add (mul x (sin (mul x c))) (cos (mul d y))) - )) - ) - - (defn dejong (r a b c d) - (reduce - (lambda (acc val) - (first ( - (_dejong (first acc) (last acc) a b c d) - ))) - (range 0 r) - (2 1) - ) - ) - (benchmark - '(dejong 12800 - (random -2 2) - (random -2 2) - (random -2 2) - (random -2 2) +(defn _dejong (x y a b c d) + (rest ((point + (add 300 (mul 100 x)) + (add 400 (mul 100 y)) + "red") + (add (sin (mul a y)) (mul x (cos (mul b x)))) + (add (mul x (sin (mul x c))) (cos (mul d y))) )) ) + +(defn dejong (r a b c d) + (reduce + (lambda (acc val) + (first ( + (_dejong (first acc) (last acc) a b c d) + ))) + (range 0 r) + (2 1) + ) +) +(benchmark + '(dejong 12800 + (random -2 2) + (random -2 2) + (random -2 2) + (random -2 2) +)) diff --git a/examples/glitch.lisp b/examples/glitch.lisp index b5f723e..5491fc8 100644 --- a/examples/glitch.lisp +++ b/examples/glitch.lisp @@ -1,25 +1,19 @@ -; pixels +; Glitch -( - (clear) +(clear) - ; Glitch - - (defn glitch - (rec) - (if (gt rec 1) - ((clone - (rect (random 400) (random 400) 2 2) - (rect (random 400) (random 400) +(defn glitch + (rec) + (if (gt rec 1) + ((clone + (rect (random 400) (random 400) 2 2) + (rect (random 400) (random 400) (random 10) (random 30))) - (glitch (sub rec 1)))) - ) + (glitch (sub rec 1)))) +) - ; Draw photo - - (import - "../static/crystal.jpg" - (rect 0 0 400 400)) +(import + "../static/crystal.jpg" + (rect 0 0 400 400)) - (glitch 500) -) \ No newline at end of file +(glitch 500) \ No newline at end of file diff --git a/examples/gradient.lisp b/examples/gradient.lisp index b11e9aa..3637db9 100644 --- a/examples/gradient.lisp +++ b/examples/gradient.lisp @@ -1,4 +1,3 @@ -( ; gradients (clear) @@ -12,5 +11,4 @@ (svg "M255,60 L255,60 L135,180 L75,60 L195,210 L120,225 L105,225 L165,255 L225,195 L255,135 L285,150") 1 (gradient (50 0 180 0) - ("black" "white" "blue" "green"))) -) \ No newline at end of file + ("black" "white" "blue" "green"))) \ No newline at end of file diff --git a/examples/guides.lisp b/examples/guides.lisp index f956c75..66c9758 100644 --- a/examples/guides.lisp +++ b/examples/guides.lisp @@ -1,57 +1,56 @@ ; guides -( - (clear) - (stroke - (frame) 1 "red") - (stroke - (line - (pos 0 0) - (pos +(clear) +(stroke + (frame) 1 "red") +(stroke + (line + (pos 0 0) + (pos + (of + (frame) "w") + (of + (frame) "h"))) 1 "red") +(stroke + (line + (pos + (of + (frame) "w") 0) + (pos 0 + (of + (frame) "h"))) 1 "red") +(stroke + (line + (pos + (div (of - (frame) "w") + (frame) "w") 2) 0) + (pos + (div (of - (frame) "h"))) 1 "red") - (stroke - (line - (pos + (frame) "w") 2) + (of + (frame) "h"))) 1 "red") +(stroke + (line + (pos 0 + (div (of - (frame) "w") 0) - (pos 0 + (frame) "h") 2)) + (pos + (div (of - (frame) "h"))) 1 "red") - (stroke - (line - (pos - (div - (of - (frame) "w") 2) 0) - (pos - (div - (of - (frame) "w") 2) + (frame) "w") 2) + (of + (frame) "h"))) 1 "#72dec2") +(stroke + (line + (pos + (div (of - (frame) "h"))) 1 "red") - (stroke - (line - (pos 0 - (div - (of - (frame) "h") 2)) - (pos - (div - (of - (frame) "w") 2) + (frame) "w") 2) 0) + (pos + (of + (frame) "w") + (div (of - (frame) "h"))) 1 "#72dec2") - (stroke - (line - (pos - (div - (of - (frame) "w") 2) 0) - (pos - (of - (frame) "w") - (div - (of - (frame) "h") 2))) 1 "#72dec2")) \ No newline at end of file + (frame) "h") 2))) 1 "#72dec2") \ No newline at end of file diff --git a/examples/import.lisp b/examples/import.lisp index 36841c2..4fa5b9a 100644 --- a/examples/import.lisp +++ b/examples/import.lisp @@ -1,5 +1,5 @@ -( +(clear) (def a (import "../static/crystal.jpg" (rect 0 0 400 400))) -(echo a)) \ No newline at end of file +(echo a) \ No newline at end of file diff --git a/examples/include.lisp b/examples/include.lisp index bb1fdb9..fce452b 100644 --- a/examples/include.lisp +++ b/examples/include.lisp @@ -1,4 +1,3 @@ ; include -( - (include "../examples/recursive.lisp") - (echo line-color)) \ No newline at end of file +(include "../examples/recursive.lisp") +(echo line-color) \ No newline at end of file diff --git a/examples/lambda.lisp b/examples/lambda.lisp index 2c1be4c..ed62eb4 100644 --- a/examples/lambda.lisp +++ b/examples/lambda.lisp @@ -1,6 +1,6 @@ ( -(echo (map '(echo 1 2 3) (4 5 6)) +(echo (map '(add 1 2) (4 5 6)) ) diff --git a/examples/open.lisp b/examples/open.lisp index 6166815..399edf4 100644 --- a/examples/open.lisp +++ b/examples/open.lisp @@ -1,9 +1,7 @@ -; scale file -( +; saturate image - (open "../static/crystal.jpg") - (pixels - (frame) - saturation - 12) -) \ No newline at end of file +(open "../static/crystal.jpg") +(pixels + (frame) + saturation + 12) \ No newline at end of file diff --git a/examples/pixels.lisp b/examples/pixels.lisp index d4edbff..761a462 100644 --- a/examples/pixels.lisp +++ b/examples/pixels.lisp @@ -1,7 +1,7 @@ ; pixels -( - (clear) - (import "../../PREVIEW.jpg" - (frame)) - (pixels - (rect 0 0 500 500) saturation 0.5)) \ No newline at end of file + +(clear) +(import "../../PREVIEW.jpg" + (frame)) +(pixels + (rect 0 0 500 500) saturation 0.5) \ No newline at end of file diff --git a/examples/random.file.lisp b/examples/random.file.lisp index b63101e..f95064b 100644 --- a/examples/random.file.lisp +++ b/examples/random.file.lisp @@ -1,14 +1,14 @@ ; filesystem -( - ; get files - (def files - (dir - (dirpath))) - ; pick a random file - (def random-index - (floor - (random - (len files)))) - ; print random file name - (echo - (get files random-index))) \ No newline at end of file + +; get files +(def files + (dir + (dirpath))) +; pick a random file +(def random-index + (floor + (random + (len files)))) +; print random file name +(echo + (get files random-index)) \ No newline at end of file diff --git a/examples/random.lisp b/examples/random.lisp index ff3754c..f6cdf0d 100644 --- a/examples/random.lisp +++ b/examples/random.lisp @@ -1,17 +1,17 @@ ; random -( - (clear) - (defn place - (rec) - (if - (gt rec 0) - ( - (import "../static/crystal.jpg" - (rect - (random 200) - (random 200) - (random 200) - (random 200))) - (place - (sub rec 1))))) - (place 30)) \ No newline at end of file + +(clear) +(defn place + (rec) + (if + (gt rec 0) + ( + (import "../static/crystal.jpg" + (rect + (random 200) + (random 200) + (random 200) + (random 200))) + (place + (sub rec 1))))) +(place 30) \ No newline at end of file diff --git a/examples/recursive.lisp b/examples/recursive.lisp index fb7003f..8580107 100644 --- a/examples/recursive.lisp +++ b/examples/recursive.lisp @@ -1,16 +1,16 @@ ; recursive -( - (clear) - (defn rec - (v) - (if - (gt v 0) - ( - (stroke - (circle - (mul 5 v) - (mul 5 v) - (mul 5 v)) 1 "red") - (rec - (sub v 5))))) - (rec 100)) \ No newline at end of file + +(clear) +(defn rec + (v) + (if + (gt v 0) + ( + (stroke + (circle + (mul 5 v) + (mul 5 v) + (mul 5 v)) 1 "red") + (rec + (sub v 5))))) +(rec 100) \ No newline at end of file diff --git a/examples/resize.lisp b/examples/resize.lisp index 5dbd409..bc206c4 100644 --- a/examples/resize.lisp +++ b/examples/resize.lisp @@ -1,5 +1,5 @@ ; resize -( - (clear) - (open "../../PREVIEW.jpg") - (resize 0.5 0.5)) \ No newline at end of file + +(clear) +(open "../../PREVIEW.jpg") +(resize 0.5 0.5) \ No newline at end of file diff --git a/examples/shapes.lisp b/examples/shapes.lisp index 29f0ea8..d9712c4 100644 --- a/examples/shapes.lisp +++ b/examples/shapes.lisp @@ -1,25 +1,24 @@ ; Shapes -((clear) +(clear) - ; variables - (def center-w (div (of (frame) "w") 2)) - (def center-h (div (of (frame) "h") 2)) - (def rad (div (of (frame) "h") 4)) - - ; draw circle - (stroke - (circle center-w center-h rad) 2 "white") +; variables +(def center-w (div (of (frame) "w") 2)) +(def center-h (div (of (frame) "h") 2)) +(def rad (div (of (frame) "h") 4)) - ; draw rect - (stroke - (rect - (sub center-w rad) (sub center-h rad) center-h center-h) 2 "white") +; draw circle +(stroke + (circle center-w center-h rad) 2 "white") - ; draw line - (stroke - (line - (pos (sub center-w rad) center-h) - (pos (add center-w rad) center-h))) - (stroke (text 10 170 200 "HELL") 2 "pink") -) \ No newline at end of file +; draw rect +(stroke + (rect + (sub center-w rad) (sub center-h rad) center-h center-h) 2 "white") + +; draw line +(stroke + (line + (pos (sub center-w rad) center-h) + (pos (add center-w rad) center-h))) +(stroke (text 10 170 200 "HELL") 2 "pink") \ No newline at end of file diff --git a/examples/spiral.lisp b/examples/spiral.lisp index 6ca0c55..39027a8 100644 --- a/examples/spiral.lisp +++ b/examples/spiral.lisp @@ -1,6 +1,6 @@ ; animated recusive spiral ; by @local_guru -( + (clear) (defn rec (v) @@ -27,4 +27,4 @@ (sub v 0.3))))) ; set false to stop (animate true) - (rec 300)) \ No newline at end of file + (rec 300) \ No newline at end of file diff --git a/examples/svg.lisp b/examples/svg.lisp index 497871b..2966084 100644 --- a/examples/svg.lisp +++ b/examples/svg.lisp @@ -1,8 +1,8 @@ -( - (clear) - ; ronin path - (stroke - (svg "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") 2 "white") - ; outline - (stroke - (svg "M15,15 L15,15 L285,15 L285,285 L15,285 Z") 1 "#555")) \ No newline at end of file + +(clear) +; ronin path +(stroke + (svg "M60,60 L195,60 A45,45 0 0,1 240,105 A45,45 0 0,1 195,150 L60,150 M195,150 A45,45 0 0,1 240,195 L240,240 ") 2 "white") +; outline +(stroke + (svg "M15,15 L15,15 L285,15 L285,285 L15,285 Z") 1 "#555") \ No newline at end of file diff --git a/examples/theme.lisp b/examples/theme.lisp index 9c50830..cba7b21 100644 --- a/examples/theme.lisp +++ b/examples/theme.lisp @@ -1,38 +1,38 @@ ; theme -( - (clear) - (def col - (lambda - (i) - (of - ( - (theme "f_high") - (theme "f_med") - (theme "f_low") - (theme "f_inv") - (theme "b_high") - (theme "b_med") - (theme "b_low") - (theme "b_inv")) - (mod i 8)))) - (def rec - (lambda - (v i) - (if - (gt v 0) - ( - (fill - (circle - (add - (div - (of - (frame) "w") 1.6) - (mul 1.5 v)) - (mul 10 v) - (mul v - (div v 5))) - (col i)) - (rec - (sub v 3) - (add i 1)))))) - (rec 40 0)) \ No newline at end of file + +(clear) +(def col + (lambda + (i) + (of + ( + (theme "f_high") + (theme "f_med") + (theme "f_low") + (theme "f_inv") + (theme "b_high") + (theme "b_med") + (theme "b_low") + (theme "b_inv")) + (mod i 8)))) +(def rec + (lambda + (v i) + (if + (gt v 0) + ( + (fill + (circle + (add + (div + (of + (frame) "w") 1.6) + (mul 1.5 v)) + (mul 10 v) + (mul v + (div v 5))) + (col i)) + (rec + (sub v 3) + (add i 1)))))) +(rec 40 0) \ No newline at end of file