>>>>> "bbrown" == bbrown <[EMAIL PROTECTED]> writes:
bbrown> Hello, I am kind of embarrased for asking, but I am. And,
bbrown> others from the imperative/procedural world may ask the same
bbrown> questions. I am trying to convert some code to factor, but am
bbrown> having an issue with understanding how the stack works and how
bbrown> to manipulate and get values from it. Say, for example; how
bbrown> would you convert this java code to factor. I have an idea,
bbrown> but not 100%.
You would not convert the code as-is. However, if you really want to
do this, this could give something like:
: 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 ;
Sam
--
Samuel Tardieu -- [EMAIL PROTECTED] -- http://www.rfc1149.net/
-------------------------------------------------------------------------
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