mirror of
https://github.com/peklaiho/madlisp.git
synced 2024-11-26 07:04:27 +00:00
add Compare functions
This commit is contained in:
parent
cc9fa06117
commit
4aa2a79a7b
@ -15,6 +15,7 @@ function ml_get_lisp(): array
|
||||
$env = new MadLisp\Env();
|
||||
|
||||
(new MadLisp\Lib\Math())->register($env);
|
||||
(new MadLisp\Lib\Compare())->register($env);
|
||||
|
||||
/*
|
||||
$env->set('eval', function (...$args) use ($eval, $env) {
|
||||
|
45
src/Lib/Compare.php
Normal file
45
src/Lib/Compare.php
Normal file
@ -0,0 +1,45 @@
|
||||
<?php
|
||||
namespace MadLisp\Lib;
|
||||
|
||||
use MadLisp\CoreFunc;
|
||||
use MadLisp\Env;
|
||||
|
||||
class Compare implements ILib
|
||||
{
|
||||
public function register(Env $env): void
|
||||
{
|
||||
// TODO: handle collections
|
||||
|
||||
$env->set('=', new CoreFunc('=', 'Return true if arguments are equal.', 2, 2,
|
||||
fn ($a, $b) => $a == $b
|
||||
));
|
||||
|
||||
$env->set('==', new CoreFunc('==', 'Return true if arguments are equal using strict comparison.', 2, 2,
|
||||
fn ($a, $b) => $a === $b
|
||||
));
|
||||
|
||||
$env->set('!=', new CoreFunc('!=', 'Return true if arguments are not equal.', 2, 2,
|
||||
fn ($a, $b) => $a != $b
|
||||
));
|
||||
|
||||
$env->set('!==', new CoreFunc('!==', 'Return true if arguments are not equal using strict comparison.', 2, 2,
|
||||
fn ($a, $b) => $a !== $b
|
||||
));
|
||||
|
||||
$env->set('<', new CoreFunc('<', 'Return true if first argument is less than second argument.', 2, 2,
|
||||
fn ($a, $b) => $a < $b
|
||||
));
|
||||
|
||||
$env->set('<=', new CoreFunc('<=', 'Return true if first argument is less or equal to second argument.', 2, 2,
|
||||
fn ($a, $b) => $a <= $b
|
||||
));
|
||||
|
||||
$env->set('>', new CoreFunc('>', 'Return true if first argument is greater than second argument.', 2, 2,
|
||||
fn ($a, $b) => $a > $b
|
||||
));
|
||||
|
||||
$env->set('>=', new CoreFunc('>=', 'Return true if first argument is greater or equal to second argument.', 2, 2,
|
||||
fn ($a, $b) => $a >= $b
|
||||
));
|
||||
}
|
||||
}
|
@ -13,17 +13,6 @@ class Core implements ILib
|
||||
{
|
||||
public function register(Env $env): void
|
||||
{
|
||||
// arithmetic
|
||||
|
||||
// comparison
|
||||
|
||||
$env->set('=', fn ($a, $b) => $a == $b);
|
||||
$env->set('<', fn ($a, $b) => $a < $b);
|
||||
$env->set('>', fn ($a, $b) => $a > $b);
|
||||
$env->set('<=', fn ($a, $b) => $a <= $b);
|
||||
$env->set('>=', fn ($a, $b) => $a >= $b);
|
||||
$env->set('!=', fn ($a, $b) => $a != $b);
|
||||
|
||||
// types
|
||||
|
||||
$env->set('type?', function ($a) {
|
||||
|
Loading…
Reference in New Issue
Block a user