diff options
| author | Chouser <chouser@n01se.net> | 2015-02-17 09:40:03 -0500 |
|---|---|---|
| committer | Chouser <chouser@n01se.net> | 2015-02-21 13:22:44 -0500 |
| commit | e82947d00f700558500e85e22aaf187544769a2e (patch) | |
| tree | 865caec633095612961fc7551ff393ae4537c9db /forth/core.fs | |
| parent | 794bfca1361fc6900f0ea0186d64111c3a02b0f8 (diff) | |
| download | mal-e82947d00f700558500e85e22aaf187544769a2e.tar.gz mal-e82947d00f700558500e85e22aaf187544769a2e.zip | |
forth: Add step 8
Diffstat (limited to 'forth/core.fs')
| -rw-r--r-- | forth/core.fs | 18 |
1 files changed, 18 insertions, 0 deletions
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 ;; |
