Arc Forumnew | comments | leaders | submitlogin
The Factor Language
4 points by mecon 6160 days ago | 10 comments
Before Arc was released I liked and I still like Factor. Factor is very fast for the amount of power it gives you like parsing words. local variables and closures are efficiently implemented in user space. I'm not trolling I just want to see what you think about Factor.

get it at http://factorcode.org



10 points by raymyers 6159 days ago | link

I have this friend, really sharp guy.

When we were sophmores he was learning Lisp, which was greek to me. ("What the heck is a lambda?!") Two years later, Lisp was my favorite language.

By then, he was learning Haskell, which I could barely stand to look at. ("What the heck is a comprehension?!") Today, I love Haskell too.

Why am I telling you all this? Because that guy is into Factor now, though it's still total gibberish to me.

-----

3 points by Jesin 6153 days ago | link

I am new to Factor, but I know enough to explain some of the basics. Factor, like Lisp, can do anything to a code block that it can do to a sequence. Observe:

  : until ( pred body tail -- )
      rot \ not add -rot
      while
  ; inline
Now, a line-by-line explanation (not that end-of-line means any more in Factor than it does in Lisp).

  : until ( pred body tail -- )
This starts the definition of until, and then says that it takes three values from the top of the stack (pred, body, and tail from bottom to top) and leaves none of them on the stack at the end. This particular word assumes that the 3 arguments it takes are quotations (although it does not state that; it's dynamically typed) (quotation is Factor's name for a code block).

  rot \ not add -rot
rot is a "shuffle word" with this stack effect: ( x y z -- y z x ), in this case that means ( pred body tail -- body tail pred ).

\ not pushes the word not rather than executing it, roughly equivalent to 'no in Arc.

add appends the not we just pushed to the sequence immediately underneath it, pred.

-rot has the stack effect ( x y z -- z x y ), in this case ( body tail pred -- pred body tail ).

  while
This is just a call to the built-in word while, which happens to have the same stack effect we use for until.

  ; inline
This ends the declaration, and tags the word as inline for the benefit of any optimizing compilers.

Whew. That was a lot harder to explain in English than it was to think about in Factor. Of course, anyone explaining Lisp code to a non-Lisper will have the same sort of difficulty. The point here is that you can modify blocks of code as instruction sequences and then execute them. Sound familiar?

  (mac my-until (test . body)
      `(while (no ,test) ,@body))

-----

3 points by lojic 6159 days ago | link

I stopped reading when the author's response to a question regarding the power of Factor included the following:

"Factor is a Turing-complete programming language whose programs are capable of doing whatever any other programming language can do."

-----

3 points by are 6159 days ago | link

I think he was trying to make the point that the word "power", when used about programming languages, is either:

1) Well-defined in terms of computability, but then rather uninteresting, since all programming languages are Turing-complete.

or:

2) So ridiculously ill-defined as to be meaningless.

Instead of arguing about which language is the more "powerful", one should be arguing in terms of which sets of problems have efficient (in terms of programmer time and maybe learning curves) solutions.

-----

2 points by babo 6159 days ago | link

I really nice and pleasant environment to work with, the possibility for a fast lookup/modify of any piece of code and related documentation impressed me. They have a lot of interesting thing on language front as well, it worth to look at.

-----

2 points by sacado 6160 days ago | link

Well, maybe I didn't fully understand how to use it, but it is really too hard for me to write a code that looks like "dup rot- . * + dup dup < . if", even for low-level functions.

I find myself taking too much time thinking "let's see, the value I want is at the third position on the stack, I want to get it duplicated on the top, but without changing the order of the other elements, so I should do..." instead of really solving the problem I'm working on.

But maybe I'll give it another try later ?

-----

3 points by ryantmulligan 6159 days ago | link

Either you can make a word that takes the 3rd element from the stack while maintaining order, or there already is one.

-----

1 point by sacado 6159 days ago | link

But in other languages you don't even have to bother with that. Accessing the third element of the stack is easily feasible and you can even guess how to do it.

And the fact that my variables have no name (they're all called "first element on the stack", "second element", etc.) reminds me assembly code, but without the efficiency : I can understand that in a low-level language as Forth, but it doesn't look like Factor is one.

But I can be wrong, and anyway Factor is on my "try it again later" list.

-----

1 point by mst 6158 days ago | link

On the one hand, factor -does- have named variables.

On the other hand, once you start experimenting with stack stuff there's a moment where you go "aha" and it actually starts to make a lot of sense for temporary variables.

There are probably other aha moments further in that I haven't got to yet; I've not spent as much time with factor as I want to.

I dunno if I'll ever use it for "real stuff", but I think it's worth fighting your way through to the aha moments just like lisp and haskell are even if you never expect to use -them- for "real stuff".

-----

1 point by mecon 6160 days ago | link

O.k thats fine. you just have to get used to it.

-----