###### test: linked_list
- struct node
+ struct linkage
next: @node
+ struct node
+ list: linkage
this: string
- func insert(list:@node; new:string):@node
+ func insert(list:@linkage; new:string)
p:=list
- prev := @nil
- while ?p and then p.this < new:
- prev = p
- p = p.next
- if ?prev:
- prev.next = @new()
- prev.next.next = p
- prev.next.this = new
- else
- list = @new()
- list.next = p
- list.this = new
- use list
-
- func printlist(list:@node)
- while ?list:
- print list@.this
- list = list@.next
-
- func freelist(list:@node)
- if list != @nil:
- freelist(list.next)
- @free = list
+ while ?p.next and then p.next.this < new:
+ p = p.next.list
+ t:@node = @new()
+ t.list.next = p.next
+ t.this = new
+ p.next = t;
+
+ func printlist(list:@linkage)
+ while ?list.next:
+ print list@.next.this
+ list = list@.next.list
+
+ func freelist(list:@linkage)
+ if list.next != @nil:
+ lp:@linkage = list.next.list
+ freelist(lp)
+ @free = list.next
func main(argv:[ac::]string)
- list := insert(@nil, "@start")
- list = insert(list, "~end")
+ list : linkage
+ lp:@linkage = list
+
+ insert(lp, "@start");
+ insert(lp, "~end")
for i:=1; then i=i+1; while i < ac:
- list = insert(list, argv[i])
- list = insert(list, "Hello!")
- printlist(list)
- freelist(list)
+ insert(lp, argv[i])
+ insert(lp, "Hello!")
+ printlist(lp)
+ freelist(lp)
###### output: linked_list,one,two,three,four
@start
print num@
if num == @nil or ref == ref2 or ref == 2 or ref.foo:
@free = num
+ ref = 1
###### output: ref_err2
.tmp.code:5:22: error: @new() can only be used with references, not number
.tmp.code:7:56: error: have none but need Boolean
.tmp.code:8:17: error: @free can only be assigned a reference, not number
.tmp.code:8:17: error: @free can only be assigned a reference, not number
+ .tmp.code:9:8: error: Cannot assign an rval to a reference.
oceani: type error in program - not running.
## Test erroneous command line args