My recent Factor travels in Light of Haskell

Submitted by metaperl on Sat, 02/24/2007 - 3:46am.

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)?

Submitted by metaperl on Sat, 02/24/2007 - 4:09am.

Slava shows how Factor can be similar to the Haskell:

: all? map t [ and ] reduce ;

Submitted by metaperl on Sat, 02/24/2007 - 4:15am.


slava: if haskell was strict, and . map p and the above all? would be inefficient
metaperl: slava - why would someone with your depth in mathematics use a prescriptive stack-based language like Factor?
slava: why would someone with your depth in perl chat on irc?
metaperl: instead of a language more similar to mathematical notation
slava: its an illogical question
slava: because i like programming in a stack language
slava: i don't think there is any language which is like mathematical notation, and if there were, it would be unusable because mathematical notation is ambiguous, complex and only suitable for human to human communication
5:10 AM
metaperl: why was Factor developed even though Forth already existed?
slava: because they're very different languages
slava: factor is high level
slava: factor is to lisp what forth is to c, roughly

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.