Added folder batch example
This commit is contained in:
parent
26f77727f3
commit
af4d294d2c
13
README.md
13
README.md
@ -77,6 +77,7 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
|
|||||||
- `(condense pixel q)` Condense the data of pixels.
|
- `(condense pixel q)` Condense the data of pixels.
|
||||||
- `(balance pixel q)` Change the color balance of pixels.
|
- `(balance pixel q)` Change the color balance of pixels.
|
||||||
- `(concat ...items)` Concat multiple strings.
|
- `(concat ...items)` Concat multiple strings.
|
||||||
|
- `(split string char)` Split string at character.
|
||||||
- `(add ...args)` Adds values.
|
- `(add ...args)` Adds values.
|
||||||
- `(sub ...args)` Subtracts values.
|
- `(sub ...args)` Subtracts values.
|
||||||
- `(mul ...args)` Multiplies values.
|
- `(mul ...args)` Multiplies values.
|
||||||
@ -102,9 +103,10 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
|
|||||||
- `(eq a b)` Returns true if a is equal to b, else false.
|
- `(eq a b)` Returns true if a is equal to b, else false.
|
||||||
- `(and a b ...rest)` Returns true if all conditions are true.
|
- `(and a b ...rest)` Returns true if all conditions are true.
|
||||||
- `(or a b ...rest)` Returns true if at least one condition is true.
|
- `(or a b ...rest)` Returns true if at least one condition is true.
|
||||||
- `(map fn arr)`
|
- `(each arr fn)` Run a function for each element in a list.
|
||||||
- `(filter fn arr)`
|
- `(map arr fn)` Run a function on each element in a list.
|
||||||
- `(reduce fn arr acc)`
|
- `(filter arr fn)` Remove from list, when function returns false.
|
||||||
|
- `(reduce arr fn acc)`
|
||||||
- `(len item)` Returns the length of a list.
|
- `(len item)` Returns the length of a list.
|
||||||
- `(first arr)` Returns the first item of a list.
|
- `(first arr)` Returns the first item of a list.
|
||||||
- `(last arr)` Returns the last
|
- `(last arr)` Returns the last
|
||||||
@ -124,9 +126,8 @@ Ronin helpers are keywords that facilitates adding coordinates from the canvas i
|
|||||||
- `(dirpath ~path)` Returns the path of a directory.
|
- `(dirpath ~path)` Returns the path of a directory.
|
||||||
- `(filepath ~path)` Returns the path of a file.
|
- `(filepath ~path)` Returns the path of a file.
|
||||||
- `(exit ~force)` Exits Ronin.
|
- `(exit ~force)` Exits Ronin.
|
||||||
- `(echo ...args)`
|
- `(echo ...args)` Print arguments to interface.
|
||||||
- `(table arg)`
|
- `(debug arg)` Print arguments to console.
|
||||||
- `(debug arg)`
|
|
||||||
- `(time ~rate)` Returns timestamp in milliseconds.
|
- `(time ~rate)` Returns timestamp in milliseconds.
|
||||||
- `(js)` Javascript interop.
|
- `(js)` Javascript interop.
|
||||||
- `(on event f)` Triggers on event.
|
- `(on event f)` Triggers on event.
|
||||||
|
@ -215,6 +215,10 @@ function Library (ronin) {
|
|||||||
return items.reduce((acc, item) => { return `${acc}${item}` }, '')
|
return items.reduce((acc, item) => { return `${acc}${item}` }, '')
|
||||||
}
|
}
|
||||||
|
|
||||||
|
this.split = function (string, char) { // Split string at character.
|
||||||
|
return string.split(char)
|
||||||
|
}
|
||||||
|
|
||||||
// Math
|
// Math
|
||||||
|
|
||||||
this.add = (...args) => { // Adds values.
|
this.add = (...args) => { // Adds values.
|
||||||
@ -320,14 +324,21 @@ function Library (ronin) {
|
|||||||
|
|
||||||
// Arrays
|
// Arrays
|
||||||
|
|
||||||
this.map = async (fn, arr) => {
|
this.each = async (arr, fn) => { // Run a function for each element in a list.
|
||||||
for (let i = 0; i < arr.length; i++) {
|
for (let i = 0; i < arr.length; i++) {
|
||||||
const arg = arr[i]
|
const arg = arr[i]
|
||||||
await fn(arg)
|
await fn(arg)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.filter = (fn, arr) => {
|
this.map = async (arr, fn) => { // Run a function on each element in a list.
|
||||||
|
for (let i = 0; i < arr.length; i++) {
|
||||||
|
const arg = arr[i]
|
||||||
|
arr[i] = await fn(arg)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
this.filter = (arr, fn) => { // Remove from list, when function returns false.
|
||||||
const list = Array.from(arr)
|
const list = Array.from(arr)
|
||||||
return Promise.all(list.map((element, index) => fn(element, index, list)))
|
return Promise.all(list.map((element, index) => fn(element, index, list)))
|
||||||
.then(result => {
|
.then(result => {
|
||||||
@ -337,7 +348,7 @@ function Library (ronin) {
|
|||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
this.reduce = async (fn, arr, acc) => {
|
this.reduce = async (arr, fn, acc) => {
|
||||||
const length = arr.length
|
const length = arr.length
|
||||||
let result = acc === undefined ? subject[0] : acc
|
let result = acc === undefined ? subject[0] : acc
|
||||||
for (let i = acc === undefined ? 1 : 0; i < length; i++) {
|
for (let i = acc === undefined ? 1 : 0; i < length; i++) {
|
||||||
@ -463,17 +474,12 @@ function Library (ronin) {
|
|||||||
ronin.source.quit(force)
|
ronin.source.quit(force)
|
||||||
}
|
}
|
||||||
|
|
||||||
this.echo = (...args) => {
|
this.echo = (...args) => { // Print arguments to interface.
|
||||||
ronin.log(args)
|
ronin.log(args)
|
||||||
return args
|
return args
|
||||||
}
|
}
|
||||||
|
|
||||||
this.table = (arg) => {
|
this.debug = (arg) => { // Print arguments to console.
|
||||||
console.table(arg)
|
|
||||||
return arg
|
|
||||||
}
|
|
||||||
|
|
||||||
this.debug = (arg) => {
|
|
||||||
console.log(arg)
|
console.log(arg)
|
||||||
return arg
|
return arg
|
||||||
}
|
}
|
||||||
|
24
examples/batch/folder.lisp
Normal file
24
examples/batch/folder.lisp
Normal file
@ -0,0 +1,24 @@
|
|||||||
|
; open every file in a folder.
|
||||||
|
(defn filter-jpg
|
||||||
|
(file-name)
|
||||||
|
(eq
|
||||||
|
(last
|
||||||
|
(split file-name ".")) "jpg"))
|
||||||
|
;
|
||||||
|
(def images
|
||||||
|
(filter
|
||||||
|
(dir) filter-jpg))
|
||||||
|
;
|
||||||
|
(debug
|
||||||
|
(concat "Found: "
|
||||||
|
(len images)))
|
||||||
|
;
|
||||||
|
(defn image-operation
|
||||||
|
(file-name)
|
||||||
|
(
|
||||||
|
(def file-path
|
||||||
|
(concat
|
||||||
|
(dirpath) "/" file-name))
|
||||||
|
(open file-path)))
|
||||||
|
;
|
||||||
|
(each images image-operation)
|
@ -35,9 +35,9 @@
|
|||||||
(test "range simple" (range 0 4) (0 1 2 3 4))
|
(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 step" (range 0 4 2) (0 2 4))
|
||||||
(test "range with negative step" (range 0 -4 -1) (0 -1 -2 -3 -4))
|
(test "range with negative step" (range 0 -4 -1) (0 -1 -2 -3 -4))
|
||||||
(test "map" (map (λ (a) (add 1 a)) (1 2 3)) (2 3 4))
|
(test "map" (map (1 2 3) (λ (a) (add 1 a))) (2 3 4))
|
||||||
(test "filter" (filter (λ (a) (eq 0 (mod a 2))) (2 3 4 5 6)) (2 4 6))
|
(test "filter" (filter (2 3 4 5 6)) (λ (a) (eq 0 (mod a 2))) (2 4 6))
|
||||||
(test "reduce" (reduce (λ (acc val) (add acc val)) (1 2 3) 4) 10)
|
(test "reduce" (reduce (1 2 3) (λ (acc val) (add acc val)) 4) 10)
|
||||||
|
|
||||||
; Scope
|
; Scope
|
||||||
|
|
||||||
|
@ -16,11 +16,11 @@
|
|||||||
|
|
||||||
(defn dejong (r a b c d)
|
(defn dejong (r a b c d)
|
||||||
(reduce
|
(reduce
|
||||||
|
(range 0 r)
|
||||||
(λ (acc val)
|
(λ (acc val)
|
||||||
(first (
|
(first (
|
||||||
(_dejong (first acc) (last acc) a b c d)
|
(_dejong (first acc) (last acc) a b c d)
|
||||||
)))
|
)))
|
||||||
(range 0 r)
|
|
||||||
(2 1)
|
(2 1)
|
||||||
)
|
)
|
||||||
)
|
)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user