World: r3wp
[Core] Discuss core issues
older newer | first last |
Steeve 29-Dec-2008 [11903] | wrong, in R3: append my-object [new-var: none] |
Davide 29-Dec-2008 [11904] | R3 is going to be my nightmare :-) |
Steeve 29-Dec-2008 [11905] | when i need to simulate extendable objects in R2, i use blocks in replacement. |
Davide 29-Dec-2008 [11906] | I'm trying to find a workaroud using first object , second object ... but it doesn't seems to work |
Steeve 29-Dec-2008 [11907] | it can't |
Davide 29-Dec-2008 [11908x2] | I'm writing a function that replace every set-word in a block of code with a compoment of an object, so I have to build the object in one single pass |
(so every words become local for default) | |
Steeve 29-Dec-2008 [11910] | are there inner blocks which contain set-words too or not ? |
Davide 29-Dec-2008 [11911] | yes there are |
Steeve 29-Dec-2008 [11912x2] | so you can't use the construct function on the primary bock... |
except if the local vars are all set in the primary one too | |
Davide 29-Dec-2008 [11914] | the code is an handler so it could be everything |
Steeve 29-Dec-2008 [11915] | y |
Davide 29-Dec-2008 [11916x2] | I'm looking in lfulc code by ladislav, the parse rule to catch the set-words is quite simple |
lfunc | |
Steeve 29-Dec-2008 [11918] | you could write your handler in a context directly, it's the most simple thing to do |
Davide 29-Dec-2008 [11919x2] | it's in a context |
but the words used are still global, no ? | |
Steeve 29-Dec-2008 [11921x2] | not those which are scoped directly by the context |
ctx: context [ a: 1 block-code: [a: a + 1] ] a is defined local to the context ctx | |
Davide 29-Dec-2008 [11923x2] | I'm not sure if this can apply to my app. It's a web server so I have to mantain client values between session |
the context is unset after single request | |
Steeve 29-Dec-2008 [11925] | and ??? it's not related with your previous request |
Davide 29-Dec-2008 [11926] | If I change the code as: ctx: context [ saveobj/a: 1 block-code: [saveobj/a: saveobj/a + 1] ] I can retain the counter between web session |
Steeve 29-Dec-2008 [11927x3] | you lost your context, because you don't keep him in memory (i don't know how to answer to this problem) |
saveobj is not in your context | |
ctx: context [ localobj: saveobj localobj/a: 1 block-code: [localobj/a: localobj/a + 1] ] this should work... | |
Davide 29-Dec-2008 [11930] | yes ! saveobj is global, so I can use it for saving values that are in my context . In my context values will be lost. I'm writing a function to change every var in my handler like "var" to "saveobj/var" |
Steeve 29-Dec-2008 [11931x2] | i don't see y |
i don't see your point... ctx is global too... you shoul'd not lose it | |
Davide 29-Dec-2008 [11933x2] | Yes, I'm not too clear .... I unset the handler block every request I get |
so If I need to keep the values of the hadler I need to store them in a global ojb | |
Steeve 29-Dec-2008 [11935x2] | i think you have several problems not not necessarily linked, you should have a look on rebol.org, there are many web servers examples |
sorry... | |
[unknown: 5] 29-Dec-2008 [11937] | Wow another webserver. Does REBOL have the record in webservers? |
Davide 29-Dec-2008 [11938] | thanks ! only talking about this cleared my mind, I'm thinking about keeping the handler in memory |
[unknown: 5] 29-Dec-2008 [11939] | That is really cool Davide. |
Steeve 29-Dec-2008 [11940] | surely ;-) |
Davide 29-Dec-2008 [11941] | thanks paul, this is not a standard web server... it's a comet web server (where the browser use an endless connection) |
[unknown: 5] 29-Dec-2008 [11942] | ok, very cool. |
Davide 29-Dec-2008 [11943] | I'm building it to use a browser instead of view in multiuser app The page don't need to be refreshed so It's quite fast |
BrianH 29-Dec-2008 [11944x2] | You won't be able to remove fields from an object in R3, just add them. |
C still has the record in webservers :( | |
PeterWood 29-Dec-2008 [11946] | Davide: Can't you do this? >> my-object: make object! [a: 0 b: [1 2 3 4 5] c: "abcde"] >> insert my-object/b 0 == [1 2 3 4 5] >> my-object/a: 1 == 1 >> probe my-object make object! [ a: 1 b: [0 1 2 3 4 5] c: "abcde" ] >> my-object: make my-object [d: #0123] >> probe my-object make object! [ a: 1 b: [0 1 2 3 4 5] c: "abcde" d: #0123 ] |
Davide 29-Dec-2008 [11947x3] | thanks peter that sintax is very handy ! I didn't remember that |
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] ] |
older newer | first last |