Two problems I see at first:
1) Your docell word should be inline, because you are passing a quotation
("op") it needs to be marked inline so it will compile where it is used.
2) You aren't using mutable local variables properly.
You define them initially (say, setting "x" to 1):
1 :> x!
Then you can get the value, like this (without the exclamation), adding two
to "x" (not changing the value of "x" variable):
2 x +
If you want to change the value of "x", say to 5, use the exclamation point:
5 x!
You can see some examples of local variables like this in the docs:
http://docs.factorcode.org/content/article-locals-examples.html
Best,
John.
On Tue, Jul 2, 2013 at 3:20 PM, Mark Green <m...@antelope.nildram.co.uk>wrote:
> Hi,
>
> Is there a good standard implementation of Bresenham's linedraw? My silly
> attempt, which is basically just a translation of a Processing program, is
> below. I know it can be done better than this, I'm just not sure how - and
> this program fails to compile with a rather bizarre error related to the
> first unless statement which apparently takes something like 5 inputs!?
>
> Mark
>
>
> ! Create a new 10x10 grid
> : newgrid ( n n -- byte-array ) * <byte-array> ;
>
> ! Get address of cell x,y
> : celladdress ( n n -- n ) 10 * + ;
>
> ! Get value of cell at x,y
> : cellat ( byte-array n n -- n ) celladdress swap nth ;
>
> ! Do operation on cell at x,y
> :: docell ( array x y op -- ) x y celladdress array op change-nth ;
>
> ! Set value of cell at x,y
> :: setcell ( array x y val -- ) array x y [ drop val ] docell ;
>
> :: los ( map ax ay bx by -- bool )
> bx ax - abs :> dx!
> by ay - abs :> dy!
> dx! dy! - :> err!
> t :> continue!
> t :> result!
> ax ay
> [ continue! ] [
> 2dup cellat 0 = [ f :> continue! f :> result! ] unless
> 2dup by = swap bx = and [ f :> continue! t :> result! ] when
> err 2 *
> dup 0 dy! - > [ err! dy! - :> err! roll dx! sgn + -roll ] when
> dx! < [ err! dx! + :> err! dy! sgn + ] when
> ] while
> result! ;
>
>
> ------------------------------------------------------------------------------
> This SF.net email is sponsored by Windows:
>
> Build for Windows Store.
>
> http://p.sf.net/sfu/windows-dev2dev
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
------------------------------------------------------------------------------
This SF.net email is sponsored by Windows:
Build for Windows Store.
http://p.sf.net/sfu/windows-dev2dev
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk