Added support for λ

This commit is contained in:
Devine Lu Linvega 2019-07-21 09:52:37 +09:00
parent 3ea7fff85f
commit 938a9d22ec
6 changed files with 25 additions and 24 deletions

View File

@ -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.

View File

@ -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, ' ( ')

View File

@ -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))))
(λ (a) (echo (concat "time:" a))))

View File

@ -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))

View File

@ -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)
)))

View File

@ -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)