Hacker News new | ask | show | jobs
by sherjilozair 4809 days ago
I must say, that the syntax and semantics are not intuitive at all. I've spent half an hour trying to learn how does this thing work, and have not been able to. I guess, a damn good tutorial is in order. I think one of the primary reasons Python took off really well, was because of very good tutorials available. The language of Factor's documentation is still only tuned for language designers, not language users.
7 comments

Concatenative language syntax is actually pretty easy at the basic level. I don't know Factor, but I used to dabble a lot in Forth. The single syntactical rule with Forth is that a symbol (called a "word") is one or more non-space characters, delimited by spaces. So the following three things are all words: SWAP ." -1

Next, there's the idea of the stack. Every word is executed, one after the other, and the words operate on the stack. So the four-word sequence 3 4 + . puts a 3 on the stack, then puts a 4 on the stack, then pops the top two numbers from the stack and puts their sum on the stack, then prints the top number on the stack. So the result, naturally, is 11. (Well, it is if you're operating in base 6 at the time. Didn't want to make it TOO easy for you!)

Oh, and there's also the concept of interpreting vs compiling. The colon word, which is spelled :, reads the very next word from the input and begins the definition of that word. Every word it encounters up to the next semi-colon is compiled, not executed. So if I did this

    3 4 + : FOO SWAP DROP ; .
... it would still print out the sum of 3 and 4, but in between it would also define a new word called FOO. Which would be a silly way to program, but it demonstrates the point.

So the short form is: begin reading at the top left, continue rightward and downward until you reach the bottom. There's no syntax as such, like Perl's die "Can't open file" unless $fileopen; because Forth-like languages don't read ahead to the end of the line.

[Edited: HN doesn't do Markdown. WTF? Also, I don't know my left and right.]

That's what's cool about the Forth idea, and why it can be so effective. It's not that it's unintuitive, it just doesn't take Algol-style semantics as a given as we do today. (It was being used before C was even developed.) If we're interested, it's our job to see if we can fit our thought process into the Forth idea, not vice versa.

And it's a very coherent idea. It's meant to respect processor architecture while maintaining a good level of comprehensibility to the human. And it keeps a MUCH closer correspondence between "word" (essentially a routine) and actual instruction. That got WAY lost with C, enter the beast-compiler.

I think of it as a concept layer above assembly, that has features far beyond just mnemonic value. It's like Lisp to me- a language whose "syntax" is dictated by the functional necessity of a computing methodology, not the decisions of language designers. For me at least, the approach leads to much higher productivity for a variety of reasons.

There's also a very high probability that Forth is the first thing to be run when you turn on the computer or cellphone you're reading this from.

Now as to Factor... see my post above and help me out!

Actually, Forth (the predecessor of concatenate languages) has the best tutorials I've ever read - Starting Forth and Thinking Forth by Leo Brodie.

http://www.forth.com/starting-forth/

http://thinking-forth.sourceforge.net

To be fair Factor/Forth's way of thinking is really foreign to the usual Pascal/C derivatives. Learning how to program from scratch certainly too you more than 30min.
It has nothing to do with python being particularly intuitive and everything to do with it being very similar to every other imperative language you already know. If your first language was forth or PS you'd find factor intuitive too.
Postscript was around my 9th language[1] and I find Factor pretty easy to read. I might be a special case as I hate reading Python and every time I try an S-expr language I really never get the hang of it.

Thinking about Python, looks wise it is kind of the opposite of any of the stack languages. I get the feeling that you can like one or the other.

1) various 8-bit BASICs, 6502 ASM, Modula-2, 370 ASM, C, Ada, foxbase, SQL, Postscript, Forth, Objective-C (weird listing it out)

I started with C++ and thought I was just good at picking up languages because I picked up Java and Python in a day or two. Then I realized it was because they were so similar. When I learned Common Lisp I had to do some real work even though ny then I had been programming for 7-8 years.
>> I guess, a damn good tutorial is in order.

Firing up the Factor GUI environment you can access help via F1 where two options are the cookbook and the "Your First Program" tutorial.

This same documentation available in the environment is also available online[1].

[1] http://docs.factorcode.org/content/article-first-program.htm...

I think that's true. Forth is so called "ultimate low-level language".