madlisp/src/Util.php

45 lines
926 B
PHP
Raw Normal View History

2020-05-31 04:34:24 +00:00
<?php
2020-12-14 01:49:07 +00:00
/**
* MadLisp language
* @link http://madlisp.com/
* @copyright Copyright (c) 2020 Pekka Laiho
*/
2020-05-31 04:34:24 +00:00
namespace MadLisp;
class Util
{
public static function makeHash(array $args): Hash
{
if (count($args) % 2 == 1) {
throw new MadLispException('uneven number of arguments for hash');
}
$data = [];
for ($i = 0; $i < count($args) - 1; $i += 2) {
$key = $args[$i];
$val = $args[$i + 1];
if (!is_string($key)) {
throw new MadLispException('invalid key for hash (not string)');
}
$data[$key] = $val;
}
return new Hash($data);
}
2020-12-11 01:57:31 +00:00
public static function valueForCompare($a)
{
if ($a instanceof Symbol) {
return $a->getName();
} elseif ($a instanceof Collection) {
return $a->getData();
}
return $a;
}
2020-05-31 04:34:24 +00:00
}