From e82947d00f700558500e85e22aaf187544769a2e Mon Sep 17 00:00:00 2001 From: Chouser Date: Tue, 17 Feb 2015 09:40:03 -0500 Subject: forth: Add step 8 --- forth/core.fs | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) (limited to 'forth/core.fs') diff --git a/forth/core.fs b/forth/core.fs index e601e1d..43e6b75 100644 --- a/forth/core.fs +++ b/forth/core.fs @@ -96,3 +96,21 @@ defcore concat { lists argc } MalList new start over MalList/start ! count over MalList/count ! ;; + +defcore nth ( argv[coll,i] argc ) + over ( argv argc argv ) + cell+ @ MalInt/int @ ( argv argc count ) + swap over <= if ." nth out of bounds" cr 1 throw endif ( argv count ) + cells swap ( c-offset argv ) + @ to-list MalList/start @ + @ ;; + +defcore first ( argv[coll] argc ) + drop @ to-list + dup MalList/count @ 0= if + drop mal-nil + else + MalList/start @ @ + endif ;; + +defcore rest ( argv[coll] argc ) + drop @ to-list MalList/rest ;; -- cgit v1.2.3