My recent Factor travels in Light of Haskell
Factor is a modern stack-based language. It has a very interactive and easy-to-use GUI and is fun to work with.
Something was itching me about using this language and it was not until I picked up Haskell Road to Logic Maths and Computer Programming that I knew what was bothering me. He says that _Haskell_ is a type of descriptive programming very different from the prescriptive programming that you see in Java or C.
And that's it. In Factor, one is very mechanical. putting things on the stack, duplicating stack items. Hiding things in a retain stack, etc.
I notice that a lot of Factor functions for stack shuffling scale up to 3 stack elements. Is there something magic about this number of args to a word that it would never have to shuffle on more?
A very telling example of the difference in Haskell and Factor has to do with
this page on the Factor website discussing how to determine if all elements of a sequence obey a boolean:
The word "all"
Tests if all elements in the sequence satisfy the predicate.The implementation makes use of a well-known logical identity:
P[x] for all x <==> not ((not P[x]) for some x)
Let's compare the Factor and the Haskell:
Factor
: all? ( seq quot -- ? )
swap [ swap call not ] contains-with? not
Haskell
all p = and . map p
conclusions
The author of Factor is a very strong mathematician... what provoked him to involve himself in stackrobatics (acrobatics with a stack)?
- metaperl's blog
- Login to post comments
Slava shows how Factor can be similar to the Haskell: