diff --git a/README.md b/README.md index d49c62f..b1251db 100644 --- a/README.md +++ b/README.md @@ -25,6 +25,8 @@ npm start ## Library +Additional functions can be found in the [includes](https://github.com/hundredrabbits/Ronin/tree/master/desktop/sources/lisp), you can also look at the [examples](https://github.com/hundredrabbits/Ronin/tree/master/examples) to see them in action. + - `(import path rect)` Imports a graphic file with format. - `(export path ~format ~quality)` Exports a graphic file with format. - `(open path)` Imports a graphic file and resizes the frame. @@ -38,6 +40,17 @@ npm start - `(stroke ~shape)` Strokes a shape. - `(fill ~rect)` Fills a shape. - `(clear ~rect)` Clears a rect. +- `(frame)` Returns a rect of the frame. +- `(center)` Returns a position of the center of the frame. +- `(resize w h ~fit)` Resizes the canvas to target w and h, returns the rect. +- `(rescale w h)` Rescales the canvas to target ratio of w and h, returns the rect. +- `(crop rect)` Crop canvas to rect. +- `(clone a b)` +- `(theme variable ~el)` +- `(gradient [x1 y1 x2 y2] ~colors 'black'])` +- `(pixels rect fn q)` +- `(saturation pixel ~q)` +- `(contrast pixel ~q)` - `(concat ...items)` Concat multiple strings. - `(add ...args)` Adds values. - `(sub ...args)` Subtracts values. @@ -71,17 +84,8 @@ npm start - `(get item key)` Gets an object's parameter with name. - `(set item key val)` Sets an object's parameter with name as value. - `(of h ...keys)` Gets object parameters with names. -- `(frame)` Returns a rect of the frame. -- `(center)` Returns a position of the center of the frame. -- `(resize w h ~fit)` Resizes the canvas to target w and h, returns the rect. -- `(rescale w h)` Rescales the canvas to target ratio of w and h, returns the rect. -- `(crop rect)` Crop canvas to rect. -- `(clone a b)` -- `(theme variable ~el)` -- `(gradient [x1 y1 x2 y2] ~colors 'black'])` -- `(pixels rect fn q)` -- `(saturation pixel ~q)` -- `(contrast pixel ~q)` +- `(keys item)` Returns a list of the object's keys +- `(values item)` Returns a list of the object's values - `(dir ~path)` Returns the content of a directory. - `(file ~path)` Returns the content of a file. - `(dirpath ~path)` Returns the path of a directory. diff --git a/desktop/sources/scripts/lisp.js b/desktop/sources/scripts/lisp.js index 82fe8de..e13eb79 100644 --- a/desktop/sources/scripts/lisp.js +++ b/desktop/sources/scripts/lisp.js @@ -153,7 +153,7 @@ function Lisp (lib = {}, includes = []) { } const tokenize = function (input) { - const i = input.replace(/^\;.*\n?/gm, '').split('"') + const i = input.replace(/^\;.*\n?/gm, '').replace('λ','lambda ').split('"') return i.map(function (x, i) { return i % 2 === 0 ? x.replace(/\(/g, ' ( ') diff --git a/examples/basics.lisp b/examples/basics.lisp index 3c6f391..cbffb3e 100644 --- a/examples/basics.lisp +++ b/examples/basics.lisp @@ -8,9 +8,6 @@ (defn add-two (a) (add 2 a)) (echo (add-two 4)) -; run +; use a lambda (times 5 - (lambda - (a) - (echo - (concat "time:" a)))) \ No newline at end of file + (λ (a) (echo (concat "time:" a)))) \ No newline at end of file diff --git a/examples/benchmark.lisp b/examples/benchmark.lisp index e0b698e..03e1e51 100644 --- a/examples/benchmark.lisp +++ b/examples/benchmark.lisp @@ -35,14 +35,14 @@ (test "range simple" (range 0 4) (0 1 2 3 4)) (test "range with step" (range 0 4 2) (0 2 4)) (test "range with negative step" (range 0 -4 -1) (0 -1 -2 -3 -4)) - (test "map" (map (lambda (a) (add 1 a)) (1 2 3)) (2 3 4)) - (test "filter" (filter (lambda (a) (eq 0 (mod a 2))) (2 3 4 5 6)) (2 4 6)) - (test "reduce" (reduce (lambda (acc val) (add acc val)) (1 2 3) 4) 10) + (test "map" (map (λ (a) (add 1 a)) (1 2 3)) (2 3 4)) + (test "filter" (filter (λ (a) (eq 0 (mod a 2))) (2 3 4 5 6)) (2 4 6)) + (test "reduce" (reduce (λ (acc val) (add acc val)) (1 2 3) 4) 10) ; Scope (def aaa 123) - (def addOne (lambda (a) (add a 1))) + (def addOne (λ (a) (add a 1))) (test "def - value" aaa 123) (test "def - func" (addOne 4) 5) (defn addTwo (a) (add 2 a)) diff --git a/examples/dejong.lisp b/examples/dejong.lisp index 654271c..d373008 100644 --- a/examples/dejong.lisp +++ b/examples/dejong.lisp @@ -16,7 +16,7 @@ (defn dejong (r a b c d) (reduce - (lambda (acc val) + (λ (acc val) (first ( (_dejong (first acc) (last acc) a b c d) ))) diff --git a/examples/theme.lisp b/examples/theme.lisp index cba7b21..7a5db32 100644 --- a/examples/theme.lisp +++ b/examples/theme.lisp @@ -2,7 +2,7 @@ (clear) (def col - (lambda + (λ (i) (of ( @@ -16,7 +16,7 @@ (theme "b_inv")) (mod i 8)))) (def rec - (lambda + (λ (v i) (if (gt v 0)