Author: | rn443 |
---|---|
Mode: | factor |
Date: | Thu, 17 May 2012 18:45:33 |
! x and y are numbers, boards are 2d arrays SYMBOL: _ : marker-at ( x y board -- marker ) nth nth ; : occupied? ( x y board -- ? ) marker-at _ eq? not ; :: in-bounds? ( x y board -- ? ) x y [ 0 >= ] bi@ and x y [ board length < ] bi@ and and ; : available? ( x y board -- ? ) 3dup in-bounds? [ occupied? not ] when ; ! The word available? cannot be executed because it failed to compile ! ! The input quotation to “when” doesn't match its expected effect ! Input Expected Got ! [ occupied? not ] ( ..a -- ..a ) ( x x x -- x )
Author: | otoburb |
---|---|
Mode: | factor |
Date: | Fri, 18 May 2012 00:59:25 |
! Your true and false branches for the available? word ! are not balanced. The true branch conforms to the ! stack effect, but the false branch leaves the x y ! and board elements which violates the stack ! effect declaration. ! The following definition balances both branches: : available? ( x y board -- ? ) 3dup in-bounds? [ occupied? not ] [ 3drop f ] if ;