Skip to content

Instantly share code, notes, and snippets.

View mhcoma's full-sized avatar
🔰
Noob

Coma mhcoma

🔰
Noob
View GitHub Profile
@niconii
niconii / list.fs
Last active May 29, 2024 19:24
Simple linked list implementation in Forth
0 constant nil
: cons ( car cdr -- list ) here >r swap , , r> ;
: list ( x... #x -- list ) nil swap 0 ?do cons loop ;
: list: ( x... #x "name" -- ) list constant ;
: car ( list -- car ) @ ;
: car! ( car list -- ) ! ;
: cdr ( list -- cdr ) cell+ @ ;
: cdr! ( cdr list -- ) cell+ ! ;
: list. ( list -- ) begin ?dup while dup car . cdr repeat ;