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

World: r3wp

[Core] Discuss core issues

Davide
29-Dec-2008
[11948x2]
Now I can ask a more precise question:

here is my problem:
I have an application object app that "serve" two client c1, c2

app: make object! [
	hset: func [c] [k: c/name]
	hget: func [c] [print ["k=" k]]
]

c1: make object! [
	name: "pippo"
]

c2: make object! [
	name: "pluto"
]


The handlers of app, use k as internal container, but of course it's 
shared between clients:

>> app/hset c1
== "pippo"
>> app/hset c2
== "pluto"
>> app/hget c1
k= pluto   


I would bind k (and every set-word in the handler) to the object 
passed as parameter so the last line would produce:

>> app/hget c1
k= pippo

Now I come to this solution, using blocks instead of funcs in app

app: make object! [
	hset: [k: name]
	hget: [print ["k=" k]]
]

c1: make object! [
	name: "pippo"
	vars: make object! [
		k: none
	]
]

c2: make object! [
	name: "pluto"
	vars: make object! [
		k: none
	]
]

This produce:

>>  do bind bind app/hset c1/vars c1
== "pippo"
>> do bind bind app/hset c2/vars c2
== "pluto"
>> do bind bind app/hget c1/vars c1
k= pippo


This works, but I have to collect every set-words used in the handler, 
into the clients (using Ladislav set-words http://www.fm.tul.cz/~ladislav/rebol/set-words.r
)


sw: copy [] repeat h next first app [sw: union sw set-words app/:h]

b: copy [] repeat w sw [insert tail b reduce [to set-word! w none]] 
vars: make object! head b
c1/vars: vars
c2/vars: vars


Now, my questions are:
1) Is this approch "rebolish" ? There's a smarter way to do it ?
2) If I need a function in my app like:

app: make object! [
	hset: [k: avg a b]
	hget: [print ["k=" k]]
	avg: func [x y] [aux: x + y aux: aux / 2]
]


How can I collect the aux: word in avg function, and bind this function 
to c1/vars ?
Well I can bind avg to c1 with: 


app/avg: func first get in app 'avg bind bind second get in app 'avg 
c1/vars c1


Still hold the first question: there is a better approach ? If we 
suppose the app object is large, with hundreds of clients, would 
be better, for example, copy the entire app obj in every client, 
so I can execute the code without bind ?
Gabriele
30-Dec-2008
[11950]
I don't seem to understand what you're trying to do... why isn't 
hget defined as func [c] [print c/name] ?
Davide
30-Dec-2008
[11951]
k: c/name and print ["k=" k] are only one (stupid) example that use 
a word k that I want to keep distinct between client.. Every client 
need its instances of words.
Steeve
30-Dec-2008
[11952]
again, why don't you define K and aux localy to your object ?
app: make object! [
	k: aux: none
	hset: does [k: avg a b]
	hget: does [print ["k=" k]]
	avg: func [x y] [aux: x + y aux: aux / 2]
]
Davide
30-Dec-2008
[11953]
If I define aux locally it is shared to every client:

app: make object! [
	aux: none
	hset: [avg a b]
	hget: [print ["avg=" aux]]
	avg: func [x y] [aux: x + y aux: aux / 2]
]

c1: make object! [
	a: 2
	b: 4
]

c2: make object! [
	a: 3
	b: 5
]

>> do bind app/hset c1
== 3
>> do bind app/hget c1
avg= 3
>> do bind app/hset c2
== 4
>> do bind app/hget c1
avg= 4 <<< error this shoud be 3 !
Steeve
30-Dec-2008
[11954x2]
erf, app should use your object as parameter instead of using unbound 
vars:
app: make object! [
	hset: func [obj][avg obj/a obj/b]
	hget: func [obj][print ["avg=" obj/aux]]
	avg: func [obj x y] [obj/aux: x + y obj/aux: obj/aux / 2]
]
c1: make object! [
	a: 2
	b: 4
	aux: none
]
...

>>app/hset c1
==3
>>app/hget c1
==3
>>app/hset c2
==4
>>app/hget c1
==3
hset: func [obj][avg obj obj/a obj/b]
Davide
30-Dec-2008
[11956]
ok, "aux" need to be defined in every client, this is the key to 
 ensure correct results.

About function vs blocks: don't you think that using binded blocks, 
instead of functions, the code would be simplier ? 

Using functions is very "javascript style", but it looks not very 
natural to me in rebol.
[unknown: 5]
3-Jan-2009
[11957x3]
Has anyone created any code that is used to ensure a series doesn't 
contain function that when reduced produce harmful code?
for example something that could prevent the execution of a block 
suchas [delete %somefile] when reduced.
I have produced some code to do this but curious if others have as 
well.  Seems it could be useful.
Sunanda
3-Jan-2009
[11960]
It would be useful.....Here's a previous discussion that looks at 
various related issues:
http://www.rebol.org/ml-display-thread.r?m=rmlDMBC
[unknown: 5]
3-Jan-2009
[11961]
That is somewhat simliar but that sounds like you were interested 
in executing any script code in a sandbox.  What I'm doing is allowing 
all other values to be reduced except allowed functions and natives.
btiffin
3-Jan-2009
[11962]
I think Maxim mentioned that he had done a lot of work when he sandboxed 
Elixir.  I didn't study enough of the magic Elixir to know how he 
pulled it off, but if it's Max, it's good and ahead of it's time.
[unknown: 5]
3-Jan-2009
[11963x2]
I got it working but needs much more testing.
For example, my function will take a series and if anything in it 
is a function or native then it will change that word to a literal 
so that it is then seen as a value.
btiffin
3-Jan-2009
[11965]
I always wondered why REDUCE/ONLY didn't do this (an exclusion list 
of words or an inclusion list of words more like)
[unknown: 5]
3-Jan-2009
[11966x4]
For example:

>> defunction [print "cool" 1 * 1 2 = 2]
== ['print "cool" 1 * 1 2 = 2]
Yeah Brian, that is what would be nice to have.  But not just an 
exclusion but also a type!  such as Reduce/exclude [delete %somefile] 
[function!]
My functions works on nested series also.
>> s

== [print "cool" do exit halt 1 * 1 [print "cool" do exit halt 1 
* 1]]
>> defunction s

== ['print "cool" 'do 'exit 'halt 1 * 1 ['print "cool" 'do 'exit 
'halt 1 * 1]]
Chris
3-Jan-2009
[11970]
Sounds like you need a 'map function.  Psuedo-example:

	map my-block func [val][
		either word? val [
			either any-function? get val [val][get val]
		][
			val
		]
	]
BrianH
3-Jan-2009
[11971]
A whitelist is easier to implement in R2. You create an object that 
has all of the legit functions assigned to fields, then load the 
block unbound (to-block of its string representation), then bind 
the block to the legit object. All other function references will 
be unbound in the block. Be really careful when choosing your legit 
functions - you might need to make safe equivalents for some.
Chris
3-Jan-2009
[11972x2]
Not sure that is 'easier to implent'?  Especially when your spec 
is blanket screening of all functions...
...implement (getting more like Reichart : )
BrianH
3-Jan-2009
[11974x2]
(I've been having keyboard problems that do the same thing)
Chris, you missed that being able to screen for "bad" functions is 
what Paul is trying to do. It is much easier to maintain a whitelist 
than a blacklist, and easier to implement in R2 as well.
[unknown: 5]
3-Jan-2009
[11976x4]
Chris is on to the method that I deploy but I do it recursively.
I also use an exceptions list to allow certain words.
>> s

== [print "cool" 1 + 1 age > 18 halt all [3 + 3] find "this" "i" 
[print "cool" 1 + 1 age > 18 halt all [3 +
 3] find "this" "i"]]
>> defunction s

== ['print "cool" 1 '+ 1 age '> 18 'halt 'all [3 '+ 3] 'find "this" 
"i" ['print "cool" 1 '+ 1 age '> 18 'ha
lt 'all [3 '+ 3] 'find "...
>> reduce s

== [print "cool" 1 + 1 19 > 18 halt all [3 '+ 3] find "this" "i" 
['print "cool" 1 '+ 1 age '> 18 'halt 'all
 [3 '+ 3] 'find "this" "...
>>
I have two implements of that function
Henrik
4-Jan-2009
[11980x3]
I want to use the body of an object in a VID layout block, but words 
are not lit:

things: make object! [item-type: 'something]

layout compose/deep [button "Hello" with [(things)]]

When words are not lit, the layout process goes wrong, because:

>> probe things
make object! [
    item-type: 'something ; yes
]
>> third things
== [item-type: something] ; no!

How do I get lit words there?
oops, the layout line is supposed to be:

layout compose/deep [button "Hello" with [(third things)]]
layout compose/deep [button "Hello" with [(load at mold :things 14)]]

Dumb solution, but it works.
Ammon
4-Jan-2009
[11983]
>> third things
== [item-type: something]
>> type? second third things
== word!
>> things/item-type
== something
>> type? things/item-type
== word!
>> type? things/item-type: to lit-word! things/item-type
== lit-word!
>> third things
== [item-type: 'something]
>> type? things/item-type
== lit-word!
Henrik
4-Jan-2009
[11984]
yes
Ammon
4-Jan-2009
[11985]
I vaguely remember some sort of hack I worked with Compose to come 
out with the correct result on item creation but I may very well 
be mistaken.
Gregg
4-Jan-2009
[11986]
I've done the mold+load trick as well Henrik. I've also taken the 
block from THIRD and changed each word type to lit-word.

  change-each w third things [either word? w [to-lit-word w] [w]]
Henrik
4-Jan-2009
[11987]
thanks, Gregg. I'm assuming now there is no truly quick way to do 
this.
Maxim
4-Jan-2009
[11988]
henrik, the trick is to keep them as lit words:

make object! [
    item-type: to-lit-word 'something
]
Graham
5-Jan-2009
[11989]
Have there been any efforts to standardize on IPC methods?
Gregg
5-Jan-2009
[11990]
Not that I'm aware of, other than me bugging Carl about it. I've 
used a number of different methods myself (files, local TCP ports, 
tuplespace).
Pekr
5-Jan-2009
[11991x2]
Graham - what do you mean by IPC? Rebol task to rebol task?
IIRC r3 architecture counts on it, and there should be ipc:// scheme, 
or I think I saw something like that proposed :-)
Graham
5-Jan-2009
[11993]
Yes, rebol process to rebol process
Nicolas
7-Jan-2009
[11994]
are rebol's words stored as a linked list? also, where are rebol's 
datatypes stored? is there a value in front of every value that is 
the datatype? is the datastructure stored in a separate place to 
the values themselves? how does it work?
Sunanda
7-Jan-2009
[11995]
No one is really saying, Nick. It's a part of the implementation 
that may change at any time.

Some clues have surfaced over the years in discussions about "slots" 
(search for [REBOL slots] for more links:

http://www.rebol.org/cgi-bin/cgiwrap/rebol/ml-display-thread.r?m=rmlKVVC
Henrik
7-Jan-2009
[11996]
Can anyone explain exactly what random/secure does?
btiffin
7-Jan-2009
[11997]
Does this help?  http://www.rebol.net/cookbook/recipes/0019.html