Hello,

Here's an example of putting a quotation in a ro local. The resulting 
quotation compiles. The local expression itself is:

        [| a | [ a call ] ]

This takes a quotation from the stack, and returns a new quotation, which when 
called, just calls the original quotation. The generated quotation can be 
compiled; here I'll pass in the simple quotation [ 0 ], which just returns 0.

( scratchpad ) [ 0 ] [| a | [ a call ] ] call compile-quot
Compiling G:197812
----------
G:197812
----------

If you change the local to be rw, by appending a ! to the local name, the 
generated quotation doesn't compile:

( scratchpad ) [ 0 ] [| a! | [ a call ] ] call compile-quot
Compiling G:197813
Word: G:197813
Literal value expected
Nesting: { G:197813 }

Let's look at the generated code for the ro version:

( scratchpad ) [ 0 ] [| a | [ a call ] ] call
----------
[ [ 0 ] >r r> dup swap >r r> drop call ]
----------

As we've discussed before, the generated code is in a naive form and there are 
some 'no op' code sequences in it. We can remove any occurance of ">r r>", 
replace "dup swap" with just "dup", and remove "dup drop":

        [ [ 0 ] call ]

The compiler is happy with that quot. (Also note that the simplified version 
is identical to the body of the original local expression with a replaced by 
the quot!)

Now let's look at the generated code for the rw version:

( scratchpad ) [ 0 ] [| a! | [ a call ] ] call
----------
[ { [ 0 ] } >r r> dup swap >r first r> drop call ]
----------

And simplify it:

        [ { [ 0 ] } dup >r first r> drop call ]

The compiler is not happy with this quot. Ah compiler!!! You're so close! The 
quot you need to call is RIGHT THERE! :-)

My question for slava is, do you think the compiler will someday be able to 
handle quotations like that? It seems like it should be possible; we have a 
literal quot inside a literal array and the call is operating on that quot 
value. If the compiler could handle this, then there's no reason why we can't 
also teach the compiler about stored quotations in... tuples, vectors, etc. 
This would give us all sorts of new ways to store and recall quotations; 
higher-order heaven.

Ed

-------------------------------------------------------------------------
This SF.net email is sponsored by: Splunk Inc.
Still grepping through log files to find problems?  Stop.
Now Search log events and configuration files using AJAX and a browser.
Download your FREE copy of Splunk now >>  http://get.splunk.com/
_______________________________________________
Factor-talk mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/factor-talk

Reply via email to