On Wed, Mar 14, 2012 at 11:33 PM, John Benediktsson <mrj...@gmail.com>wrote:

>
>    1. I am unsure how to check for an empty string and skip it if it is
>    empty.
>
>  "" empty?
>
>
>
>
>    1. I have been unsuccessful in getting it to write to a single file in
>    an append mode, or to create a sequence of files as it goest through 'each'
>    'with-directory-files'.
>
>  "/tmp/foo" ascii [ "hello world" print ] with-file-appender
>
>
>    1. The people who have entered the data mixed mm/dd/yyyy with
>    dd/mm/yyyy in the original Excel sheets that I created my CSV sheets from.
>    Of course it is easy to check for numbers > 12, but dates like 10/10/2010
>    are problematic.
>    2. I had to use file-lines vs. file>csv to bring in the data, or else
>    I could not get my regexp working on the CSV from file>csv.
>
> The csv vocab makes sequences of strings.  The regexp vocab only works on
> strings.
>
> IN: scratchpad "a,b,c" string>csv .
> { { "a" "b" "c" } }
>
> You might want to look into words like "find", "find-from", or other
> sequence operations if you want regexp like searching or matching.
>
>
>    1. Not really an issue, but are there any cominators or other commands
>    that could consolidate all of the 'swap drop swap' commands I have resorted
>    to using. Or 'first second' commands? I wish there was more Factor code out
>    there on the web to learn from...
>
> Well, "swap drop swap" is "nip swap".  But often when you are using stack
> shuffling words, you are not taking advantage of higher level words or
> combinators.  Try reading:
>
> IN: scratchpad "combinators" help
>
> Also, you might find this blog post I wrote on refactoring a word that has
> ugly stack shuffling to be useful:
>
> http://re-factor.blogspot.com/2010/05/evenly-partition-integer.html
>
>
>
>
>
> "resource:work/thodw/data" [
> [
> utf8 file-lines
> [ R/ Date|Ticket|\"Show Time:\"/ re-contains? ] filter
> dup
> 0 swap nth string>csv
> first second 10 cut swap "," append
> swap drop swap
> dup
> 1 swap nth string>csv
> first second 5 cut swap "," append
> swap drop swap
> 2 swap nth string>csv
> dup
> first second "," append swap
> first 4 swap nth
> 3append
> append
> print
> #! utf8 csv>file
> ] each
> ] with-directory-files
>
>
> You might find something like this makes it cleaner:
>
> utf8 file-lines
> [ regexp ] filter
>  { 0 1 2 } swap nths
> [ string>csv ] map
>
> Also, if you are appending and then printing, you can just write the
> strings as they happen, or try looking into the "make" vocabulary:
>
> [ "Hello" % CHAR: \s , "World" % ] "" make .
>
> Best,
> John.
>
>
> ------------------------------------------------------------------------------
> Virtualization & Cloud Management Using Capacity Planning
> Cloud computing makes use of virtualization - but cloud computing
> also focuses on allowing computing to be delivered as a service.
> http://www.accelacomm.com/jaw/sfnl/114/51521223/
> _______________________________________________
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
> Thank you so much, John. I have figured out how to integrate all of your
tips into my code. By 'empty string' I was referring to field or cell in
the CSV file left empty by the data input person, so all I parse out is ""
(a pair of double quotes). It stopped my program from completely walking
the directory, since I had no exceptions, everything is hard-coded. The
find command works to an extent, but I still need to chop out only the
portion I need.

Your article was a good read. Very informative for me. I still haven't
fully integrated your shorthand of my code with the map and array you used
above, because I have some cut commands between the maps, although I
completely understand the concept now.

I think I will start a new thread on a new topic. Do folks here normally
reply at the bottom of the post or inline? Thanks again.

Rob
------------------------------------------------------------------------------
This SF email is sponsosred by:
Try Windows Azure free for 90 days Click Here 
http://p.sf.net/sfu/sfd2d-msazure
_______________________________________________
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to