Bluish Coder

Programming Languages, Martials Arts and Computers. The Weblog of Chris Double.

Posts tagged “factor”

61 posts

Fun Factor Libraries

Factor is a programming language I've written about before and in the early days of Factor development I wrote a number of libraries and contributed to development. It's been a while since I've contributed but I still use Factor. The development environment has a very Smalltalk-like feel to it and it includes full documentation and browseable source code of libraries.... more →

Revisiting the Linear recursion combinator in Factor four years on

The Joy programming language has a linrec combinator for performing linear recursion. Some time ago I took a stab at implementing linrec in Factor. Slava also posted his version that was originally a part of Factor. As can be seen from Slava's version, juggling the stack when four quotations are involved can be problematic. I thought I'd revisit linrec using... more →

Factor Web Framework Example

The Factor web framework was recently redeveloped and my previous post on the topic is out of date. I'm re-learning how to write Factor web applications as I work through a simple app I'm building. At first I was overwhelmed by the large number of features in the new framework, but once I got a bit of an understanding I... more →

Parsing JavaScript with Factor

I've made some more changes to the Parsing Expression Grammar library in Factor. Most of the changes were inspired by things that OMeta can do. The grammar I used for testing is an OMeta-JS grammar for a subset of JavaScript. First the list of changes. Actions in the EBNF syntax receive an AST (Abstract Syntax Tree) on the stack. The... more →

Factor Parsing DSL

I've been doing some experimenting with the emedded grammar code I wrote for Factor, trying to make it easier to use and a bit more useful for real world projects. My inspiration for the changes has been seeing the kinds of things OMeta can do and the examples in the Steps towards the reinvention of programming from the Viewpoints Research... more →

Collection of Factor Articles in PDF

Factor has experienced some rapid change in the libraries and language over the past few years. I've written a few blog posts about Factor in the past and many of them suffer from bitrot due to this, making it hard to try out the examples in the latest Factor versions. I've collected some of these articles, put them in a... more →

Embedded Grammars in Factor

I'm working on a new parser combinator library for Factor based on Parsing Expression Grammars and Packrat parsers. This is based on what I learnt from writing a packrat parser in Javascript. It's progressing quite well and already fixes some problems in the existing parser combinator library I wrote. The main issue with that one is it's not tail recursive... more →

Writing Web Applications in Factor

There was a request on #concatenative for information on how to write web applications in Factor. I went through a few steps on how to get started. I'm repeating it here for others that might be interested. There are a number of different ways of writing web applications in Factor but for this approach I'm using the furnace framework. The... more →

How to publish a Git repository

This post is aimed mainly at Factor developers who need to make their repository accessible to Slava to retrieve patches. Factor has recently moved to using git as the version control system. To set up a repository on a server you should clone the existing Factor repository using the '--bare' option: git clone --bare http://www.factorcode.org/git/factor.git factor.git more →

Distributed Channels in Factor

Following on from my Channels implementation, I've now added 'Remote Channels'. These are distributed channels that allow you to access channels in separate Factor instances, even on different machines on the network. It's based on my Distributed Concurrency work. A channel can be made accessible by remote Factor nodes using the 'publish' word. Given a channel this will return a... more →

Concurrent Channels for Factor

Rob Pike gave a talk at Google about the NewSqueak programming language, and specifically how it's concurrency features work. NewSqueak uses channels and is based on the concepts of Communicating Sequential Processes. To play around with some of the ideas in the video I created a quick implementation of channels for Factor and converted a couple of the NewSqueak examples.... more →

Using the Factory Window Manager on Mac OS X

Factory is an X11 window manager written in Factor by Eduardo Cavazos. Although best used in Linux, it can also be run using the X11.app in Mac OS X. First you need to build Factor using the X11 backend rather than the standard Mac OS X backend. This can be done with the latest darcs code using these steps: cd... more →

A mix of many things

I haven't been blogging much about what I've been doing lately so here's my attempt to put lots of little things in one post. Work at Mozilla is going well. My patches for Firefox related to offline event notifications were reviewed and committed to CVS. Offline support is now in the nightly builds and can be used. I finished the... more →

Ogg Theora support for Factor

A month or two back I did more work on my Ogg bindings for Factor. I didn't blog about it but I added Ogg Theora playback support and moved the Vorbis playback into a generic 'ogg-player' application written in Factor. This is now in the standard Factor distribution. You can play Theora video files by loading the apps/ogg-player module and... more →

Factor Article Manager Source

At the beginning of the year I wrote an 'Article Manager' web application in Factor. The idea was to have a simple way of writing short articles and snippets of information, that could be tagged and navigated. I wanted something small and easy to use, suited for this purpose. In about 8 hours I threw together the article manager and... more →

Factor Space Invaders Updated

I've updated my space invaders emulator written in Factor to work with the new Factor GUI system. This means that Space Invaders can run in a seperate window from the main Factor GUI and you can even run multiple instances at a time. While the emulator is running you can still use the Factor GUI to browse, run code, etc.... more →

Ogg Vorbis support for Factor

I've implemented Ogg Vorbis playback in Factor. The library is in the module 'libs/vorbis' and supports playing Vorbis encoded audio from .ogg files and streams: "test.ogg" play-vorbis-file "http://www.bluishcoder.co.nz/test.ogg" http-get* [ play-vorbis-stream ] keep stream-close more →

Factor on Windows Mobile 5

Slava has been working on porting Factor to the ARM CPU for running on a gumstix. Windows Mobile 5 devices also use a chipset that uses the ARM architecture. Doug Coleman, another Factor contributor, has a Windows Mobile 5 device and was keen to get Factor running on it. Between us we'd been trying out the various options to compile... more →

Factor to Javascript Compiler Makeover

I've made some changes to the way the Factor to Javascript compiler REPL works. I used 'termlib' to make a terminal style interface for the REPL. Instead of entering Factor code, hitting submit, and waiting for the result, you can type in a listener style REPL, hit enter and get the result back. It works much better. History is available... more →

Factor Compiler Transforms and Shuffle Words

Factor has a couple of different ways of automatically generating code. One of these is 'parsing words'. These are words that get run at parse time and can generate code that then gets compiled. I used this approach in the 8080 emulator to parse a domain specific language into Factor code: INSTRUCTION: LD SP,HL ; opcode F9 cycles 06 more →

Lunar Rescue Emulator

The Space Invaders emulator I wrote is actually a generic 8080 emulator. Quite a few arcade games used similar hardware to the old Space Invaders machines. more →

Emulating other Intel 8080 Based Arcade Games

I've done some refactoring of the Intel 8080 emulator I wrote in Factor and split the games out into separate libraries. ROM's can now be stored anywhere with the path to the root of the ROM directory set in the 'rom-root' variable. Many of the 8080 based arcade games use similar hardware to Space Invaders. If they use a similar... more →

Space Invaders gets Sound

Following up on my previous post, I've added sound to my Space Invaders Emulator written in Factor. I used the .wav files obtained from the Space Invaders Didactic Emulator and also used the hardware information from that site to work out how the Space Invaders sound system worked. If you have OpenAL and ALUT installed you should be able to... more →

OpenAL library wrapper for Factor

I've written a wrapper for the OpenAL sound library for Factor. It's a thin alien wrapper around the C interface and was pretty easy to write given Factor's great C FFI support (called 'alien'). It has been tested under Windows and Linux and should be easy to get going for the Mac. You'll need to install OpenAL and ALUT. Binaries... more →

Article Management System

I usually have a collection of notes and howto's that I've gathered as I worked out how to do things and file them away. Sometimes they're not really relevant for blog postings or I prefer to be able to edit them over time to keep them up to date - which is not really useful for weblog postings without spamming... more →

Parser Combinators

Gilad Bracha has a post on parser combinators in Smalltalk. It's a good introduction to parser combinators and how to implement them in an OO language. Christian Plesner follows up with more details on writing and using parser combinators in Smalltalk. Christian mentions the left recursion problem for parsing things like lists. For example this grammar: <expr-list> -> <expr-list> ","... more →

JSON Web Services with Factor

There's a post on Matt Croydon's weblog about using Lua to process JSON Web Services. The resulting Lua code is very easy to read. Here's my attempt at the same code in Factor: REQUIRES: libs/http-client libs/json ; USING: kernel io http-client json hashtables prettyprint sequences math namespaces ; more →

ODBC Interface for Factor

I've written a simple wrapper around the ODBC API for Factor. I based it on some Forth code I wrote a few years ago. It has only been tested in Windows but it works quite well and I plan to do some more work on it as I need features. In the meantime it's in my repository: darcs get http://www.bluishcoder.co.nz/repos/factor more →

Implementing concatenative words with Pattern Matching

There's a dicussion on the concatenative mailing list about concatenative languages and macros. The discussion veered into pattern matching and Manfred Von Thun wrote about using pattern matching to implement common concatenative operations. I wrote previously about using pattern matching in Factor to do similar, calling the word 'shuffle'. For example, 2dup, could be implemented as: { ?a ?b }... more →

Basic Authentication added to Factor web server

I've added a simple basic authentication mechanism to the Factor web server (called 'httpd'). Basic Authentication is built into all browsers so it makes for a simple authentication method. It has one major downside and that is the password and username are sent from the browser to the client in clear text. You can work around this by using SSL... more →

Factor Pattern Matching Additions

I've made a couple of additions to the pattern matching library I wrote for Factor. The idea came from a suggestion from Slava in #concatenative. The main addition is a 'match-replace' word. This matches an object against a pattern and constructs a new object given a second pattern. The second pattern can use pattern matching variables from the first pattern... more →

Search and Replace with Parser Combinators

I've added some code to the Factor parser combinator library to allow search and replace using parser combinators. The idea was to be able to do similar things with parser combinators that regular expressions are commonly used for. I've also started adding some simple reusable parsers for numbers, strings, etc. The search word takes a string and a parser off... more →

Cross Domain JSON with fjsc

I've added support to fjsc for cross domain AJAX calls to web services that use the JSON format. Usually Ajax requests from a web page are limited to requesting resources on the server that the web page originated from. A way to work around this is to load cross domain Javascript by creating an HTML SCRIPT tag dynamically, setting the... more →

Continuations added to fjsc

I've added support for continuations to the Factor to Javascript compiler. The public interface is the same as the standard Factor continuation support. Namely the 'callcc0', 'callcc1', 'continue' and 'continue-with' words. This involved quite a few changes to the internals of the compiler. The Javascript generated code is now in continuation passing style (CPS). It makes the generated code harder... more →

Factor to Javascript compiler updates

I've done some minor updates to my compiler from a subset of Factor to Javascript. The updates are now running on the fjsc test page and available from my repository: darcs get http://www.bluishcoder.co.nz/repos/factor more →

Parser Combinator enhancements

While working on the Factor to Javascript compiler I struck some performance issues with how I was using Parser Combinators. The problem manifested when parsing word definitions. For example: : foo ( a b -- c d ) one two ; more →

Factor interface to Google Search

About a year ago I wrote some Factor code to use the Google SOAP API to run automated Google searches. I wanted to put together the results of a quick search so I fixed the code to work with the latest Factor release. The code is in my repository and will hopefully eventually make to the main Factor repository. You... more →

Compiling Factor to Javascript

A while back I wrote a toy Factor to Javascript compiler to use as an example in my Compilers and Interpreters post. I ended up using a different example in that post so didn't do any further work on it. Yuuki from #concatenative is writing a Factor tutorial and I thought it might be useful to put something online to... more →

Factor gets XML-RPC

Factor has an XML-RPC library thanks to Dan (littledan in #concatenative). Slava has a post demonstrating how to use it to talk to the paste.lisp.org pastebin. more →

Factor Parser Combinator example

I was asked on IRC how to use parser combinators to write a simple translator from s-expressions to Factor quotations. The translation was quite simple - here are some examples of how it was supposed to work: (set a 10) => [ "set" "a" 10 ] (set square (lambda (n) (* n n))) => [ "set" "square" [ "lambda" [... more →

Factor 0.86 released

Slava has released version 0.86 of Factor. In other Factor news, Doug Coleman has started a blog with a focus on Factor programming and tutorials. more →

Writing a Lisp Interpreter in Haskell

A neat article that appeared on reddit just recently: Writing a Lisp Interpreter in Haskell. It's interesting to compare the approach to my recent post on writing interpreters in Factor and my parser combinator article for the s-expression parser. Apart from the fact that Haskell is a typed language, the approaches are quite similar. No surprise there since I based... more →

Compilers and Interpreters in Factor

Writing compilers and interpreters in Factor is quite easy. By writing the grammar using parser combinators, and having those combinators produce an abstract syntax tree (AST), it's easy to write a simple compiler or interpreter for the tree. I've already covered writing simple parser combinators so I'll concentrate on processing the AST for a simple language in this post. A... more →

Lazy file reading in Factor

I've added a couple of new lazy list routines in Factor to do lazy stream input/output. These are lazy counterparts to the standard contents and lines words. The new words are 'lcontents' and 'llines'. The first returns a lazy list of all the characters in the file. The second returns a lazy list of all lines in the file. Both... more →

Factor code to upload to the S1 MP3 Player

Futher to my post on using Factor to program the S1 MP3 Player, I got some basic code working to upload Z80 code and execute it. It requires updates to the usb code in my Factor repository: darcs get http://www.bluishcoder.co.nz/repos/factor more →

Writing your own MP3 player firmware

The S1 MP3 Player (or 's1mp3' as it is commonly known as) is a generic type of MP3 that is used and branded by a number of manufacturers. It uses a chip that is firmware updatable, where the firmware is written in Z80 machine code. A number of people have written third party tools allowing writing and running their own... more →

Factor Lazy Lists Revisited

I originally wrote the Lazy Lists library in Factor to support the Parser Combinators library. It was one of my first libraries in Factor and was probably not very well written. Matthew Willis worked on it for the recent Factor releases to get it working with the removal of the standard list datatype and made it a lot better in... more →

Serializable Gadgets

As Slava has noted, I've managed to get the serialization code to the point where it serializes user interface gadgets. To demonstrate it I serialized an in-progress game of Space Invaders, uploaded the serialized file to my web server and someone else on IRC downloaded it, deserialized it, and continued where the game left off. Given the gadget on the... more →

Pattern Matching in Factor

For the concurrency library in Factor I've struggled to come up with good ways of writing the main loop of processes that handle messages. Erlang makes it so nice being able to create tuples and break them apart using pattern matching. I've gone from using Factor arrays and breaking them apart with 'first', etc to using generic functions. The latter... more →

Object Serialization with Factor

As Slava noted in his weblog, I've tidied up a previous serialization library to get it working with current Factor versions in the hopes of using it to get distributed concurrency working. The serialisation supports most Factor types and is extensible by adding methods to generic functions. You can even serialize quotations containing words, and so long as those words... more →

Cells style gadget updating in Factor

Factor has a Cells like mechanism for propogating changes in models to their GUI representation (called Gadgets). It's like a lightweight functional reactive programming system. Using the latest darcs Factor code, which includes a Calendar library, you can quite easily get a gadget displaying with a dynamically updated date. To have a gadget dynamically updated it must reference a 'model'... more →

JSON parser for Factor

I've implemented a simple JSON parser for Factor following RFC 4627. It will be available soon from the standard Factor repository and is also available from my darcs repository: darcs get http://www.bluishcoder.co.nz/repos/factor more →

Factor and The Computer Language Shootout

I implemented one of the Computer Language Shootout benchmarks in Factor to see how it would compare. I wanted to get a gauge of the comparative performance of compiled Factor as well as seeing how the Factor implementations of the algorithms looked. I started with the recursion benchmark. A darcs repository containing the Factor code and the C code for... more →

Factor Partial Continuation Updates and Iterators

I've made some changes to the parser combinator library I wrote for Factor. The changes were to make the usage of the library to be more consistent with good Factor style. The first change was to ensure that items on the stack are accessable in an intuitive manner from within the quotations passed to breset and bshift. When writing combinators... more →

Partial Continuations and Factor

I've written some partial continuation support and put it in the Factor contrib directory. It implements bshift and breset as outlined by Oleg's post on comp.lang.scheme. It's in contrib/partial-continuations.factor and can be pulled from my repository until it makes it to the official Factor repository: darcs pull http://www.bluishcoder.co.nz/repos/factor more →

Factor help system

Slava has been busy with Factor lately. Not only has he done a lot more on the AMD 64 backend, he's writing a help system that runs within Factor. more →

Factor website changes

Slava Pestov has moved the main Factor website to a new machine and is running it on the Factor web server. It's also running the Factor code browser. I've retired the browser I was previously running on factor.modalwebserver.co.nz as a result. Slava is using Linode to host the site. Linode provides 'User Mode Linux' machines within which you can install... more →

64bit Factor

Slava has a post about the AMD64 backend he is working on for Factor. There has been quite a bit of interesting progress with Factor recently, including some nice contributions. Someone has even written an X11 window manager in Factor. more →