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

World: r3wp

[View] discuss view related issues

Anton
6-Oct-2006
[5701]
You probably don't spend enough time playing with function creation 
:)
Pekr
6-Oct-2006
[5702x2]
I would expect pointer to the block, not to some concrete position 
inside that block
I don't, never :-)
Anton
6-Oct-2006
[5704x3]
Here's the "copy, paste and bind" way:
view layout [
	field feel [
		engage: func [face act event] bind bind [
			switch act [
				down [

     either equal? face focal-face [unlight-text] [focus/no-show face]
					caret: offset-to-caret face event/offset
					show face
				]
				over [
					if not-equal? caret offset-to-caret face event/offset [
						if not highlight-start [highlight-start: caret]
						highlight-end: caret: offset-to-caret face event/offset
						show face
					]
				]

    key [if event/key <> #"^M" [edit-text face event get in face 'action]]
			]		
		] system/view ctx-text
	]
]
Notice we are binding the code first to system/view, then to ctx-text. 
(Then it is also bound to the function context.)
Pekr
6-Oct-2006
[5707]
why is there a difference?

>> body: [print "hello"]
== [print "hello"]
>> f: func [] body
>> same? body second :f
== false
>> probe second :f
[print "hello"]
== [print "hello"]
Anton
6-Oct-2006
[5708x2]
Obviously FUNC copies the body block.
Why is that good ? Probably because that's what people expect most 
of the time.
Pekr
6-Oct-2006
[5710x2]
ah, ok, thanks
to your double bind example - what does it do internally? you first 
bind the block to system/View - what happens in that context, and 
what happens in next context - ctx-text?
Anton
6-Oct-2006
[5712x2]
When you bind a block, eg:
	bind [all my words] some-context

an attempt is made to bind each of the words in the block to the 
specified context.

If the context contains the word in question, then the word is bound, 
otherwise the word is left with the same binding as it had before.
So if I
	bind [caret: "hello"] system/view

then the first word in the block gets the same context as this word:
	in system/view 'caret

and thus it also references the same value, because it is the context 
which determines what value a word has.
Pekr
6-Oct-2006
[5714x2]
what does it mean the word it bound? it is registered somewhere at 
memory, in some word table, as belonging to that new context, or 
it just is assigned particular value of tha word in the context we 
are binding it to?
now I seem to understand, just did some small example myself:

block: [print a]
do block ; 'a is not known
my-context: context [a: 1]
do bind block my-context ; now 1 is printed
Anton
6-Oct-2006
[5716]
And note that it works also for sub-blocks:
	do bind [print [a]] context [a: 1]
Pekr
6-Oct-2006
[5717]
I don't use bind, as it is more guru stuff, but is the bind as it 
is sufficient for you? e.g. wouldn't you prefer bind not binding 
for sub-blocks by default, and e.g. having bind/deep for such thing?
Anton
6-Oct-2006
[5718]
Yes, I would prefer more options for binding particular parts of 
a block "surgically".
Pekr
6-Oct-2006
[5719]
hehe, I can rebind whatever, even functions? do bind [print a] context 
[a: 1 print: :probe]
Ladislav
6-Oct-2006
[5720]
yes, you can
Pekr
6-Oct-2006
[5721]
hmm, but maybe mine is not example of binding anyway, it just simply 
created alias, no?
Ladislav
6-Oct-2006
[5722]
I would prefer more options for binding particular parts of a block 

surgically"" - that is possible e.g. using my BUILD dialect or other 
instruments...
Anton
6-Oct-2006
[5723x2]
It *is* an example.
That's true, Ladislav, I was just about to write that it is possible 
to write higher-level functions.
Pekr
6-Oct-2006
[5725]
yes, it seems so ... print: :probe is known only in a newly created 
context, or so it seems ...
Ladislav
6-Oct-2006
[5726]
right, Pekr
Pekr
6-Oct-2006
[5727]
'bind offers whole level of interesting low level (or high level, 
it depends how you look at it :-) magic ...
Ladislav
6-Oct-2006
[5728]
right again
Pekr
6-Oct-2006
[5729]
you can "borrow" your values here or there ...
Ladislav
6-Oct-2006
[5730x2]
actually, you "borrow" variables, when using BIND
(which is almost the same in many cases)
Pekr
6-Oct-2006
[5732]
and when such variable "points to" some other context, you get there 
too with newly binded word? Well, that is interesting also from security 
pov - we have powerfull instrument on one hand, but we have to be 
carefull on the other hand ...
Ladislav
6-Oct-2006
[5733]
yes, that is why REBOL modules are hard to implement
Pekr
6-Oct-2006
[5734]
one question - can we save and send some context, with all its bindings, 
to some other machine, load it there, and theoretically expect that 
such rebol got all identical environment?
Ladislav
6-Oct-2006
[5735]
no
Pekr
6-Oct-2006
[5736]
that could easily mean copying all internal state of particular rebol 
process, right? :-) I wonder is some language makes such a "reflectivity" 
(probably improper word) possible ...
Anton
6-Oct-2006
[5737]
Of course, enter Jaime...
Pekr
6-Oct-2006
[5738]
ah, so Scheme?
Ladislav
6-Oct-2006
[5739x2]
Confusion for Pekr:

    f: func [x] [x]
    g: func [x] [x]
    var1: first second :f
    var2: first second :g
    bind second :f var2
    bind second :g var1
    f 1
    g 2
    f 3
    g 4
what a mess, isn't it?
Pekr
6-Oct-2006
[5741]
yes, it is :-)
Anton
6-Oct-2006
[5742]
Let me guess output: none, none, 1, 2  ?
Ladislav
6-Oct-2006
[5743]
wrong
Anton
6-Oct-2006
[5744]
Oops.
Ladislav
6-Oct-2006
[5745]
#[unset!] 1 2 3
Anton
6-Oct-2006
[5746]
Ok makes sense.
Pekr
6-Oct-2006
[5747]
fuctnion words remember their values? g 2 results in 1, which is 
there because there was first call to f 1
Anton
6-Oct-2006
[5748]
All words remember their values, unless you rebind the words to a 
different context. Whether a word is in a function body block or 
not doesn't matter.
Ladislav
6-Oct-2006
[5749]
warning! according to the documentation it is possible that in the 
future REBOL function words will be set to #[none!] or something 
else when the function returns
Henrik
8-Oct-2006
[5750]
Anyone have an idea on how INFORM stops the event system and returns 
to the console after pressing a button, allowing it to return a value? 
I've been studying the source of SHOW-POPUP, HIDE-POPUP, INFORM and 
the various POPFACE-FEEL objects, but I can't figure out how it's 
done.