I absolutely LOVE the implicit indexing Lutz. Just one question, can we do something with rest in a similar manar?
Eddie
I love it just as much :), you could see implicit indexing as a natural extension of traditional LISP/Scheme evaluation:
traditional LISP
-----------------
built-ins -> apply to args
lambda -> apply to args
newLISP adds
---------------
contexts -> apply default function on args
lists -> indexing with args
Theoretically you could extend this to any data type, i.e. numbers:
number -> slice list in args
(1 '(a b c d e f g)) => (b c d e f g) ; like (rest ...)
(2 '(a b c d e f g)) => (c d e f g) ; like (rest (rest ...))
(2 '(a b c d e f g) 3) => (c d e) ; like (slice ...)
have to think about this a little bit more ...
Lutz
Would something like
(0 3 '(a b c d e)) => (a b c d)
(1 2 '(a b c d e)) => (b c)
?
Eddie
Opps, I didn't see the slice up there. Wouldn't the semantics indicate
(2 '(a b c d e f g) 3) =>
('(c d e f g) 3) =>
f
?
I think the implicit nrest is fine:
(1 '(a b c d)) => (b c d)
(2 '(a b c d)) => (c d)
(10 '(a b c d)) => ()
But I am not happy with the slice (idx theList len) or (idx len theList), just doesn't feel right, but the second syntax may be the better one.
I implemented (undocumented, experimental, list only, no strings) the implicit nrest in the new development version 8.4.7 here: http://newlisp.org/downloads/development
Lutz
I was thinking more
(idx1 idx2 list)
(2 4 '(a b c d e f g)) => '(c d e)
But I'm not sure. The only thing that might be confusing is the position of the number. I still get confused on set-nth and nth-set. There might be a similar problem with implicit indexing and slicing.
Eddie
Already did similar over the weekend, but length instead of idx2 this:
(offset len lst)
(2 4 '(a b c d e f g)) => (c d e f)
so its's basically a slice with implicit indexing, and it also works with negative offsets:
(-4 2 '(a b c d e f g)) => (d e)
and I also have the implicit index/rest now for negative index:
(-3 '(a b c d e f g)) => (e f g)
and everything works on strings too.
Lutz