• Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

AltME groups: search

Help · search scripts · search articles · search mailing list

results summary

worldhits
r4wp5907
r3wp58701
total:64608

results window for this page: [start: 39101 end: 39200]

world-name: r3wp

Group: Core ... Discuss core issues [web-public]
Chris:
19-Dec-2008
A 'bind question: how do I construct an object containing blocks 
without changing the blocks' contexts?  This bad:

>> id: #foo
== #foo
>> blk: [id]
== [id]
>> reduce blk
== [#foo]
>> ctx: context append/only [id: #bar bk:] blk
>> reduce ctx/bk
== [#bar]

This good:

>> id: #foo
== #foo
>> blk: [id]
== [id]
>> reduce blk
== [#foo]
>> ctx: magic-context append/only [id: #bar bk:] blk
>> reduce ctx/bk
== [#foo]

How to 'magic-context ?
[unknown: 5]:
20-Dec-2008
What is the best way to set all locals in a function to none before 
returning the result of the function if you have an extensive list 
of locals?
Geomol:
20-Dec-2008
Is there a better way than just doing:

var1: var2: var3: ... varN: none
[unknown: 5]:
20-Dec-2008
would be nice if you could  just have a command  inside your function 
that says  clear-locals.
Geomol:
20-Dec-2008
That would require to get access to locals from the outside of a 
function. I'm not away of a way to do that.
Geomol:
20-Dec-2008
*aware* of a way ...
Geomol:
20-Dec-2008
You still need to get easy access to all the locals. Like having 
them in a series.
Sunanda:
20-Dec-2008
If you know the "name" of the function, then you can get at the variables:
f: func [a b /local c d e] [print mold first :f]
f 1 2
Then you could run a loop for all those after /local
Gregg:
20-Dec-2008
1) what is the purpose of clearing the locals?

2) how often do you need to do this, where the list is large? i.e. 
does it indicate a design issue?
[unknown: 5]:
20-Dec-2008
I tried  that after I posted Sunanda but even though I could get 
to them I was still able to out put a value of the local before setting 
them to none that way so what that  meant was that even though I 
attempted to set them to none! that way that it didn't take (and 
didn't give me an error either).
[unknown: 5]:
20-Dec-2008
Sundanda , here is a test:
Geomol:
20-Dec-2008
I found a way to set all locals to none, while just specifying one 
of the locals, and it isn't beautiful, I'm afraid:

f: func [/local a b c][
	a: 1 b: 2 c: 3
	print [a b c]

	; This next line set all locals to none:
	set next bind first :f 'a none
	print [a b c]
]

Running the function in the console:
>> f
1 2 3
none none none
>>
[unknown: 5]:
20-Dec-2008
myfunc: func [ /local lcl lcl2][
    lcl: "I still have a value"
    print mold lcl2: next find third get 'myfunc /local
    foreach item lcl2 [print mold item]
    foreach item lcl2 [print mold get :item]
    foreach item lcl2 [set :item none!]
    print lcl
]
[unknown: 5]:
20-Dec-2008
myfunc: func [ /local lcl lcl2][
    lcl: "I still have a value"
    print mold lcl2: next find third get 'myfunc /local
    foreach item lcl2 [print mold item]
    foreach item lcl2 [print mold get :item]
    foreach item lcl2 [set :item none]
    print lcl
]
Geomol:
20-Dec-2008
My example only works for functions, which doesn't take arguments. 
If a function take argument, you need:

f: func [v /local a b c][
	a: 1 b: 2 c: 3
	print [a b c]

	set next find bind first :f 'a /local none
	print [a b c]
]
Geomol:
20-Dec-2008
Hard to read that setting-to-none line, and I haven't found a way 
to do it by a function call (like a clear-locals function).
[unknown: 5]:
20-Dec-2008
Its a good idea though - isn't it?
Geomol:
20-Dec-2008
Yes, a native clear-locals seem like a good idea.
BrianH:
20-Dec-2008
R3 doesn't have this problem, so you are not likely to get a native.
Geomol:
20-Dec-2008
:-) It gets worse, if all parameters should be set to none:

f: func [v /local a b c][
	a: 1 b: 2 c: 3
	print [v a b c]

	set bind head remove find first :f /local 'a none
	print [v a b c]
]

Try:
>> f 42
BrianH:
20-Dec-2008
Keep in mind that unless you have a known name reference to a function, 
the code inside the function has no idea which function it is inside, 
so a native would need a reference to a function or a word with the 
function assigned to it or it won't work - natives aren't magic.
Geomol:
20-Dec-2008
Hm, I don't need the HEAD, so it can be:
set bind remove find first :f /local 'a none
Geomol:
20-Dec-2008
Brian, do you know, if it's possible from outside a function to specity 
its context? (To be used in the second parameter for BIND.)
BrianH:
20-Dec-2008
You don't need the find either. John, your example with ALSO:

f: func [v /local a b c][
	a: 1 b: 2 c: 3
	print [v a b c]

	also
		print [v a b c]
		set bind remove first :f 'a none
]
BrianH:
20-Dec-2008
In answer to your question, in R2 it is only possible from outside 
a function to retrieve its context. You were doing so in your example. 
It doesn't have any meaning when the function isn't running, but 
you can't get a reference to the function from the inside.
Geomol:
20-Dec-2008
I was thinking about making a clear-locals function, but then I need 
to access the context of the function calling clear-locals (from 
clear-locals).
BrianH:
20-Dec-2008
Remember, the /local refinement is also a local variable, so if you 
want to clear *all* the locals you also need to clear the word versions 
of the refinements.
BrianH:
20-Dec-2008
For the most part you don't need to clear *all* of the locals, just 
a select few that still refer to large series or structures.
BrianH:
20-Dec-2008
John, you can't just access the context of a calling function or 
even the current function, even from a native. The code block your 
code is in can be assigned to many functions, and isn't bound to 
any context. Words are direct bound individually. If you want to 
clear a context, yo have to specify which one in a parameter.
Steeve:
20-Dec-2008
a function with a context for local vars
BrianH:
20-Dec-2008
You can't get access to a function's context without having a known 
word that is already bouund to that context. When you do first :f, 
the words retrn are not bound to the function's context. In R2, when 
you do third :f you get words that are bound, but you can only guess 
to what., since words are bound individually. The only safe way to 
do clear-words is to pass both the function and a known word bound 
to the function's context, and even then you have to copy the fuunction's 
argument block and convert any refinements to words before you bind 
the copy.
[unknown: 5]:
20-Dec-2008
So brianH are you saying it is impossible in R2 to send a function 
within a func to clear the parent functions locals?
BrianH:
20-Dec-2008
No, just difficult unless you provide 2 parameters:
- A reference to the function or a copy of its parameter list.
- A word known to be bound to the function's context.
BrianH:
20-Dec-2008
As a side effect, the clear-words function would be impossible in 
R3.
BrianH:
20-Dec-2008
Getting a the argument list, which you would have to copy, convert 
refinements to words, then bind. The copy and conversion would be 
slower than necessary.
[unknown: 5]:
20-Dec-2008
>> myfunc: func [arg /local lcl lcl2][
[        lcl: "I still have a value"
[        lcl2; 2
[        clear-locals :myfunc lcl
[        print lcl
[        print lcl2
[    ]
>>
>> myfunc 2
none
none
>>
[unknown: 5]:
20-Dec-2008
>> myfunc: func [arg /local lcl lcl2][
[        lcl: "I still have a value"
[        lcl2: 2
[        clear-locals :myfunc lcl
[        print lcl
[        print lcl2
[    ]
>>
>> myfunc 2
none
none
Steeve:
20-Dec-2008
clearly guys, a function should never be so huge and obscufated so 
that it will not be any more interesting to use a clear-locals func.
Steeve:
20-Dec-2008
i meant, it's better to do a my-var: none when necessary
[unknown: 5]:
20-Dec-2008
I have 22 locals in one function alone already and even though I 
plan on reducing some of those in reducing some code, I have a feeling 
that I will regain them as I add more code in the function.
Steeve:
20-Dec-2008
for this specific case (lot of locals). you could define a local 
block to reset them simply.
f: func [ ... /local a f g...][
	local: [a f g ...]
	....
	set local none		;clear locals
]
Steeve:
20-Dec-2008
did you know that 'set still works with block of get-words [:a :b 
:c]
[unknown: 5]:
21-Dec-2008
As for the clearing of the locals  from a function - here you go:

clear-locals: func [

        {Used as the ending statement within a function to set the function's 
        locals to none value.}
        fnc [function!]
    ][

        set bind first to-block trim/with mold first :fnc "/" first find 
        second :fnc set-word! none
]
[unknown: 5]:
21-Dec-2008
Would make a good mezz for 2.7.7
Anton:
21-Dec-2008
There may not be a set-word in the function body.
[unknown: 5]:
21-Dec-2008
Anton, in that case wouldn't wouln't have a need to use a clear-locals 
function.
[unknown: 5]:
21-Dec-2008
See the answers group as Gabriele posted a superior clear-locals 
function.
BrianH:
21-Dec-2008
Note that his solution requires the known word parameter, but not 
the function context parameter. This means that it is more easy to 
call from "inside" the function where you can specify a known word 
instead of having to find one. The no-parameter solution is still 
up in the air :)
Steeve:
21-Dec-2008
in R3 it's the same object, so i assume it's a bug in R2
[unknown: 5]:
21-Dec-2008
Steeve, I guess what I'm saying is that SELF itself becomes a new 
value thus same? would report false.
[unknown: 5]:
21-Dec-2008
I'm not sure how you can see that the self of one could be the same 
value as a self of another?
Steeve:
21-Dec-2008
i said previously that in R3 (comparing to R2) the bind? function 
returns the same object, not a different one.
[unknown: 5]:
21-Dec-2008
I'll yield to those that have used the Alpha a bit more as I really 
couldn't speculate at this point even.
Anton:
21-Dec-2008
Steeve, it does look odd, like a bug.
[unknown: 5]:
21-Dec-2008
If you think it is a bug Anton, then you should report it to Rambo 
assuming your talking about R2.
Anton:
21-Dec-2008
There are no tickets that match a search for "bind?" in Rambo.
Steeve:
21-Dec-2008
especialy when we know that the word humour has a greek root  meaning 
FLUID
Gabriele:
22-Dec-2008
I do not think this is a bug, and it may not be trivial to fix it 
if it was (which means, it'll never get fixed as Carl is not going 
to spend that much time on R2 for something not important)
Steeve:
22-Dec-2008
i agree Gab, for me, it's not a bug but a functionnality
Steeve:
22-Dec-2008
a dynamic one
Steeve:
23-Dec-2008
besides in R3, the bind? func doen't return a cloned object anymore
Gabriele:
23-Dec-2008
Anton, it's not that it has any use, it's that there is no "object" 
internally, just a "context", and the bind? function creates an "object" 
for the "context" so that it can return it (there is no way to access 
a context directly). bind? does not know whether the context is already 
referenced by an existing object or not, nor has any way to get to 
any such existing objects, so it just always creates a new one.
Geomol:
23-Dec-2008
Has anyone noticed a max length for filenames giving to EXISTS? under 
Windows? I get a false reply, if the length of the full path is more 
than some 54 characters.
[unknown: 5]:
25-Dec-2008
Notice that example1 is more efficient than example 2.  However, 
Example 3 takes the flexibility of setting my-block to a cleared 
block and actually is more efficient than example 1.
PeterWood:
26-Dec-2008
I'm running a CGI script from which I want to 'launch another script 
to do some housekeeping. The output from the launched script (including 
the Rebol banners) is returned to the browser. Is there a way to 
redirect the output from the launched Rebol session?

(I am getting this behaviour on both Mac OS X and Linux).
eFishAnt:
26-Dec-2008
OK, so 'close does not return anything...so you can't  try a block 
with close if close is the last line in the block of you check if 
error? try [close whatever]

If I use instead:

if error? catch [
	close whatever
 	true
][print "will this ever get printed?"]
[unknown: 5]:
26-Dec-2008
I'm finding a bug in loop function.  Anyone know of a problem with 
loop.  Heading to Rambo...
[unknown: 5]:
26-Dec-2008
Yes Steeve, I was doing other things with ihe function which is why 
it had the false.  That was a remant.
[unknown: 5]:
26-Dec-2008
I spent a couple hours checking my code and yet  it seems LOOP is 
the culprit.
[unknown: 5]:
26-Dec-2008
Still seems to be a bug somewhere.
Steeve:
26-Dec-2008
missing a copy somewhere in your code
[unknown: 5]:
26-Dec-2008
tried copy on that part also and it didnt' make a difference.
Steeve:
26-Dec-2008
normal, it's different blocks, walways the same bug with a missing 
copy some
[unknown: 5]:
26-Dec-2008
Maybe not a bug just a need to use copy/deep in loop.
[unknown: 5]:
26-Dec-2008
Steeve, I see what you were saying.  I went ahead and fixed that 
by changing a piece of code so that the d block wasn't modified also.
BrianH:
26-Dec-2008
It's not a bg in loop, you are reusing the inner block [fname] where 
you shouldn't.
Davide:
29-Dec-2008
Is there a way to modify an object (adding and removing components) 
at runtime without rebuild it from scratch ?

I remember an old thread in the mailing list abut this argument, 
but I cannot find it..
Davide:
29-Dec-2008
I'm trying to find a workaroud using first object , second object 
... but it doesn't seems to work
Davide:
29-Dec-2008
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
Steeve:
29-Dec-2008
you could write your handler in a context directly, it's the most 
simple thing to do
Davide:
29-Dec-2008
it's in a context
Steeve:
29-Dec-2008
ctx: context [
a: 1
block-code: [a: a + 1]
]

a is defined local to the context ctx
Davide:
29-Dec-2008
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
Davide:
29-Dec-2008
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
ctx: context [
localobj: saveobj
localobj/a: 1
block-code: [localobj/a: localobj/a + 1]
]

this should work...
Davide:
29-Dec-2008
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"
Davide:
29-Dec-2008
so If I need to keep the values of the hadler I need to store them 
in a global ojb
Steeve:
29-Dec-2008
i think you have several problems not not necessarily linked, you 
should have a look on rebol.org, there are many web servers examples
Davide:
29-Dec-2008
thanks paul, this is not a standard web server... it's a comet web 
server (where the browser use an endless connection)
Davide:
29-Dec-2008
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
PeterWood:
29-Dec-2008
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
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 ?
Davide:
29-Dec-2008
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 ?
Davide:
30-Dec-2008
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
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
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
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
Steeve:
30-Dec-2008
hset: func [obj][avg obj obj/a obj/b]
[unknown: 5]:
3-Jan-2009
Has anyone created any code that is used to ensure a series doesn't 
contain function that when reduced produce harmful code?
[unknown: 5]:
3-Jan-2009
for example something that could prevent the execution of a block 
suchas [delete %somefile] when reduced.
39101 / 6460812345...390391[392] 393394...643644645646647