mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 21:35:03 +00:00
add functions car and cdr because they are familiar for Lispers
This commit is contained in:
parent
16808c7ff9
commit
c53eba8d23
@ -90,9 +90,11 @@ class Collections implements ILib
|
|||||||
|
|
||||||
// Get partial seq
|
// Get partial seq
|
||||||
|
|
||||||
$env->set('first', new CoreFunc('first', 'Return the first element of a sequence or null.', 1, 1,
|
foreach (['car', 'first'] as $name) {
|
||||||
fn (Seq $a) => $a->getData()[0] ?? null
|
$env->set($name, new CoreFunc($name, 'Return the first element of a sequence or null.', 1, 1,
|
||||||
));
|
fn (Seq $a) => $a->getData()[0] ?? null
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$env->set('second', new CoreFunc('second', 'Return the second element of a sequence or null.', 1, 1,
|
$env->set('second', new CoreFunc('second', 'Return the second element of a sequence or null.', 1, 1,
|
||||||
fn (Seq $a) => $a->getData()[1] ?? null
|
fn (Seq $a) => $a->getData()[1] ?? null
|
||||||
@ -116,11 +118,13 @@ class Collections implements ILib
|
|||||||
}
|
}
|
||||||
));
|
));
|
||||||
|
|
||||||
$env->set('tail', new CoreFunc('tail', 'Return new sequence containing all elements of argument except first.', 1, 1,
|
foreach (['cdr', 'tail'] as $name) {
|
||||||
function (Seq $a) {
|
$env->set($name, new CoreFunc($name, 'Return new sequence containing all elements of argument except first.', 1, 1,
|
||||||
return $a::new(array_slice($a->getData(), 1));
|
function (Seq $a) {
|
||||||
}
|
return $a::new(array_slice($a->getData(), 1));
|
||||||
));
|
}
|
||||||
|
));
|
||||||
|
}
|
||||||
|
|
||||||
$env->set('slice', new CoreFunc('slice', 'Return a slice of the given sequence. Second argument is offset and third is length.', 2, 3,
|
$env->set('slice', new CoreFunc('slice', 'Return a slice of the given sequence. Second argument is offset and third is length.', 2, 3,
|
||||||
function (Seq $a, int $offset, ?int $length = null) {
|
function (Seq $a, int $offset, ?int $length = null) {
|
||||||
|
Loading…
Reference in New Issue
Block a user