Re: [Factor-talk] What exactly is the retain stack?

2014-05-15 Thread Jon Purdy
> In the current state of Kitten:

Oop, correction: this is not Kitten syntax. I had been writing in
Kitten but decided against it, then forgot to update the text. Current
Kitten would be:

def dip {.r, .s, a}(.r a (.r -> .s) -> .s a): …

But this is a Factor mailing list. ;)

--
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] What exactly is the retain stack?

2014-05-15 Thread Jon Purdy
> Is that it's only use? Then why? dip can easily be formulated using
> non-retain stack using primitives:
>
> For example: "a" "b" "c" [ append ] dip -> "a" "b" "c" -rot append swap
>

That implementation assumes the quotation takes two operands and
produces one result, which is not always the case. More generally, the
functional argument of “dip” is not really supposed to be able to
touch the argument it’s operating under. If you don’t have types or a
stack checker enforcing this, the formulations with a retain stack or
dynamically composing quotations are safe by construction, but the
“-rot” version is not. Consider “[ 3drop ] dip” or “[ append dup ]
dip”.

You can easily describe the constraint with a type dependent on the
arity of the argument type, though. In the current state of Kitten:

dip :: ∀R S a. (R a (R → S) → S a)

--
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] What exactly is the retain stack?

2014-05-15 Thread Björn Lindqvist
Hi!

Is that it's only use? Then why? dip can easily be formulated using
non-retain stack using primitives:

For example: "a" "b" "c" [ append ] dip -> "a" "b" "c" -rot append swap


2014-05-15 22:49 GMT+02:00 Slava Pestov :
> Hi Bjorn,
>
> The retain stack is used to implement the 'dip' combinator.
>
> Slava
>
>
> On Thu, May 15, 2014 at 1:46 PM, Björn Lindqvist  wrote:
>>
>> Hi everyone,
>>
>> I've been walking around in Factors VM for a while and there is a lot
>> of usages and references to "the retain stack." But I can't for my
>> life figure out what its purpose is or why anyone ever would want one
>> when there is a perfectly good data stack already available.
>>
>> I only found these two posts by Slava Pestov about it:
>>
>>
>> http://article.gmane.org/gmane.comp.lang.factor.general/1931/match=retain+stack
>>
>> http://factor-language.blogspot.se/2010/07/overhauling-factors-c-library-interface.html
>>
>> "In the future, I intend on using GC maps at call sites of Factor
>> words as well, instead of spilling temporary values to the retain
>> stack; then I can eliminate the retain stack altogether, freeing up a
>> register. After this is done the data stack will only be used to pass
>> parameters between words, and not to store temporaries within a word.
>> This will allow more values to be unboxed in more situations, and it
>> will improve accuracy of compiler analyses."
>>
>> So the retain stack is useless? Freeing up a whole register sounds
>> like it should be great for performance, at least on 32 bit x86.
>>
>>
>> --
>> mvh/best regards Björn Lindqvist
>>
>>
>> --
>> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
>> Instantly run your Selenium tests across 300+ browser/OS combos.
>> Get unparalleled scalability from the best Selenium testing platform
>> available
>> Simple to use. Nothing to install. Get started now for free."
>> http://p.sf.net/sfu/SauceLabs
>> ___
>> Factor-talk mailing list
>> Factor-talk@lists.sourceforge.net
>> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
>
>
> --
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform
> available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>



-- 
mvh/best regards Björn Lindqvist

--
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] What exactly is the retain stack?

2014-05-15 Thread Jon Purdy
> So the retain stack is useless? Freeing up a whole register sounds
> like it should be great for performance, at least on 32 bit x86.

You can make a complete stack-based concatenative language with only
one stack. But some combinators are implemented more efficiently when
you have scratch space to use.

Here are some pseudocode reductions.

You can implement “dip” as “swap quote cat apply”:

1 2 3 [ + ] dip
1 2 3 [ + ] swap quote cat apply
1 2 [ + ] 3 quote cat apply
1 2 [ + ] [ 3 ] cat apply
1 2 [ + 3 ] apply
3 3

Or you can implement it as “swap retain apply restore”:

1 2 3 [ + ] dip
1 2 3 [ + ] swap retain apply restore
1 2 [ + ] 3 retain apply restore
1 2 [ + ] apply restore
3 restore
3 3

In the former case, you had to allocate a quotation and concatenate
two quotations. These can of course be optimised out, but a retain
stack has a more efficient naïve operational semantics, and having a
“spare” stack for temporary use makes some code a lot nicer without
needing to go as far as introducing local variables.

--
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


Re: [Factor-talk] What exactly is the retain stack?

2014-05-15 Thread Slava Pestov
Hi Bjorn,

The retain stack is used to implement the 'dip' combinator.

Slava


On Thu, May 15, 2014 at 1:46 PM, Björn Lindqvist  wrote:

> Hi everyone,
>
> I've been walking around in Factors VM for a while and there is a lot
> of usages and references to "the retain stack." But I can't for my
> life figure out what its purpose is or why anyone ever would want one
> when there is a perfectly good data stack already available.
>
> I only found these two posts by Slava Pestov about it:
>
>
> http://article.gmane.org/gmane.comp.lang.factor.general/1931/match=retain+stack
>
> http://factor-language.blogspot.se/2010/07/overhauling-factors-c-library-interface.html
>
> "In the future, I intend on using GC maps at call sites of Factor
> words as well, instead of spilling temporary values to the retain
> stack; then I can eliminate the retain stack altogether, freeing up a
> register. After this is done the data stack will only be used to pass
> parameters between words, and not to store temporaries within a word.
> This will allow more values to be unboxed in more situations, and it
> will improve accuracy of compiler analyses."
>
> So the retain stack is useless? Freeing up a whole register sounds
> like it should be great for performance, at least on 32 bit x86.
>
>
> --
> mvh/best regards Björn Lindqvist
>
>
> --
> "Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
> Instantly run your Selenium tests across 300+ browser/OS combos.
> Get unparalleled scalability from the best Selenium testing platform
> available
> Simple to use. Nothing to install. Get started now for free."
> http://p.sf.net/sfu/SauceLabs
> ___
> Factor-talk mailing list
> Factor-talk@lists.sourceforge.net
> https://lists.sourceforge.net/lists/listinfo/factor-talk
>
--
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk


[Factor-talk] What exactly is the retain stack?

2014-05-15 Thread Björn Lindqvist
Hi everyone,

I've been walking around in Factors VM for a while and there is a lot
of usages and references to "the retain stack." But I can't for my
life figure out what its purpose is or why anyone ever would want one
when there is a perfectly good data stack already available.

I only found these two posts by Slava Pestov about it:

http://article.gmane.org/gmane.comp.lang.factor.general/1931/match=retain+stack
http://factor-language.blogspot.se/2010/07/overhauling-factors-c-library-interface.html

"In the future, I intend on using GC maps at call sites of Factor
words as well, instead of spilling temporary values to the retain
stack; then I can eliminate the retain stack altogether, freeing up a
register. After this is done the data stack will only be used to pass
parameters between words, and not to store temporaries within a word.
This will allow more values to be unboxed in more situations, and it
will improve accuracy of compiler analyses."

So the retain stack is useless? Freeing up a whole register sounds
like it should be great for performance, at least on 32 bit x86.


-- 
mvh/best regards Björn Lindqvist

--
"Accelerate Dev Cycles with Automated Cross-Browser Testing - For FREE
Instantly run your Selenium tests across 300+ browser/OS combos.
Get unparalleled scalability from the best Selenium testing platform available
Simple to use. Nothing to install. Get started now for free."
http://p.sf.net/sfu/SauceLabs
___
Factor-talk mailing list
Factor-talk@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/factor-talk