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

World: r3wp

[Core] Discuss core issues

Graham
14-Aug-2010
[17783x2]
c: does [
	f/text: "hello" show f
]
view layout [
	f: field
	button "New" [
		context [
			f: g: none
			bind [c] 'g
			view/new layout [
				f: field
				button "test" [c]
			]
		]
	]
]
should be 

bind [c] g

but still doesn't work
sqlab
14-Aug-2010
[17785]
Probably I do not understand the real intention, but I woud do
c: func [f] [
	f/text: "hello" show f
]
and
button "test" [c f]
Gregg
14-Aug-2010
[17786]
Very cool both Nick and Gabriele.
Graham
14-Aug-2010
[17787x3]
My 'c function references about 20 fields so I want to avoid passing 
the field name as parameter
If it can be solved thru binding .. .?
If it can't I'll just copy the function
Gregg
14-Aug-2010
[17790x2]
Graham, you need to bind the function body.
c: does [
	f/text: "hello" show f
]
view layout [
	f: field
	button "New" [
		context [
			f: g: none
			bind second :c 'g
			view/new layout [
				f: field
				button "test" [c]
			]
		]
	]
]
Graham
14-Aug-2010
[17792x5]
thanks .. I'll give it a go
rebol []

c: does [
	f/text: copy "hello" 
	show f
]
view layout [
	f: field
	button "test - c" [ 
		bind second :c 'show
		c 
	]
	button "Clear" [ f/text: copy "" show f ]
	button "New" [
		context [
			f: g: none
			bind second :c 'g
			view/new center-face layout [
				f: field
				button "test" [
					bind second :c 'g
					c
				]
				button "Clear" [ f/text: copy "" show f ]
			]
		]
	]
]
And this works ....
I can open multiple new windows and the 'c function now works on 
its own instance of f field
( the first 'bind outside of the layout is not needed )
Gabriele
15-Aug-2010
[17797x2]
Graham, use the /to refinement of my VID-CONTEXT and pass the object 
to the function
Gregg, your solution either "breaks" C (in the sense that it will 
only work on the new context and not the others) or does not work 
(on versions of REBOL that copy the function code block - I think 
R3 does this)
Graham
15-Aug-2010
[17799x2]
c: does [	f/text: copy "hello" show f ]

view layout [
	f: field
	button "test - c" [	c ]
	button "Clear" [ f/text: copy "" show f ]

	button "New" [
		context [
			f: g: none
			view/new center-face layout vid-context/to [
				f: field
				button "test" [ c ]
				button "Clear" [ f/text: copy "" show f ]
			] 'c
		]
	]
]

Gabriele, this doesn't work for me ...
assuming that is what you meant :)
Gregg
15-Aug-2010
[17801]
My assumption--never assume, I know--was that 'c would always be 
re-bound before each call. I was looking at the action, not the context 
*in* the action.
Graham
15-Aug-2010
[17802]
Gregg, that's what I did to get it working .. but I'm interested 
to see how Gab's solution would work
Gregg
15-Aug-2010
[17803]
Agreed. Gabriele and others often point out holes in my naive code, 
for which I am always grateful.
Anton
15-Aug-2010
[17804]
Graham, you have misused the /TO refinement of VID-CONTEXT.

The function help states:  /to word [word!] "Set this word to the 
context created"
That's "set to", not "bind to", the context created.

So you've not bound C's body block as you intended. Instead, C loses 
its initial function value when it is set to the new context created 
by VID-CONTEXT.

Furthermore your context (created by CONTEXT above) ought to be no 
longer necessary since using VID-CONTEXT.
Graham
15-Aug-2010
[17805]
so how to use it correctly?
Anton
15-Aug-2010
[17806x4]
hang five
Ok, here's my first way. (untested)
hello: func [word][do bind [f/text: copy "hello" show f] word]

open-window: does [
	view/new center-face layout vid-context [
		f: field

  button "Hello" [hello 'f] ;  Pass to HELLO any one of the words in 
  this context (here 'f).
		button "Clear" [clear-face f]
	]
]

open-window
do-events
You can call OPEN-WINDOW several times before DO-EVENTS, or add a 
button which calls it.
Graham
15-Aug-2010
[17810]
untested??
Anton
15-Aug-2010
[17811x3]
I just tested it and it seems to work.
Here's another way, also tested:
Here's another way, also tested:
Graham
15-Aug-2010
[17814]
What about Gabriele's vid-context ?
Anton
15-Aug-2010
[17815x2]
window-functions: [
	hello: does [f/text: copy "hello" show f]
]

open-window: has [ctx] [
	view/new center-face layout bind vid-context/to [
		f: field
		button "Hello" [hello]
		button "Clear" [clear-face f]
		button "New window" [open-window]
	] 'ctx context bind window-functions ctx
]

open-window
do-events
Gabriele's vid-context is a pretty nice function.
Graham
15-Aug-2010
[17817x2]
So, how can I use it?
oops ...
Anton
15-Aug-2010
[17819]
Well... what do you need to do again?
Graham
15-Aug-2010
[17820]
Sorry ..didn't read your example with care
Anton
15-Aug-2010
[17821]
oh ok
Graham
15-Aug-2010
[17822x2]
What I want to do is the working example I posted above.
Your last example works
Anton
15-Aug-2010
[17824]
Your 'c function is my 'hello function.
Graham
15-Aug-2010
[17825]
why is it wrapped in a block?
Anton
15-Aug-2010
[17826]
Because I need to bind that code in open-window.
Graham
15-Aug-2010
[17827]
my functions already exist in the global context
Anton
15-Aug-2010
[17828]
It creates new copies of the functions in window-functions each time 
a new window is opened.
Graham
15-Aug-2010
[17829]
that's cheating!
Anton
15-Aug-2010
[17830x2]
I see.
Ok, in that case, go back to the first example I posted. I'll need 
to modify it a little bit..
Graham
15-Aug-2010
[17832]
the situation is that I have a lot of screens inside tabs.  now sometimes 
I want to re-use those screens outside the tabs ... so I just copy 
the code and put into a new window .. but then I want to be able 
to make the functions that operate on the original sceens work on 
my new ones.