World: r4wp
[Rebol School] REBOL School
older newer | first last |
Henrik 12-Oct-2012 [1369x2] | hmm... I clearly remember it being not copied, but I seem to be wrong about that. |
aha, it's the case for contexts inside contexts. | |
Ladislav 12-Oct-2012 [1371] | so is there any reason for using copy at the top level (global assignments) with binding to literals? - certainly, there are reasons. See these two examples: ; example #1 repeat i 2 [ a: [] append a i print mold a ] and ; example #2 repeat i 2 [ a: copy [] append a i print mold a ] |
MarcS 12-Oct-2012 [1372] | ladislav: i meant when not binding inside a block |
Ladislav 12-Oct-2012 [1373x2] | What does it have in common with "binding"? |
BTW, the examples both use binding in a way | |
MarcS 12-Oct-2012 [1375] | i just mean assigment |
Ladislav 12-Oct-2012 [1376] | actually, you cannot use assignment "outside of a block" in REBOL |
MarcS 12-Oct-2012 [1377] | henrik: but - http://pastebin.com/3s30AxY4 |
Ladislav 12-Oct-2012 [1378] | (there is always a block somewhere) |
MarcS 12-Oct-2012 [1379x2] | ladislav: sorry, i'm using terminology sloppily |
i guess: assigning to a word in the global (system?) context | |
Ladislav 12-Oct-2012 [1381x2] | that is what both the examples above do |
(the 'A word is not local) | |
MarcS 12-Oct-2012 [1383] | yes, but the other part was: not inside a(nother literal) block |
Ladislav 12-Oct-2012 [1384] | That cannot be done. |
MarcS 12-Oct-2012 [1385] | okay, not inside another explicit literal block |
Henrik 12-Oct-2012 [1386] | MarcS, yes, now you are in X and Y pointing at the same context. |
Ladislav 12-Oct-2012 [1387] | In REBOL, there is always a block somewhere |
MarcS 12-Oct-2012 [1388x2] | henrik: oh, right |
ladislav: yes, okay - i'm just saying that i understand the pitfalls of not copying when you're re-entering a block (be it a loop, function, etc. body) | |
Ladislav 12-Oct-2012 [1390] | for example, something like: do "a: []" first "converts" the string to a block |
MarcS 12-Oct-2012 [1391] | but where i'm assigning to a "global" (which i understand is just another context) outside of an explicit (one i write myself) literal block, are there pitfalls in not using copy |
Henrik 12-Oct-2012 [1392] | yes, if you are running the same script several times in the same console. |
MarcS 12-Oct-2012 [1393x4] | also, i get that x: [ append [] 1 ] then 'do x do x' differs from x: [ append copy [] 1 ] 'do x do x' |
henrik: so if i load the script, then do it, rather than doing the file? | |
makes sense, hadn't considered that | |
so: best practice is to consider everything to be inside a block, and hence copy even toplevel literals? | |
Henrik 12-Oct-2012 [1397] | not even needed. you may DO the same script several times for the same effect. |
Ladislav 12-Oct-2012 [1398x2] | in the a: [] it is so, that if you do not "reuse" the literal block then it does not matter whether you copy or not |
by "reuse" I mean if you do not keep the code and reevaluate it once again | |
MarcS 12-Oct-2012 [1400x4] | right |
but of course, | |
>> x: load %foo.r == [ foo: [] append foo 1 ] >> do x == [1] >> do x == [1 1] >> foo == [1 1] | |
which was henrik's point | |
Henrik 12-Oct-2012 [1404] | actually not |
MarcS 12-Oct-2012 [1405] | oh! |
Ladislav 12-Oct-2012 [1406] | and by "keep the code" I mean "keep the code as a block", if you keep it as a string then it does not matter |
Henrik 12-Oct-2012 [1407] | do %foo.r do %foo.r will produce something you may not intend. |
MarcS 12-Oct-2012 [1408x4] | well, if there are side effects, sure |
but with the above, i get the anticipated result, | |
>> do %foo.r Script: "Untitled" (none) == [1] >> do %foo.r Script: "Untitled" (none) == [1] >> foo == [1] | |
ladislav: yep, understood | |
Henrik 12-Oct-2012 [1412] | sorry, MarcS. you are right again. I better take a nap... |
MarcS 12-Oct-2012 [1413x2] | so to get back to pitfall vs. stylistic - i notice that carl's scripts (makedoc, blog) tend not to copy 'global' literals |
whereas, for example, the source for vanilla does | |
Ladislav 12-Oct-2012 [1415] | However, when writing something like: a: [] into a file, you may not be totally sure that somebody does not LOAD your code and try to evaluate it twice.... |
MarcS 12-Oct-2012 [1416x2] | yep |
so unless you're certain (!) that that won't occur, better to be safe and copy? | |
Ladislav 12-Oct-2012 [1418] | Yes, copy looks safer.... |
older newer | first last |