function map($f, $seq) { $l = new ListClass(); # @ to surpress warning if $f throws an exception @$l->exchangeArray(array_map($f, $seq->getArrayCopy())); return $l; }
function _list() { $v = new ListClass(); $v->exchangeArray(func_get_args()); return $v; }
function seq($src) { if (_list_Q($src)) { if (count($src) == 0) { return NULL; } return $src; } elseif (_vector_Q($src)) { if (count($src) == 0) { return NULL; } $tmp = $src->getArrayCopy(); $s = new ListClass(); $s->exchangeArray($tmp); return $s; } elseif (_string_Q($src)) { if (strlen($src) == 0) { return NULL; } $tmp = str_split($src); $s = new ListClass(); $s->exchangeArray($tmp); return $s; } elseif (_nil_Q($src)) { return NULL; } else { throw new Exception("seq: called on non-sequence"); } return $s; }