News for hackers. Stuff that matters.
Re:Factor implementation in 150 lines of Python by kssreeram on Wednesday December 08, 2010 @12:55AM (#1982061)
The title is misleading. It's an implementation of _a_ concatenative language. It's not Factor.
Re:Factor implementation in 150 lines of Python by jdp on Wednesday December 08, 2010 @03:32AM (#1982295)
You're right, I should have introduced it as a subset of Factor. Factor is much more full-featured, but the syntax of the language is in line with Factor's.
Re:Factor implementation in 150 lines of Python by thesz on Wednesday December 08, 2010 @05:40AM (#1982461)
By implementing a variant of Joy concatenative language in Haskell I learnt monads:

http://tech.groups.yahoo.com/group/concatenative/message/471

I checked it up, it also counts at 150 lines of code, including comments and headers. A strange coincidence, I say.

Re:Factor implementation in 150 lines of Python by ntoshev on Wednesday December 08, 2010 @04:26AM (#1982366)
I am aware of the role of the stack in concatenative languages, but what about the retain parameter in the primitive functions? In most of them it is unused...
Re:Factor implementation in 150 lines of Python by jdp on Wednesday December 08, 2010 @04:53AM (#1982402)
The retain parameter is a secondary stack for temporarily storing things from the data stack. It can be manipulated through the `r>` and `>r` words. The former puts the top of the data stack at the top of the retain, and one does the opposite. The `dip` word isn't a primitive in this implementation, but instead is defined as `swap >r call r>`, which saves the value underneath the top value of the stack (which is expected to be a quotation), calls the quotation, and then restores the retained value to the top of the data stack.
Re:Factor implementation in 150 lines of Python by thesz on Wednesday December 08, 2010 @08:14AM (#1982782)
Two stacks are halves of Turing machine tapes: http://en.wikipedia.org/wiki/Stack_machine#Stacks_in_automat...
Re:Factor implementation in 150 lines of Python by ntoshev on Wednesday December 08, 2010 @08:53AM (#1982909)
Does this mean that the language would not be Turing-complete without the second stack?

What is the retain stack typically used for?

Re:Factor implementation in 150 lines of Python by thesz on Wednesday December 08, 2010 @04:49PM (#1984764)
This precisely mean that language without second stack (more or less) is not Turing complete.

But, if your language can store lists on a stack, you're Turing complete again! One example if a Joy language, where you can have quotation on stack, assemble them and decompose back.

Most of the time you store there various intermediate values. It depends on the nature of language. For example, Forth variants often store loop counters on retain stack.

Re:Factor implementation in 150 lines of Python by JulianMorrison on Wednesday December 08, 2010 @06:58AM (#1982609)
This clearly derives from Forth's (much lower level) manipulation of the return stack as transient storage (with the same operators).
Re:Factor implementation in 150 lines of Python by Locke1689 on Wednesday December 08, 2010 @04:48AM (#1982390)
Just as an FYI, one of the properties of Factor and stack-based languages is that they are extremely simple -- almost trivial -- to implement an interpreter for. The main benefit of this interpreter would probably be to simply describe the syntax and evaluation structure of a stack-based language to one unfamiliar with the concept and not, instead, as a technical case study.