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

World: r3wp

[Core] Discuss core issues

Henrik
9-Apr-2008
[10189x2]
>> a: [(i)]
== [(i)]
>> repeat i 5 [print i compose a]
1
** Script Error: i has no value
** Where: halt-view
** Near: i

>> repeat i 5 [print i compose load mold/all a]
1
** Script Error: i has no value
** Where: halt-view
** Near: i


Is that correct? I'm obviously missing something, but I don't know 
what. Does COMPOSE not work inside the REPEAT context?

>> b: ['i]
== ['i]
>> repeat i 5 [print i reduce b]
1
2
3
4
5
== [i]

This works as expected.
solved it:

>> a: [(i)]
>> repeat i 5 [print i compose bind a 'i]
1
2
3
4
5
== [5]


I assumed that LOAD MOLD/ALL would kill the existing bindings and 
re-bind it to whatever context it was being run in. I guess it doesn't 
do that.
Anton
9-Apr-2008
[10191]
I think LOAD just binds to global context.
Henrik
9-Apr-2008
[10192]
yes, I think it does.
Geomol
9-Apr-2008
[10193]
:-/ Yeah, that must be the answer. Do we need a /local (or something) 
refinement for LOAD?
Anton
9-Apr-2008
[10194x2]
c: context [print: "local" w: load "print"]
type? get c/w  ; == native!
Geomol, why add another refinement when you can just use BIND, which 
allows you to bind it anywhere ?
Geomol
9-Apr-2008
[10196x2]
Yes, LOAD is native. !? What's the point?
Anton, right. Good point.
Anton
9-Apr-2008
[10198]
And in any case, what does "local" mean ? How would LOAD determine 
what is meant by local ? The block it's in does not have any associated 
context.
Geomol
9-Apr-2008
[10199]
Ah, let me reconsider the native! thing. Was thinking in terms of 
blocks. It's an object! of course. ...
Anton
9-Apr-2008
[10200]
Only the words in the block know what context they're bound to.
Geomol
9-Apr-2008
[10201x2]
>> probe get a/w
native
Heh! :-) I'm not so sharp today.
Anton
9-Apr-2008
[10203]
In the code above, I make an object which has a local word 'print 
(with a local value "local"), and another word 'w whose value is 
LOADed from the string "print" (which becomes the word 'print). This 
new word is bound to the global context. Where else could it be bound 
? The word 'load in the block above is not bound to the context I 
made, it retains its global binding (which is why it actually does 
what we expect it to).
Geomol
9-Apr-2008
[10204]
I was doing this:
a: context [w: load "print"]
get a/w


Same thing. I understand you now, Anton. The words know, what context 
they're bound to. So it should all just be sorted out with BIND. 
And BIND can be confusing (at leat I find it confusing now and then).
Anton
9-Apr-2008
[10205]
Yes, the "invisible links" of bind can be confusing.
Geomol
9-Apr-2008
[10206]
Thanks for the explanation! :-)
Anton
9-Apr-2008
[10207]
np
Geomol
9-Apr-2008
[10208x4]
And we can make our own LOAD to do, what we want: :-)


>> c: context [print: "local" load: func [w] [bind to block! w self 
w] w: load "print"]
>> type? c/w
== string!
>> c/w
== "print"
Argh, that should return "local", shouldn't it? :-D
BIND is hard! Period! ;-)
This does it (I think):

>> c: context [print: "local" load: func [w] [first reduce bind to 
block! w self] w: load "print"]                                  
                           
>> c/w
== "local"
[unknown: 5]
9-Apr-2008
[10212x4]
Maybe someone will know if this is possible.  I want to be able to 
set a value when parsing outside a function to a local value in context 
of a funciton.  I can do this with an object but want to know how 
to do it with a function.  Here is the object method:
a: [1]
b:  context [c: none]
parse a compose [set (in b 'c) integer!]
>> b/c
== 1
I want to be able to instead of having b as an object be able to 
have b as:    b: func [val /local s][print val + s]   where I want 
to set 's from the parsing.
Geomol
9-Apr-2008
[10216]
I found, that making my own version of LOAD in a context in another 
way worked:

>> c: context [print: "local" my-load: :load w: my-load print]
>> c/w
== local
>> type? c/w
== word!

But it doesn't work as Henrik would like in a REPEAT block:

>> a: [(i)]
== [(i)]
>> repeat i 5 [print i my-load: :load compose my-load mold/all a]
1
** Script Error: i has no value
btiffin
9-Apr-2008
[10217]
Paul; you've read through the Ladislav articles?  tfunc and lfunc 
and his Bindology paper?   http://www.fm.tul.cz/~ladislav/rebol/
[unknown: 5]
9-Apr-2008
[10218]
I have read a lot of his stuff but not sure I ever read this.  I'll 
take a look into it.  Thanks Brian.
Anton
10-Apr-2008
[10219x2]
Paul, you need to do something like this:
	parse a compose [set (first second :f ) integer!]

where f is a function, second :f gives you the function's body, and 
FIRST picks a local word which just happens to be in first position 
in the body block. You will have to change FIRST to whatever navigates 
to a local word.
Example, given a function:
	f: func [var][
		print var: 10
	]

then you will navigate to the 'var: set-word in the function body 
like so:
	second second :f
because 'var: is in second position, after the 'print word.

(it doesn't matter that it's a set-word and not a word, you can still 
set it and bind to it, etc)

We can test this:
	set second second :f 20
	get second second :f
	; == 20
	?? f
	f: func [var][
		print var: 10
	]

Notice the 10 value is still the same (we didn't touch it.) But we 
know the 'var: set-word is 20 thanks to our setting it above. If 
the function is now evaluated it will not stay that way, obviously.
BrianH
11-Apr-2008
[10221x3]
Keep in mind that the words local to a function's context are only 
really valid during the execution of the function. When referred 
to from outside the function, their bindings are valid but their 
assigned values are not, and will be overridden on next run.
This is even more the case in R3.
Much of the code in Ladislav's article wouldn't work in R3, because 
of the changes in functions and the different reflective accessors.
[unknown: 5]
11-Apr-2008
[10224]
thanks Anton, I had tried that but I want to do something a bit differently. 
 I want to set a functions /local word instead of its arguments.
Anton
12-Apr-2008
[10225]
It's the same method; all of the words (including the /local refinement) 
in the following function spec are local to the function's context:

	func [arg /local var]
[unknown: 5]
12-Apr-2008
[10226x2]
I tried it Anton and it didn't work.  I'm trying from within the 
same function.
I'm going to investigate other possible ways of doing it wonce I 
get a chance.
Anton
12-Apr-2008
[10228]
Ok, but did you navigate to the local word properly ?
[unknown: 5]
12-Apr-2008
[10229]
Yes, but what I think the problem is that I need to do the setting 
of the word from within.
Anton
12-Apr-2008
[10230]
Perhaps you can show us the actual function, and the code which tries 
to set the word. I know this is entirely possible, and especially 
so if you are the author of the function involved.
Henrik
17-Apr-2008
[10231]
I'm debugging my debugger right now. For some reason it does not 
log certain lines of debug information. The method I use is:

write/binary/append %debug-file.r string


By probing it in console, I get the correct output, but the same 
lines are always missing in the disk version. Would there be any 
time this write would not occur?
[unknown: 5]
17-Apr-2008
[10232]
Maybe the write is occurring but the 'string is not containing anything?
Henrik
17-Apr-2008
[10233x3]
I will check again with another probe
those lines are just not saved
write/binary/append %debug-file.r probe string

will print the string in the console, but it's not saved
[unknown: 5]
17-Apr-2008
[10236]
You confirmed that 'string contains data and not just ""
Henrik
17-Apr-2008
[10237x2]
this can't be... there _has_ to be something else wrong :-)
yes, but I have to check some other things now too