« first day (1454 days earlier)      last day (2326 days later) » 

2:35 AM
Anyone have news about Red 0.5.0 ETA?
 
 
1 hour later…
3:39 AM
Is this the intended behaviour of 'FUNCTION in Rebol3

>>i: 1
>> i: 1
f1: function[][f2: func [i][i: 1234] f2 i]
f3: function[][o: make object! [i: 1234] i]
print ["f1 returns " f1]
print ["f3 returns " f3]
@RebolBot

i: 1
f1: function[][f2: func [i][i: 1234] f2 i]
f3: function[][o: make object! [i: 1234] i]
print ["f1 returns " f1]
print ["f3 returns " f3]
 
; Brought to you by: try.rebol.nl
f1 returns  1234
f3 returns  none
 
 
1 hour later…
4:54 AM
The answer is, of course, this is the expected behaviour.
 
 
2 hours later…
6:36 AM
The value for f1 I expected, the second one I do not expect. I expected 1 there, taking the value for i from the global context (or it should have been declared as /local ) I am now curious what was the value for i that was used as argument to be processes by function f2?
 
7:34 AM
This is an improvement on the prior example that demonstrated the behaviour of FUNCTION a little better:
@RebolBot

i: 1
f1: function[][f2: func [i][i: 1234] i]
f3: function[][o: make object! [i: 1234] i]
print ["f1 returns " f1]
print ["f3 returns " f3]
 
; Brought to you by: try.rebol.nl
f1 returns  none
f3 returns  none
 
Perhaps this will show some light on which i was used?
@RebolBot

f1: function[][f2: func [i][i: 1234] f2 i]
probe :f1
 
; Brought to you by: try.rebol.nl
make function! [[
    /local f2 i
][f2: func [i] [i: 1234] f2 i]]
== make function! [[
    /local f2 i
][f2: func [i] [i: 1234] f2 i]]
 
8:11 AM
@RebolBot

f3: function[][o: make object! [i: 1234] i]
probe :f3
 
; Brought to you by: try.rebol.nl
make function! [[
    /local o i
][o: make object! [i: 1234] i]]
== make function! [[
    /local o i
][o: make object! [i: 1234] i]]
 
@RebolBot

f1: function[][f2: func [i][i: 1234] probe f2 f2 i]
probe :f1
 
; Brought to you by: try.rebol.nl
make function! [[
    /local f2 i
][f2: func [i] [i: 1234] probe f2 f2 i]]
== make function! [[
    /local f2 i
][f2: func [i] [i: 1234] probe f2 f2 i]]
 
@RebolBot

f1: function[][f2: func [i][i: 1234] probe f2 f2 i]
f1
 
; Brought to you by: try.rebol.nl
1234
== 1234
 
8:17 AM
@RebolBot

f1: function[][f2: func [i][print i i: 1234] f2 i ]
f1
 
; Brought to you by: try.rebol.nl
none
== 1234
 
ok it's local, that's it. :-) Now I expect that too ;-)
 
 
1 hour later…
9:41 AM
@kealist we can talk any mumbo-jumbo here, but for me it does not mean much anyway. I know, that by definition, the result is correct. But whoever came with the ill idea of mixing code-as-data aproach to actually simplify simple block scanning for set words, while the result is the code anyway, should be obliged to cover that in docs at least ...
I wonder, how expensive would be function reimplementation using parse, to find nested function or object definitions and make locals at the levels, where they would be expected kind of - more naturally ...
 
 
4 hours later…
1:47 PM
@pekr Whether it is expensive or not would not make it useful
 
2:27 PM
@pekr It's technically impossible.
 
2:51 PM
Just wondering why? Because the functionality is based upon the 'collect-words, which is a native and hence can't be further tweaked? The parser would look for set-word followed by make function! or make object! or for a setword followed by function and context/object? Is that too naive? :-)
 
3:30 PM
@pekr I fear it is :)
In current Rebol, you cannot in general statically determine if a given piece of code constructs a function or an object.
f: func [] [g: func [] []]
There is no make function! anywhere inside the body of F.
foobar: :func
f: func [] [g: foobar [] []]
Now there isn't even a FUNC inside the body anymore. How do you know that FOOBAR actually constructs a function, which semantically makes the second block after FOOBAR code to be executed in a different scope -- thus needing special /LOCAL treatment?
You can only know that in general, once you are actually executing the code. When you start executing FOOBAR is only when you'll find out that FOOBAR constructs a function.
But if you are trying to write the locals-finding tool you want, that's too late. You need that information much earlier, when you are far far away from this particular execution.
f: x [] [g: y [] []]
 
Yes, that is the only reason which came to my mind, but then - how often do you reassign function names? I know it does not matter, because once that happens, the result would be unpredictable. You can't even pre-check on the type of the value, as it is not code yet, just data
 
Exactly. You just simply cannot correctly write the suggested locals-gathering tool in the current language.
 
I generally wonder about the scenario, where collect-words/deep inside the function source is useful? I mean - the deep aspect?
Hmm, once again wrong assumption - for block values it would be usefull
 
f: function [x] [either x < 123 [t: 42] [t: 99] t * t]
That's useful for very simple scenarios already :)
Deep-collecting correctly catches T as local, in the above example.
 
I was just shocked by just hitting t in console :-)
it reports missing file. Did not know t is a shortcut for some testing :-)
 
3:46 PM
Yeah, one of the debugging left-overs that haven't yet been cleaned up :)
 
what is function/with object-value good for?
will it collect words into the object?
hmm, apparently so ...
@earl - to just not give up so easily - you stated, that you can't check on 'foobar above being function. But you can - type? :foobar == function! Would it cover the needs, or still would I miss on some cases?
 
@pekr What i have found is that Function does collect the words from an object defined inside a function but it doesn't hijack them. You just get two words with the same name, one local to the function and one local to the object:
@RebolBot

i: 1
f: function [] [
o: make object! [i: 3]
print ["i is " i]
print ["o/i is " o/i]
]
f
 
; Brought to you by: try.rebol.nl
i is  none
o/i is  3
 
4:02 PM
It is exactly the same behaviour as if you wrote:
@RebolBot

f: func [/local i o] [
o: make object! [i: 3]
print ["i is " i]
print ["o/i is " o/i]
]
f
 
; Brought to you by: try.rebol.nl
i is  none
o/i is  3
 
/local words are set to none?
 
Yes if you just declare them (/local) and don't set them.
 
4:25 PM
@pekr type? == function! just tells you that it is a function. It does not tell you, what this function does. In particular, it doesn't tell you, that it is a function that creates functions.
 

« first day (1454 days earlier)      last day (2326 days later) »