On Mon, Mar 12, 2012 at 2:46 AM, Joe Groff <arc...@gmail.com> wrote:

> > I am still not clear on the use of USE: or USING: when I am coding in
> SciTE and
> > copying and pasting to the Listener. Also, now that I have a working
> bunch of
> > code lines, I would like to be able to execute it, but when I type
> '"filename"
> > run' or '"filename" load' it faults. I know I need t define a MAIN entry
> point,
> > and possibly turn my code into one big word (starting with ":" and
> ending with
> > ";", or vocabulary, but I am not sure how yet.
>
> USE: is for importing a single module, as in `USE: foo`. It's
> primarily intended as a shorthand for interactive use. In source code
> you should always write out USING: as in `USING: foo bar ;`.
>
> > To continue with this task, I now need to figure out how to process a
> directory
> > of csv files, extract the same bits as above and append them in one big
> csv file
> > like so:
> >
> > 24/02/2012,1029,998
> > 22/02/2012,1803,1799
> > and so on...
> >
> > The big directory of csv files was created by running a Windows shell
> command,
> > and then a Python OpenOffice-to-csv script from original Excel xls
> files. I
> > would love to re-create that part by using only Factor.
> >
> > After I complete the task, I really want to go back over the code above
> and see
> > if I can make it more 'elegant' or 'Factorish'.
>
> To iterate over the files in a directory, I would recommend looking at
> the `with-directory-files` function, which will change to a directory
> then call a quotation with a sequence containing the names of the
> files in that directory. You should be able to just use `each` to
> apply your existing code over that sequence.
>
> -Joe
>
>
> ------------------------------------------------------------------------------
> 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
>

I have been able to wak the directory and extract the data I needed thanks
to the help here. Pouring over the documentation, which is excellent by the
way and makes learning Factor enjoyable, I have learned tons. I have a few
issues with my current version.

   1. I am unsure how to check for an empty string and skip it if it is
   empty.
   2. 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'.
   3. 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.
   4. 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.
   5. 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...


"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

Here is some sample output lines showing the issues. I couldn't actually
munge the whole directory, since it would hit an out of range for the index
because my current code uses hard codes like '10 cut swap'. I am hoping to
clean this up by changing my regexp for the end of text after checking for
empty strings:

24/11/2010,08:00,1937,1912
25/11/2010,05:00,,
1/282010 (,08:00,1381,1370

Factor is making my brain hurt in a good way. Being a dilettante, the shift
from imperative to stack programming is flexing my brain muscles. Plus I've
always been a once-in-a-while programmer, coding only when I need to for a
task; it's not my day job. Thanks for all of the help.

Rob
------------------------------------------------------------------------------
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

Reply via email to