r3wp [groups: 83 posts: 189283]
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

World: r3wp

[World] For discussion of World language

Geomol
7-Dec-2011
[467x3]
@Oldes, fix uploaded. Get world_* again.
And the WITH function would then be:

with: func [obj body] [do compile/at body obj]
I added WITH to rebol.w
Andreas
7-Dec-2011
[470x3]
APPEND not resetting compilation while INSERT resets compilation 
is kind of weird (even though the implementation details leading 
to that decision may be understandable).
A helper function to reset compilation state would probably be helpful.
(Not sure if just calling COMPILE w/o context after modification 
would always be the same. Will have to think about it a bit more, 
but I have a hunch that it is not.)
Geomol
7-Dec-2011
[473]
Yes, I agree to some degree. If APPEND was a native, it would really 
make sense (I guess). We could add a compile to the APPEND mezzanine.


I think, the compilation reset would just be COMPILE. Don't you think?
Andreas
7-Dec-2011
[474x2]
No, I don't think so. The result will differ if something used in 
the block is redefined _after_ the block was modified.
A basic example:
c: copy []
f: func [x] [x]
append c [f 10 20]
;; recompiling c here, do c would == 20
f: func [x y] [x * y]
;; recompiling c here, do c would == 200
Geomol
7-Dec-2011
[476]
That code leads to an error, if c is compiled before f is redefined. 
The error system isn't very good atm., and I'll probably work on 
that next.


I need more experience with World and more examples to say, if a 
compile reset is a good idea.
Andreas
7-Dec-2011
[477x2]
You can also do it the other way round, then it won't lead to an 
error (at the moment, that is :)
So:
c: copy []
f: func [x y] [x]
append c [f 10 20]
;; recompiling c here, do c would == 10
f: func [x] [x]
;; recompiling c here, do c would == 20
Geomol
7-Dec-2011
[479]
Correct. World is not designed to cope with such cases, where words 
changes from functions taking arguments to passive non-function values, 
or if number of arguments changes to a function. To change the behaviour 
of the c block, a compile is needed. So question is, if that compile 
should be executed by a COMPILE call, or if the compile state of 
the block could be reset, and in this case, it would be compiled, 
the next time, it was executed with DO.
Andreas
7-Dec-2011
[480x2]
Currently we have a way to force (re)compilation (with COMPILE), 
but we don't have a way to drop previous compilation.
The example above illustrates that for the most general case, both 
are needed.
Geomol
7-Dec-2011
[482]
Right, and we have to figure out, if we really need that.
Andreas
7-Dec-2011
[483]
I am a strong believer that in cases such as this, whatever is helpful 
internally should also be exposed at the user-level.
Geomol
7-Dec-2011
[484]
My personal view is, that it's sort of bad programming practise to 
change number of arguments to a function in the middle of a program, 
or to change a work from meaning a function or operator to meaning 
e.g. a number.


But I think, it's possible to cope with such strange situations, 
because we have COMPILE.
Andreas
7-Dec-2011
[485x2]
I.e. as INSERT is able to _reset_ compiled state, so should be the 
user.
(Then a mezzanine APPEND could just reset compiled state, and would 
behave identical to INSERT in that aspect.)
Geomol
7-Dec-2011
[487]
Ok. I understand that view. We can reset compiled state now with:

next 'c back 'c
or
c: back next c
Andreas
7-Dec-2011
[488x2]
Ok.
Something similar for functions?
Geomol
7-Dec-2011
[490]
w> f: func [v][v + 1]
w> f 1
== 2
w> compiled? :f
== true
w> f: make function! reduce [pick :f 1 pick :f 2]
w> compiled? :f
== false
Andreas
7-Dec-2011
[491x3]
Hmm, that creates a new function, though, doesn't it?
Are compiled references to values or to names in contexts?
(Well, I can just try that myself :)
Geomol
7-Dec-2011
[494]
And I get a malloc error, when doing that a couple of times. Yes, 
crash. I'll hunt that down.
Andreas
7-Dec-2011
[495]
(Well, I can't, as I get a crash immediately :)
Geomol
7-Dec-2011
[496x2]
:)
World suxx!
Andreas
7-Dec-2011
[498x2]
Nope :)
I agree with the notion that those particular examples illustrate 
bad programming practice. But re-binding words to different values 
(functions) is possible in World, so I believe it should cope nicely 
with that situation.
Steeve
7-Dec-2011
[500]
I don't think you should keep the compiled block in memory when DO 
is used.

Compiled blocks (including the nested ones) should be linked with 
functions only (whe functions are created).

I don't think it would be a real perf problem  because DO is not 
used that much to execute standard code in an app.
Just my opinion though.
Andreas
7-Dec-2011
[501x2]
A possibility, but I think that would on the one hand make implementation 
more complex, and on the other would just introduce more semantic 
corner cases.
Such as a block being shared by a function and a global word.
Steeve
7-Dec-2011
[503]
I agree, the compilation of a function would be more complex (because 
of the nested blocks)
Andreas
7-Dec-2011
[504]
Yes, because compiled code would become an attribute of a function, 
instead of just dangling off a block.
Steeve
7-Dec-2011
[505]
Andreas in R3, nested blocks inside a function can't be shared with 
global words.
The body of a function is deep copied before compilation.
Andreas
7-Dec-2011
[506]
This is the #World channel, though :)
Geomol
7-Dec-2011
[507]
np
Steeve
7-Dec-2011
[508]
Just to say that the R3 model of a function is better than R2 in 
that case
Andreas
7-Dec-2011
[509x3]
Yes, sorry for the snark.
Block sharing can also occur through code blocks passed as parameters, 
though.
t: [...]
f: func [c t f] [either c t f]
f ... t ...
Steeve
7-Dec-2011
[512]
yead but it"s generaly not the blocks which are executed (data only)
Andreas
7-Dec-2011
[513]
But you could of course "localise" those blocks (or at least their 
compiled code) upon function compilation.
Steeve
7-Dec-2011
[514]
that's my point ;-)
Andreas
7-Dec-2011
[515x2]
Mine as well :) That's certainly one of the "weird semantic corner 
cases" I'm talking about :)
But keeping a "compiled block pool" attached to a function is certainly 
a very interesting idea.