First, I would like to apologize for using blogger as a blog host. Some of the past factor code on this blog is highly unreadable and probably won't compile with the most recent version of Factor. I have moved a couple of the simple examples to a google code subversion repository and I will try to stay on top of keeping the code in sync with the most recent Factor builds and images.
Use the most recent codeIn getting back to Factor, I was able to compile Factor from the git repository pretty easily under cygwin.
git clone http://factorcode.org/git/factor.git
(git output)
got 9e702a358399c7200e456d3097bb024eda0c2cbc
got a059b9bd38d03225223ed17b855676da30f7889b
got 75782c7e4db9563ffeb7bf9a92377f7305ad0dd2
Checking 2465fills out....
100% (2465/2465) done
I added the no-cygwin flag to the gcc compile flags and simply typed make
-mno-cygwin
(As discussed in Doug Coleman's blog)
http://code-factor.blogspot.com/2007/04/building-factor-in-cygwi-now-suppported.html
I got the most recent bootstrap image (win32 x86) from factorcode.org and then compiled the words into a factor-nt.image. This is all described in the documentation, but I just wanted to mention it to confirm that it does actually work. (For example, trying to compile the most recent version of X11under cygwin might be more of an issue. Compiling factor for windows was pretty straight-forward).
Code under google-code
The simple examples are just that, but they can be run like you would run a script from any other open source scripting language (e.g. python)
I copied the hello world example straight from the repository but added a couple of more comments to remind you about the word definitions and how to look them up through the help system. You will also notice that the example is structured for running in a shell environment.
hello.sh is a simple (a lazy/easy approach) bash script that invokes the factor binary and image and also launches the myhelloworld vocab. The vocab should have a MAIN: word definition that calls your particular entry point code.
time $FACTOR_BIN -i=$FACTOR_IMG -e="\"$VOCAB_NAME\" run" -quiet -run=noneStartup times comparred with Java ExampleI also included a similar Java source example just to see how long it would take the java virtual machine to startup.
$ time java HelloWorldHello World
real 0m0.108s
usr 0m0.015s
sys 0m0.000s
$ ./hello.shCompiling 1 words...
Hello wrld real
l 0m0.145s
user 0m0.015s
sys 0m0.015s
Note: the directory and file structure is importantNote: the directory and file structure is important.
hello.sh - shell script that invokes the factor executable to load the myhelloworld module.
factor_bin_conf.sh - simple include script with factor binary paths
myhelloworld/ - myhelloworld module and subdirectory
* authors.txt - simple text file, list of author names
* myhelloworld.factor - source code with hello word definition
* tags.txt - whitespace separated list of tags to classify the vocabulary
* summary.txt - one line description of the module
The majority of example code in the csvparser example comes from Phil Dawes. He wrote a parser and included source that parses different common separated formats from file. In my client csv parser application, I load all the data from a simple repository of URLs and then count then number of URLs. Over the next couple of more posts I plan to add a bit more functionality like map-reduce words, and some URL analytical tools. This particular Botlist URL data drop contains over 100,000 URLs and associated titles and keywords.
http://www.phildawes.net/blog/2007/10/02/baby-steps-with-factor-a-csvparser/wget http://openbotlist.googlecodmp.tar.gles/botlist_datadump.tar.gz
When running the factor version against a similar Java version, I get the following results:
$ ./parse.sh
Compiling 10 words...
Running simple csv parser example
Opening file, testcsv.txt
Number of lines in file:
85364
Done.
real 0m9.885s
user 0m0.015s
sys 0m0.000s
(see the java directory)
Running the java Application and 174,000 lines of URL data:
$ time java AnalyzeURLFiles botlist_datadump.dat
Analyzing Files
Reading file=botlist_datadump.dat
Total Lines:174008
Completed in=1859 ms
real 0m1.936s
user 0m0.031s
sys 0m0.000s
The java version probably performed a little bit better over all because IBM's JVM is optimized for an Intel dual core machine. Also, I believe I didn't compile factor win32 correctly. But, my goal was only to compare and contrast run times without any tweaking or performance enhancements.The last example opens a socket connection to a HTTP web server and sends a basic HTTP/1.0 GET request and retrieves the response. I have written several of these examples in the past and I will develop a more robust Factor oriented http load testing library as I do a lot of analysis of HTTP traffic.
Full Download
http://haskellnotebook.googlecode.com/files/factor_examples1.tar.gzPart 2: A Factor Operating System (maybe)
I have been developing small hobby operating systems off and on for a while now (more off since I have been doing web development over the last 6 years or so). When I was in college, I leaned more toward systems engineering than pure computer science (hence the Electrical Engineering degree). My interest originally stemmed from religiously studying the Minix (a small microkernel operating system) source code and then early versions of Linux. Over time I created simple 100 line systems. Some in nasm assembly, some in gcc assembly. Some on Motorola chipsets, some of old intel cpus. It was fun, none of the code was useful but still some interesting projects.
In 2002, I created an abandonware operating system project for the intel x86 (I worked on the project for a month or two and abandoned it). The premise was simple; initialize the operating system kernel. Boot from the floppy disk, initialize the interrupts, timers, keyboard driver, VGA driver. I never made it past the hard drive driver, filesystem, scheduling, and application loading. That is what I hope to do with in recreating OrangeLinux/AkitaOS as this new project,
OctaneOS.
Basically, OctaneOS is a simple x86 hobby (currently only has a couple thousand lines of C/Asm code) operating system. I plan to finish the floppy and hard drive driver, file-system and then hopefully boot a customized
Factor image. There is a lot of refactoring work that needs to be done on the old code and there are many driver pieces still missing but I was happy that it actually runs in the bochs emulator and compiles on a modern host system (Ubuntu 7.10).
http://code.google.com/p/octaneos/wiki/ProjectDiaryhttp://octaneos.googlecode.com/svn/trunk/octaneos/