Errors in Mozart / Oz with tree traversal examples from book " Concepts, Techniques, and Models of Computer Programming " -


thanks in advance, , apologies errors or confusing post.

i getting errors tree traversal examples in section 3.4.6 of " concepts, techniques, , models of computer programming ". using oz / mozart2-2.0.0-alpha.0 (+build.4091-slitaz-1.01.ova).

i entering below procedures , functions in book (two versions of book, different code) , getting errors when try execute. i've tried fixing them myself, cannot anywhere far. i'll give code, execution statements, errors, , test tree declaration (which seems valid can execute {lookup}, {insert} , {delete} on without issue) below. i'll include more notes think necessary, below..

so, question is wrong these bits of code or how using them or trees? included function , 3 procedures giving same issue complete (and maybe troubleshooting), think solution same all.

tree declaration last, below.

the code -->

%all of below errors occur upon execution, not on definition of proc or function  % version: vanroyharidi2003-book.pdf % section 3.4.6 - "trees","tree traversal", "depth-first traversal % p.159 (adobe reader p. 202 of 939)  declare  proc {dfs t}    case t    of leaf skip    [] tree(key val l r)       {dfs l}       {browse key#val}       {dfs r}    end end  {dfs s}  /* %******************** error: conditional failed ***************** %** %** missing else clause %** %** matching: tree(key:250 left:tree(key:125 left:tree(key:60 left:tree(key:30 left:leaf right:leaf value:pyramid) right:tree(key:90 left:leaf right:leaf value:cube) value:sphere) right:tree(key:185 left:tree(key:155 left:leaf right:leaf value:wave) right:tree(key:215 left:leaf right:leaf value:plane) value:shadow) value:shape) right:tree(key:375 left:tree(key:315 left:tree(key:285 left:leaf right:leaf value:boing) right:tree(key:345 left:leaf right:leaf value:ring) value:tap) right:tree(key:435 left:tree(key:405 left:leaf right:leaf value:whoosh) right:tree(key:465 left:leaf right:leaf value:ping) value:boom) value:sounds) value:treetop) %** in file "/mnt/host_folder/trees - traversals", line 39 %** %** call stack: %** procedure 'dfs' in file "/mnt/host_folder/trees - traversals", line 33, column 1, pc = -1279897415 %**-------------------------------------------------------------- */  % version: ctmchapters1-3.pdf, "tree traversal" p.155 (adobe read p. 181 of 226) % section 3.4.6.2, "tree traversal" declare proc {dfs t}    case t    of leaf skip    [] tree(key val l r)       {browse key#val}       {dfs l}            {dfs r}    end end  {dfs s} % {dfs t} version 2 had same error 1st version % know trivially different, included anyway... sorry  % same page {dfs t} in ctmchapters1-3.pdf (only). declare proc {dfsaccloop t s1 ?sn}    case t    of leaf sn=s1    [] tree(key val l r) s2 s3 in       s2=key#val|s1       {dfsaccloop l s2 s3}       {dfsaccloop l s3 sn}    end end fun {dfsacc t} {reverse {dfsaccloop s nil $}} end  {browse {dfsacc s}} /* %******************** error: conditional failed ***************** %** %** missing else clause %** %** matching: tree(key:250 left:tree(key:125 left:tree(key:60 left:tree(key:30 left:leaf right:leaf value:pyramid) right:tree(key:90 left:leaf right:leaf value:cube) value:sphere) right:tree(key:185 left:tree(key:155 left:leaf right:leaf value:wave) right:tree(key:215 left:leaf right:leaf value:plane) value:shadow) value:shape) right:tree(key:375 left:tree(key:315 left:tree(key:285 left:leaf right:leaf value:boing) right:tree(key:345 left:leaf right:leaf value:ring) value:tap) right:tree(key:435 left:tree(key:405 left:leaf right:leaf value:whoosh) right:tree(key:465 left:leaf right:leaf value:ping) value:boom) value:sounds) value:treetop) %** in file "/mnt/host_folder/trees - traversals", line 67 %** %** call stack: %** procedure 'dfsaccloop' in file "/mnt/host_folder/trees - traversals", line 61, column 1, pc = -1239512161 %** procedure 'dfsacc' in file "/mnt/host_folder/trees - traversals", line 70, column 1, pc = -1239496575 %** toplevel abstraction in line 1, column 0, pc = -1238883005 %**--------------------------------------------------------------  */  % 1 of versions of {lookup x t} gives same error.  % version: ctmchapters1-3.pdf, "tree traversal" p.152 (adobe read p. 178 of 226) % section 3.4.6.2, "storing information in trees" declare fun {lookup x t}    case t    of leaf notfound    [] tree(y v t1 t2)       if x<y {lookup x t1}       elseif x>y {lookup x t2}       else found(v) end    end end /* %******************** error: conditional failed ***************** %** %** missing else clause %** %** matching: tree(key:horse left:tree(key:dog left:tree(key:cat left:leaf right:leaf value:chat) right:tree(key:elephant left:leaf right:leaf value:elephant) value:chien) right:tree(key:mouse left:tree(key:monkey left:leaf right:leaf value:singe) right:tree(key:tiger left:leaf right:leaf value:tigre) value:souris) value:cheval) %** in file "/mnt/host_folder/lookup insert delete", line 37 %** %** call stack: %** procedure 'lookup' in file "/mnt/host_folder/lookup insert delete", line 31, column 1, pc = -1241765194 %** toplevel abstraction in line 1, column 0, pc = -1241110606 %**-------------------------------------------------------------- */  % case version works, suprised when traversals using case not working me. declare fun {lookup k t}     case t of leaf notfound    [] tree(key:x value:v left:t1 right:t2) andthen x==k found(v)    [] tree(key:x value:v left:t1 right:t2) andthen x<k {lookup k t2}    [] tree(key:x value:v left:t1 right:t2) andthen x>k {lookup k t1}    end end  % there 2 test trees here declare s=tree(key:250 value:treetop        left:tree(key:125 value:dash                  left:tree(key:60 value:sphere                            left:tree(key:30 value:pyramid left:leaf right:leaf)                            right:tree(key:90 value:cube left:leaf right:leaf))                  right:tree(key:185 value:shadow                             left:tree(key:155 value:wave left:leaf right:leaf)                             right:tree(key:215 value:plane left:leaf right:leaf)))        right:tree(key:375 value:hum                   left:tree(key:315 value:tap                             left:tree(key:285 value:boing left:leaf right:leaf)                             right:tree(key:345 value:ring left:leaf right:leaf))                   right:tree(key:435 value:boom                              left:tree(key:405 value:whoosh left:leaf right:leaf)                              right:tree(key:465 value:ping left:leaf right:leaf))))  t=tree(key:horse value:cheval        left:tree(key:dog value:chien                  left:tree(key:cat value:chat left:leaf right:leaf)                  right:tree(key:elephant value:elephant left:leaf right:leaf))        right:tree(key:mouse value:souris                   left:tree(key:monkey value:singe left:leaf right:leaf)                   right:tree(key:tiger value:tigre left:leaf right:leaf)))  {browse s} {browse t} 

looking @ first program: declaration of tree wrong, can see compiler cannot match tree of clauses defined in case structure, example first program trying match in form (simplified form of declaration):

s=tree(key:250 value:treetop left:leaf right:leaf) 

with clauses:

of leaf skip [] tree(key val l r) 

s can't match neither leaf nor second, key can't match key:250 compiler gives error. can declare tree as:

s = tree(250 treetop tree(120 foo leaf leaf) tree(100 foo2 leaf leaf)) 

you can fix accordingly other programs..


Comments

Popular posts from this blog

SVG stroke-linecap doesn't work for circles in Firefox? -

routes - Laravel 4 Wildcard Routing to Different Controllers -

cross browser - XSLT namespace-alias Not Working in Firefox or Chrome -