mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-22 13:24:46 +00:00
support strings for empty?
This commit is contained in:
parent
d65fb5a58a
commit
80a72b616b
@ -271,6 +271,7 @@ sqrt | `(sqrt 2)` | `1.41` | Calculate the square root.
|
||||
|
||||
Name | Example | Example result | Description
|
||||
------- | ------- | -------------- | -----------
|
||||
empty? | `(empty? "")` | `true` | Return true if argument is empty string.
|
||||
len | `(len "hello world")` | `11` | Return the length of a string using [strlen](https://www.php.net/manual/en/function.strlen.php).
|
||||
trim | `(trim " abc ")` | `"abc"` | Trim the string using [trim](https://www.php.net/manual/en/function.trim).
|
||||
upcase | `(upcase "abc")` | `"ABC"` | Make the string upper case using [strtoupper](https://www.php.net/manual/en/function.strtoupper).
|
||||
|
@ -45,7 +45,15 @@ class Collections implements ILib
|
||||
// Read information
|
||||
|
||||
$env->set('empty?', new CoreFunc('empty?', 'Return true if collection is empty.', 1, 1,
|
||||
fn (Collection $a) => $a->count() == 0
|
||||
function ($a) {
|
||||
if ($a instanceof Collection) {
|
||||
return $a->count() === 0;
|
||||
} elseif (is_string($a)) {
|
||||
return $a === '';
|
||||
}
|
||||
|
||||
throw new MadLispException('argument to empty? is not collection or string');
|
||||
}
|
||||
));
|
||||
|
||||
$env->set('get', new CoreFunc('get', 'Get the item from first argument (collection) by using the second argument as index or key.', 2, 2,
|
||||
|
Loading…
Reference in New Issue
Block a user