I am a total newbee in factor (have just written my first sctipt).
I hope this list is right place for dumb questions. If it is not,
redirect me to the appropriate place, please!

The problem solved with this my script was trivial: count all different
words in text and print counters in alphabetical order. My solution was:

: process-line ( assoc str -- assoc )
  " " split [ 1 swap pick at+ ] each ;

: collect-data ( assoc -- assoc )
  readln [ process-line collect-data ] when* ;

: read-input ( -- assoc )
  100003 <hashtable>
  collect-data
  "" over delete-at ;

: write-output ( assoc -- )
  dup keys natural-sort
  [ dup write bl over at number>string write nl ] each
  drop ;

read-input write-output

After this first attempt a lot of question arises:

1. Is this a good way to code in factor? Maybe I have missed something
   obvious to others but obscure to me?

2. I am still not comfortable with all this compilation, inlining, stack
   effects inference an all this stuff. As far as I have understood,
   a compiled version can run a magnitude faster than interpreted one.
   Maybe something in my script prevents it from compilation?

2a. factor says "unable to infer stack effect" of readln and write. Why?

3. When calling the script with "factor -script test.factor < in > out",
   it works as expected but prints "Compiling 4 words..." to stdout
   before any real output. Is this disable-able?  The same for GC messages
   to stderr.

4. After looking at examples in source directory, I conclude that idiomatic
   way to write a loop is tail recursion. Is this true? Why there is no
   "while" word and its counterparts? I guess it is for a reason... Or they
   exists and I have just missed them in documentation?

4a. If integers even can be iterated by "each" (very enlightening feature,
    I wish it be in python), why linereaders aren't? Or they are really?

Thanks in advance!

P.S. factor 0.90 for Win32

-- 
Cyril Slobin <[EMAIL PROTECTED]> `When I use a word,' Humpty Dumpty said,
http://wagner.pp.ru/~slobin/ `it means just what I choose it to mean'

-------------------------------------------------------------------------
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to