construct LinkedList { next value ; construct { this | } len { mega | with this ; def i this:value null eq not =i while { this:next null eq not } { this:next =this i ++ =i } i } push { | with item this ; item:unwrap; this:value null eq if { item this:=value; 2 stop } LinkedList:new dup :=value; this:last-entry:=next; } last-entry { list | with this ; while { this:next null eq not } { this:next =this } this } peek { value | with this ; this:last-entry:value } pop { item | with this ; def item this =item null while { item:next null eq not } { pop item item:next =item } "if theres no next item in this"; dup null eq if { pop this:value (null this:=value;) 2 stop } :=next; item:value } push-front { | with item this ; item:unwrap; this:value null eq if { item this:=value; 2 stop } "append new next identical to this, then make this contain new value"; def new LinkedList:new =new this:next new:=next; this:value new:=value; item this:=value; new this:=next; } insert { | with item index this ; item:unwrap; index 0 eq if { item this:push-front 2 stop } def list this =list while { index 1 gt } { list:next =list index -- =index } item list:next:push-front } pop-front { item | with this ; this:value this:next null eq dup if { null this:=value } not if { this:next:value this:=value this:next:next this:=next } } remove { item | with index this ; index 0 eq if { this:pop-front 2 stop } def list this =list while { index 1 gt } { list:next =list index -- =index } list:next:pop-front } get { item | with index this ; while { index 0 gt } { this:next =this index -- =index } this:value } set { item | with value index this ; while { index 0 gt } { this:next =this index -- =index } this:value value this:=value } foreach { | with callable this ; while { this null eq not } { this:value dup null eq not if { callable:call; } this:next =this } } iter { LinkedListIter | with this ; this LinkedListIter:new } } construct LinkedListIter { cur-list ; construct { this | with list this ; list this:=cur-list this } next { item | with this ; this:cur-list dup null eq if { 2 stop } :value this:cur-list:next this:=cur-list; } } include _Iter in LinkedListIter