'do - question
[1/11] from: andreas:bolka:gmx at: 10-Nov-2001 23:46
Hi Rebols!
One question related to 'do: is there a chance for a block beeing
done
to halt the "doing"-process.
Some example for clarification:
-- snip --
[
REBOL []
bl: [
print "a"
print "b"
if ... [ ??? ]
print "c
]
do bl
]
-- snip
When the '...' condition holds, the "do" should stop.
--
Best regards,
Andreas mailto:[andreas--bolka--gmx--net]
[2/11] from: ammonjohnson:y:ahoo at: 10-Nov-2001 17:25
I would probably try something like:
bl: does [
print "a"
print "b"
if ... [ exit ]
print "c
]
bl
HTH
Ammon
[3/11] from: carl:cybercraft at: 11-Nov-2001 12:38
On 11-Nov-01, Andreas Bolka wrote:
> Hi Rebols!
> One question related to 'do: is there a chance for a block beeing
<<quoted lines omitted: 13>>
> -- snip
> When the '...' condition holds, the "do" should stop.
Would turning your block into a function be okay? ie...
REBOL []
bl: [
print "a"
print "b"
if 1 = 1 [return]
print "c"
]
do does bl
print "Still running here."
Note the "do does bl". So...
>> do %test.r
a
b
Still running here.
--
Carl Read
[4/11] from: andreas:bolka:gmx at: 11-Nov-2001 1:27
Saturday, November 10, 2001, 11:46:09 PM, Andreas wrote:
> -- snip --
> [
<<quoted lines omitted: 8>>
> ]
> -- snip
maybe this example is a bit misguiding. so i'll better describe the
situation. i'm 'do load'-ing a script (A) within a wrapper script (W).
now script A contains lot's of 'quits which are quite nasty, as
they'll not only halt the evaluation of script A but the whole
interpreter.
so i'm groping for some way to temporarily overwrite 'quit ahead of do
loading script A so that whenever a 'quit occurs within A, the
evaluation halts, but the wrapper script can continue and the
interpreter is running on.
as i'm do loading script A in a loop, overriding quit with a function
that does some cleanup work and then really 'quits won't help.
--
Best regards,
Andreas mailto:[andreas--bolka--gmx--net]
[5/11] from: al:bri:xtra at: 11-Nov-2001 13:48
> so i'm groping for some way to temporarily overwrite 'quit ahead of do
loading script A so that whenever a 'quit occurs within A, the evaluation
halts, but the wrapper script can continue and the interpreter is running
on.
> as i'm do loading script A in a loop, overriding quit with a function that
does some cleanup work and then really 'quits won't help.
Something like this could help:
o: make object! [
Quit: does []
do bind load %MyScriptWithQuit.r 'Quit
]
I hope that helps!
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[6/11] from: andreas:bolka:gmx at: 11-Nov-2001 2:07
Sunday, November 11, 2001, 1:48:14 AM, Andrew wrote:
> Something like this could help:
> o: make object! [
> Quit: does []
> do bind load %MyScriptWithQuit.r 'Quit
> ]
> I hope that helps!
for i 1 5 1 [
print "before"
do [
print 1
print 2
if = i 3 [
quit ; -> here
]
print 3
]
print "after"
]
By overwriting 'quit for that context my intention is to stop the 'do
wherever a quit occurs.
The block for the 'do is really loaded from an external file, which in
turn may load various files and quit's may occur deeply nested.
--
Best regards,
Andreas mailto:[andreas--bolka--gmx--net]
[7/11] from: al:bri:xtra at: 11-Nov-2001 15:14
Something like this then:
%Interpreter.r:
Interpreter: make object! [
Quit: does [
print "There's a Quit in this code!"
throw make error! "Quit"
]
Do: func [Code [block!]][
try bind Code 'self
]
]
for i 1 5 1 [
print "before"
Interpreter/Do bind load %Example.r 'i
print "after"
]
%Example.r:
print 2
print i
if i = 3 [
quit ; -> here
]
Seems to do the job for me.
Andrew Martin
ICQ: 26227169 http://valley.150m.com/
[8/11] from: nitsch-lists:netcologne at: 11-Nov-2001 5:55
RE: [REBOL] Re: 'do - question
carl suggested something like
>> catch/name[throw/name "goodbye" 'quit] 'quit
== "goodbye"
real-quit: :quit
quit: [throw/name 'quit]
catch/name[unview/all do your-file] 'quit]
you should also catch errors, reset directory
and figure out if you need some unview/all
to stop event-loop.
i have an extended version for that in my ide,
runs some unprepared foreign scripts well.
but german yet..
-Volker
[Al--Bri--xtra--co--nz] wrote:
[9/11] from: andreas:bolka:gmx at: 11-Nov-2001 15:22
Thanks Volker, Thanks Andrew!
Sunday, November 11, 2001, 5:55:38 AM, nitsch-lists wrote:
> carl suggested something like
>>> catch/name[throw/name "goodbye" 'quit] 'quit
> == "goodbye"
> real-quit: :quit
> quit: [throw/name 'quit]
> catch/name[unview/all do your-file] 'quit]
That's exactly with what I've come up yesterday night. As I know that
the script I call does not use any unnamed catch, it does work fine ;)
> you should also catch errors, reset directory and figure out if you
> need some unview/all to stop event-loop.
> i have an extended version for that in my ide, runs some unprepared
> foreign scripts well. but german yet..
hmm, german would be no problem, as this is my native language ;)
--
Best regards,
Andreas mailto:[andreas--bolka--gmx--net]
[10/11] from: nitsch-lists:netcologne at: 12-Nov-2001 6:46
RE: [REBOL] Re: 'do - question
Hi Andreas,
was in translations mood yesterday.
script %launch-by-do.r below.
complete (german) "ide" in "volker"-rebsite.
[andreas--bolka--gmx--net] wrote:
> Thanks Volker, Thanks Andrew!
> Sunday, November 11, 2001, 5:55:38 AM, nitsch-lists wrote:
<<quoted lines omitted: 14>>
> Best regards,
> Andreas mailto:[andreas--bolka--gmx--net]
REBOL [
title: "launch-by-do"
file: %launch-by-do.r
purpose: {
if one wants to start other scripts while launch disabled,
this script may help.
it starts them with do, but sets some stuff
so when script terminate the launcher continues.
mostly it patches quit.
be carefull because these scripts run with launchers security-settings.
}
features: {
* 'quit is "redirected" to throw/name 'quit 'quit,
so the usual quit-button returns.
except there is an unnamed catch around..
* uses some unview/all
view behaves differently if there is a window open.
with no window open it blocks with do-events,
with some it continues.
scripts which rely on blocking should be started without windows open..
* saves and resets directory
* has special protect-system.
protects only up to a specified word.
replace 'rebsite-ed there with the first word you define,
that and everything loaded later will not be protected.
allows for test scripts with protect-system twice in the same exe.
* saves and restores system/view/screen-face/pane,
after closing all windows and doing the script the old windows
appear magically.
* has some requesters: informs about termination by
error, quit or throw. search for 'alert and 'confirm to change them.
}
]
;do/args %build-pack.r 'test
demo: does [
; set to true if to disable "trusted?"-question.
debug-in-exe: false
; set to something which forms an error, like Bo's print-error.
form-error: :mold
;launch %pad.r
set-launch-by-do
launch [quit] ;we can launch blocks now, side-effect
;launch %pad.r
]
set-launch-by-do: func [] [
if not native? :launch [
unprotect 'protect-system
protect-system: does [
foreach word first system/words [
if 'rebsite-ed = word [break]
if value? word [protect word]
]
]
unprotect 'launch
launch: func [arg /secure-cmd
/local got-error thrown system-worte debug-quit
sf sf-bak system-quit my-dir set-back
] [
set-back: does [
unprotect 'quit
quit: :system-quit
change-dir my-dir
]
sf-bak: copy system/view/screen-face/pane
if any [debug-in-exe confirm reform [
"OOPS! file gets executed with 'do !"
"security risk. really?"
]
] [
unprotect 'quit
system-quit: :quit
if thrown: catch [
unview/all
quit: func [[catch]] [
unview/all
throw/name 'quit 'quit
]
my-dir: what-dir
if error? got-error: try [
do arg none
] [
alert probe form-error disarm got-error
]
none
] [
if not confirm probe reform [
"there was" mold :thrown "thrown"
"continue debugging?"
] [set-back quit]
]
set-back unview/all
;view/new -> no hotkeys.. needs hacking
sf: system/view/screen-face
sf/pane: sf-bak
show sf
]
]
]
]
demo
[11/11] from: andreas:bolka:gmx at: 12-Nov-2001 20:05
Monday, November 12, 2001, 6:46:20 AM, nitsch-lists wrote:
> was in translations mood yesterday.
> script %launch-by-do.r below.
> complete (german) "ide" in "volker"-rebsite.
great, thanks ;)
--
Best regards,
Andreas mailto:[andreas--bolka--gmx--net]
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted