Eduardo Cavazos | 6 Sep 23:15

Binding from the stack

Hello,

I've been programming in Factor for a few years now. I guess I'm a slow 
learner because I've just now had a certain eureka moment this morning. I 
even think folks have mentioned this to me before but it didn't click until 
today. The idea I finally groked:

	Locals is an abstraction of the retain stack

Maybe some of you are familiar with User RPL, the programming language of the 
HP48. Folks write some pretty complex stuff in RPL. Guess what's missing from 
User RPL? A retain stack. But what *do* they have? Locals. They use this 
syntax:

	-> a b << a b + >>

In RPL, their "quotations" are delimited using '<<' and '>>'. The above means 
bind 'a' and 'b' to values from the stack and execute the program. They also 
support "algebraic" expressions so the above could be written as:

	-> a b 'a+b'

Now I'm going to throw out a claim:

	Every piece of code which uses '>r' and 'r>' could be more clearly written
	using locals.

I think this is an important fact because from a teachers perspective, it 
means you only need to show a student locals and they don't need to learn 
about the retain stack at all.
(Continue reading)

Slava Pestov | 7 Sep 01:27

Re: Binding from the stack

On Sat, Sep 6, 2008 at 4:15 PM, Eduardo Cavazos
<wayo.cavazos@...> wrote:
>        Locals is an abstraction of the retain stack

Yup.

> Now I'm going to throw out a claim:
>
>        Every piece of code which uses '>r' and 'r>' could be more clearly written
>        using locals.

Are you referring to code that uses >r/r> directly, or code that uses
cleave combinators, compose, fry and other things built on top of
>r/r> ?

>        *Any* abstraction which was invented to overcome complex retain stack
>        manipulation can be replaced by the use of locals.

In theory, yes. In practice, will the code be cleaner?

Slava

-------------------------------------------------------------------------
This SF.Net email is sponsored by the Moblin Your Move Developer's challenge
Build the coolest Linux based applications with Moblin SDK & win great prizes
Grand prize is a trip for two to an Open Source event anywhere in the world
http://moblin-contest.org/redirect.php?banner_id=100&url=/

Gmane