diff options
| author | Keith Packard <keithp@keithp.com> | 2018-01-04 02:25:45 -0800 | 
|---|---|---|
| committer | Keith Packard <keithp@keithp.com> | 2018-01-04 02:25:45 -0800 | 
| commit | a6e01e7aafb1d1fdb15d633ec23d8fe51afd15df (patch) | |
| tree | 7fcadbfd771e4ba204a0ab80936c076cabf1ffd8 /src/scheme | |
| parent | e030fba5ab556c88af918d08e1b62e63d6605638 (diff) | |
altos/scheme: Add builtin list-tail
This is used enough to warrant a builtin, rather than lisp implementation
Signed-off-by: Keith Packard <keithp@keithp.com>
Diffstat (limited to 'src/scheme')
| -rw-r--r-- | src/scheme/ao_scheme_builtin.c | 25 | ||||
| -rw-r--r-- | src/scheme/ao_scheme_builtin.txt | 1 | 
2 files changed, 26 insertions, 0 deletions
| diff --git a/src/scheme/ao_scheme_builtin.c b/src/scheme/ao_scheme_builtin.c index 0b84a89a..1bfe6942 100644 --- a/src/scheme/ao_scheme_builtin.c +++ b/src/scheme/ao_scheme_builtin.c @@ -231,6 +231,31 @@ ao_scheme_do_list_copy(struct ao_scheme_cons *cons)  }  ao_poly +ao_scheme_do_list_tail(struct ao_scheme_cons *cons) +{ +	ao_poly	list; +	int32_t	v; + +	if (!ao_scheme_check_argc(_ao_scheme_atom_list2dtail, cons, 2, 2)) +		return AO_SCHEME_NIL; +	if (!ao_scheme_check_argt(_ao_scheme_atom_list2dtail, cons, 0, AO_SCHEME_CONS, 1)) +		return AO_SCHEME_NIL; +	list = ao_scheme_arg(cons, 0); +	v = ao_scheme_arg_int(_ao_scheme_atom_list2dtail, cons, 1); +	if (ao_scheme_exception) +		return AO_SCHEME_NIL; +	while (v > 0) { +		if (!list) +			return ao_scheme_error(AO_SCHEME_INVALID, "%v: ran off end", _ao_scheme_atom_list2dtail); +		if (!ao_scheme_is_cons(list)) +			return ao_scheme_error(AO_SCHEME_INVALID, "%v: invalid list", _ao_scheme_atom_list2dtail); +		list = ao_scheme_poly_cons(list)->cdr; +		v--; +	} +	return list; +} + +ao_poly  ao_scheme_do_quote(struct ao_scheme_cons *cons)  {  	if (!ao_scheme_check_argc(_ao_scheme_atom_quote, cons, 1, 1)) diff --git a/src/scheme/ao_scheme_builtin.txt b/src/scheme/ao_scheme_builtin.txt index 4739f121..7298add7 100644 --- a/src/scheme/ao_scheme_builtin.txt +++ b/src/scheme/ao_scheme_builtin.txt @@ -12,6 +12,7 @@ all	f_lambda	cons  all	f_lambda	last  all	f_lambda	length  all	f_lambda	list_copy	list-copy +all	f_lambda	list_tail	list-tail  all	nlambda		quote  QUASI	atom		quasiquote  QUASI	atom		unquote | 
