mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
add functions ltov and vtol
This commit is contained in:
parent
a6caab3ee2
commit
25ba08a6e7
@ -187,6 +187,8 @@ list | `(list 1 2 3)` | `(1 2 3)` | Create a new list.
|
|||||||
vector | `(vector 1 2 3)` | `[1 2 3]` | Create a new vector.
|
vector | `(vector 1 2 3)` | `[1 2 3]` | Create a new vector.
|
||||||
range | `(range 2 5)` | `[2 3 4]` | Create a vector with integer values from first to argument (inclusive) to second argument (exclusive).
|
range | `(range 2 5)` | `[2 3 4]` | Create a vector with integer values from first to argument (inclusive) to second argument (exclusive).
|
||||||
range | `(range 5)` | `[0 1 2 3 4]` | Range can also be used with one argument in which case it is used as length for a vector of integers starting from 0.
|
range | `(range 5)` | `[0 1 2 3 4]` | Range can also be used with one argument in which case it is used as length for a vector of integers starting from 0.
|
||||||
|
ltov | `(ltov '(1 2 3))` | `[1 2 3]` | Convert list to vector.
|
||||||
|
vtol | `(vtol [1 2 3])` | `(1 2 3)` | Convert vector to list.
|
||||||
empty? | `(empty? [])` | `true` | Return true if collection is empty, otherwise false.
|
empty? | `(empty? [])` | `true` | Return true if collection is empty, otherwise false.
|
||||||
get | `(get [1 2 3] 0)` | `1` | Return the nth element from a sequence, or the corresponding value for the given key from a hash-map.
|
get | `(get [1 2 3] 0)` | `1` | Return the nth element from a sequence, or the corresponding value for the given key from a hash-map.
|
||||||
len | `(len [1 2 3])` | `3` | Return the number of elements in a collection.
|
len | `(len [1 2 3])` | `3` | Return the number of elements in a collection.
|
||||||
|
@ -42,6 +42,16 @@ class Collections implements ILib
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
|
// Conversion
|
||||||
|
|
||||||
|
$env->set('ltov', new CoreFunc('ltov', 'Convert list to vector.', 1, 1,
|
||||||
|
fn (Seq $a) => new Vector($a->getData())
|
||||||
|
));
|
||||||
|
|
||||||
|
$env->set('vtol', new CoreFunc('vtol', 'Convert vector to list.', 1, 1,
|
||||||
|
fn (Seq $a) => new MList($a->getData())
|
||||||
|
));
|
||||||
|
|
||||||
// Read information
|
// Read information
|
||||||
|
|
||||||
$env->set('empty?', new CoreFunc('empty?', 'Return true if collection is empty.', 1, 1,
|
$env->set('empty?', new CoreFunc('empty?', 'Return true if collection is empty.', 1, 1,
|
||||||
|
Loading…
Reference in New Issue
Block a user