From 18dd42f65e620326bb21ffcde92004cc9705cbf8 Mon Sep 17 00:00:00 2001 From: Kaz Kylheku Date: Sun, 1 Nov 2015 19:18:57 -0800 Subject: New range type, distinct from cons cell. * eval.c (eval_init): Register intrinsic functions rcons, rangep from and to. (eval_init): Register rangep intrinsic. * gc.c (mark_obj): Traverse RNG objects. (finalize): Handle RNG in switch. * hash.c (equal_hash, eql_hash): Hashing for for RNG objects. * lib.c (range_s, rcons_s): New symbol variables. (code2type): Handle RNG type. (eql, equal): Equality for ranges. (less_tab_init): Table extended to cover RNG. (less): Semantics defined for ranges. (rcons, rangep, from, to): New functions. (obj_init): range_s and rcons_s variables initialized. (obj_print_impl): Produce #R notation for ranges. (generic_funcall, dwim_set): Recognize range objects for indexing * lib.h (enum type): New enum member, RNG. MAXTYPE redefined to RNG value. (TYPE_SHIFT): Increased to 5 since there are now 16 type codes. (struct range): New struct type. (union obj): New member rn, of type struct range. (range_s, rcons_s, rcons, rangep, from, to): Declared. (range_bind): New macro. * parser.l (grammar): New rule for recognizing the #R sequence as HASH_R token. * parser.y (HASH_R): New terminal symbol. (range): New nonterminal symbol. (n_expr): Derives the new range symbol. The n_expr DOTDOT n_expr rule produces rcons expression rather than const. * match.c (format_field): Recognize rcons syntax in fields which is now what ranges translate to. Also recognize range object. * tests/013/maze.tl (neigh): Fix code which destructures range as a cons. That can't be done any more. * txr.1: Document ranges. --- tests/013/maze.tl | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) (limited to 'tests/013') diff --git a/tests/013/maze.tl b/tests/013/maze.tl index f65bc9e0..5cb989d6 100644 --- a/tests/013/maze.tl +++ b/tests/013/maze.tl @@ -13,7 +13,8 @@ (if list [list (rand (length list))])) (defun neigh (loc) - (tree-bind (x . y) loc + (let ((x (from loc)) + (y (to loc))) (list (- x 1)..y (+ x 1)..y x..(- y 1) x..(+ y 1)))) -- cgit v1.2.3