> : myTestInit ( str -- newstr )
> "Testing: " swap append ;
>
> : myTestWord ( seq -- str )
> { "Arg1" "Arg2" "Arg3" "Arg4" } [ write ": " write print ] 2each
> "myTestWord" ;
>
> : myTestDriver ( seq -- str )
> "(null)" myTestInit add* myTestWord drop "myTestDriver" ;
>
> : main ( -- )
> { "Two" "Three" "Four" } myTestDriver drop ;
>
> Now, since the return values of myTestWord and myTestDriver are never
> used, you would rather do:
>
> : myTestInit ( str -- newstr ) "Testing: " swap append ;
>
> : myTestWord ( seq -- )
> { "Arg1" "Arg2" "Arg3" "Arg4" } [ write ": " write print ] 2each ;
>
> : myTestDriver ( seq -- ) "(null)" myTestInit add* myTestWord ;
>
> : main ( -- ) { "Two" "Three" "Four" } myTestDriver ;
>
> or, to avoid repetition of Arg1 .. Arg4,
>
> : myTestInit ( str -- newstr ) "Testing: " swap append ;
> : arg ( n -- str ) "Arg" swap number>string append ": " append ;
> : myTestWord ( seq -- ) 4 [ 1+ arg write print ] 2each ;
> : myTestDriver ( seq -- ) "(null)" myTestInit add* myTestWord ;
> : main ( -- ) { "Two" "Three" "Four" } myTestDriver ;
I just have one minor note to add to this. In Factor, the convention
(though you are by no means bound to do this) is to use dashed-words
instead of camelCase. Also, it's usually bad to have a word called
main. Instead, you should have a word describing what main does, and
then write MAIN: libs/module-name some-word ;
Dan
-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys - and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk