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

World: r3wp

[Core] Discuss core issues

Graham
16-Aug-2010
[17881]
and it doesn't solve the issue where the function you are rebinding 
actually calls a different function to update the gui
Anton
16-Aug-2010
[17882]
The major side-effect is that the action of each face (eg. button, 
field) will remake itself the first time it is used, to insert a 
snippet of code to rebind the window funcs before your specified 
action code uses them.
Graham
16-Aug-2010
[17883x4]
So, I suspect it is better to allow the programmer to select the 
context instead of automating it.
eg.  I had something like this 


button [ get-data ] ... and get-data called another function to update 
the GUI
binding 'get-data didn't help as the function it calls was still 
bound to global
so I like your first idea better :)
Anton
16-Aug-2010
[17887x3]
You're right about nested function calls. BIND doesn't recurse into 
words, so that the bodies of functions referenced by words are also 
bound. So that could be very damaging.
Updating a different window can still work, though, because you're 
going to need to reference that window anyway to distinguish it from 
the "current" one:
svv/vid-styles/button/multi/block: func [face blk][ ; <- This only 
does BUTTON for now.
	if pick blk 1 [
		;face/action: func [face value] pick blk 1

  face/action: func [face value /local window word] compose/only [

   window: face/parent-face ; Find the window face <-- (simplistic for 
   now)

   word: window/pane/1/var ; Find a word which references a field in 
   the window. <-- (simplistic for now)
			print "Remake action function."

   face/action: func [face value] probe append append copy [bind-funcs] 
   to-lit-word word (pick blk 1)
			do-face face value
		]

  if pick blk 2 [face/alt-action: func [face value] pick blk 2] ; <- 
  Also need to remake alt-action similarly to action, above.
	]
]
bind-funcs: func [word] [

 foreach window-function [hello][bind second get window-function word]
]

hello: does [f/text: copy "hello" show f]

open-window: has [window ctx] [
	window: view/new center-face layout vid-context/to [
		f: field
		button "Hello" [hello]
		button "Clear" [clear-face f]
		button "Clear window2's field" [clear-face window2/user-data/f]
	] 'ctx
	window/user-data: ctx
	window
]

window1: open-window
window2: open-window
do-events
Graham
16-Aug-2010
[17890]
neat trick .. i didn't know about user-data
Anton
16-Aug-2010
[17891x2]
No, wait a minute... that's what BIND-FUNCS is for. Currently it 
only affects HELLO, but you just need to add all the functions which 
need binding into the block:
foreach window-function [hello get-data update-gui etc.]  ...
So you can have nested function calls as deep as you like, as long 
as you specify those which need binding in BIND-FUNCS.
Graham
16-Aug-2010
[17893x2]
ok, but the other issue is that the function has to be rebound each 
time it is used
Was that what Gab was saying ..?
Anton
16-Aug-2010
[17895x2]
No, Gregg's first example suffered because it only did a BIND once, 
when the window was created. It needs to do the bind every time the 
button is pressed.
So Gregg's example would work for each window as long as that window 
was the last window opened. As soon as you opened a new window, none 
of the other windows would work properly anymore.
Graham
16-Aug-2010
[17897]
ah... mine bound with each button press
Anton
16-Aug-2010
[17898]
USER-DATA in the window faces seems unlikely to be used to me. You 
could also probably use DATA without problems as well. It depends 
on whether any other VID extensions are being used in your system, 
which could theoretically use that facet for something. Of course 
you can associate the window with it's vid-context by other means 
which doesn't touch any of the window facets at all...
Gabriele
16-Aug-2010
[17899x2]
Graham: when you use vid-context/to, the word you pass in is set 
to an object. the object contains all the set-words you used in the 
vid block. example:
>> lay: layout vid-context/to [f: field g: button] 'ctx
>> ? ctx
CTX is an object of value: 

   f               object!   [type offset size span pane text color 
   image effec... 

   g               object!   [type offset size span pane text color 
   image effec...
Graham
16-Aug-2010
[17901]
A concrete example would help me here :)
Gabriele
16-Aug-2010
[17902x2]
now you can pass this object to your functions so that you can use 
them with many layouts.
eg. you make c: func [obj] [obj/f/text: "something" ...]
Graham
16-Aug-2010
[17904x2]
ok, so this does involve some rewriting of functions
and I guess is not that different to passing a context to a function 
as discussed above
Gabriele
17-Aug-2010
[17906]
if you really can't touch the functions, you might as well just reuse 
the same globals, no? rebinding them is also "global" so there's 
not much difference.
amacleod
17-Aug-2010
[17907]
what's 'vid-context/to'?

I get an error?
Anton
17-Aug-2010
[17908]
It's in Gabriele's utility.r library which he mentioned on Saturday.
amacleod
18-Aug-2010
[17909]
thanks...i missed that
Graham
18-Aug-2010
[17910x2]
If I had a large numer of sorted strings, how can I most efficiently 
find the first string which partially matches my search string.  
Eg. I want search on '"find*"
A hash doens't allow me to do a wild card search
Gregg
18-Aug-2010
[17912]
http://www.rebol.org/view-script.r?script=like.rlets you do more 
than find/any, but you're still going to have the overhead of checking 
each string. Depending on your needs that may work, or you could 
make one big string out of them and just PARSE that.
Graham
18-Aug-2010
[17913x2]
find [ "ab" "bc" "bd" ] "b*"
looks like I should try and get a hash for each first letter, first 
and second letter etc so I can at least narrow it down to the first 
3 letters and then do search on everyone after that.
Gregg
18-Aug-2010
[17915]
How many strings and what kind of performance do you need?
Graham
18-Aug-2010
[17916x2]
18,000 strings....  real time.... as each time they type a character 
I am presenting a list of choices
I am emulating this http://rxterms.nlm.nih.gov:8080/
AdrianS
18-Aug-2010
[17918x2]
have you thought about using SQLite?
I wonder how that would compare with doing REBOL lookups
Graham
18-Aug-2010
[17920]
I was just thinking that!
Gregg
18-Aug-2010
[17921]
The example helps enormously Graham, because you said "first string" 
but now I see you want all matches for a given prefix.
Graham
18-Aug-2010
[17922]
once I get the first string .. then I can easily get the others as 
I sort the 18k strings first
AdrianS
18-Aug-2010
[17923]
is the existing sqlite driver work over the wire or does it do in 
process calls?
Graham
18-Aug-2010
[17924x4]
Maybe I need RIF
I've never used sqlite
I wonder if Ashley's rebdb would work ...
He doesn't have a like clause ... but I guess it could be faked
Gregg
19-Aug-2010
[17928x2]
Graham, did you try REFORMing into a single string and using FIND/ANY? 
I did a quick test here and it's instant for me with 18K random "words" 
making a 200K string finding the last word (non-random for testing).
Hmmm, some of the terms aren't single words though.
Graham
19-Aug-2010
[17930]
In effect you've created an index