mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-10-18 13:02:04 +00:00
split function now returns a Vector instead of a List
This commit is contained in:
parent
c3d99d60ef
commit
656f805a5c
@ -1,6 +1,6 @@
|
||||
# MadLisp
|
||||
|
||||
MadLisp is a [Lisp](https://en.wikipedia.org/wiki/Lisp_%28programming_language%29) interpreter written in PHP. It is inspired by the [Make a Lisp](https://github.com/kanaka/mal) project, but does not follow that convention or syntax strictly.
|
||||
MadLisp is a [Lisp](https://en.wikipedia.org/wiki/Lisp_%28programming_language%29) interpreter written in PHP. It is inspired by the [Make a Lisp](https://github.com/kanaka/mal) project, but does not follow that convention or syntax strictly. It provides a fun platform for learning [functional programming](https://en.wikipedia.org/wiki/Functional_programming).
|
||||
|
||||
## Goals
|
||||
|
||||
@ -273,7 +273,7 @@ upcase | `(upcase "abc")` | `"ABC"` | Make the string upper case using [strtoup
|
||||
lowcase | `(lowcase "Abc")` | `"abc"` | Make the string lower case using [strtolower](https://www.php.net/manual/en/function.strtolower.php).
|
||||
substr | `(substr "hello world" 3 5)` | `"lo wo"` | Get a substring using [substr](https://www.php.net/manual/en/function.substr.php).
|
||||
replace | `(replace "hello world" "hello" "bye")` | `"bye world"` | Replace substrings using [str_replace](https://www.php.net/manual/en/function.str-replace.php).
|
||||
split | `(split "-" "a-b-c")` | `("a" "b" "c")` | Split string using [explode](https://www.php.net/manual/en/function.explode.php).
|
||||
split | `(split "-" "a-b-c")` | `["a" "b" "c"]` | Split string using [explode](https://www.php.net/manual/en/function.explode.php).
|
||||
join | `(join "-" "a" "b" "c")` | `"a-b-c"` | Join string together using [implode](https://www.php.net/manual/en/function.implode.php).
|
||||
format | `(format "%d %.2f" 56 4.5)` | `"56 4.50"` | Format string using [sprintf](https://www.php.net/manual/en/function.sprintf.php).
|
||||
prefix? | `(prefix? "hello world" "hello")` | `true` | Return true if the first argument starts with the second argument.
|
||||
|
@ -3,7 +3,7 @@ namespace MadLisp\Lib;
|
||||
|
||||
use MadLisp\CoreFunc;
|
||||
use MadLisp\Env;
|
||||
use MadLisp\MList;
|
||||
use MadLisp\Vector;
|
||||
|
||||
class Strings implements ILib
|
||||
{
|
||||
@ -38,7 +38,7 @@ class Strings implements ILib
|
||||
));
|
||||
|
||||
$env->set('split', new CoreFunc('split', 'Split the second argument by the first argument into a list.', 2, 2,
|
||||
fn (string $a, string $b) => new MList(explode($a, $b))
|
||||
fn (string $a, string $b) => new Vector(explode($a, $b))
|
||||
));
|
||||
|
||||
$env->set('join', new CoreFunc('join', 'Join the remaining arguments together by using the first argument as glue.', 1, -1,
|
||||
|
Loading…
Reference in New Issue
Block a user