Re: [Factor-talk] Newbie questions, words and shuffling

2007-01-23 Thread Daniel Ehrenberg
> : 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
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Newbie questions, words and shuffling

2007-01-22 Thread bbrown
On 22 Jan 2007 18:49:33 +0100, Samuel Tardieu wrote
> > "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
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk


Exactly what I was looking for, thanks a lot.


--
Berlin Brown
berlin dot brown at gmail dot com or 
bbrown at botspiritcompany dot com


-
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
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] Newbie questions, words and shuffling

2007-01-22 Thread Samuel Tardieu
> "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
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk