Problem? load %script.r - howto retrieve all!!??
[1/7] from: robolinth:nodep:dds:nl at: 17-Mar-2002 21:51
Hello All,
I hope a Rebol guru inhere can answer me the folloing question.
As from the beginning im always using the Rebol/Core console to
program in, testing etc, and afterwards Im putting it into an editor.
Well as the rebol/core console does not support something like
line-numbers its impossible to save a file created inside the console,
or im doing somthing realy wrong...(this is not my question ;-)
Anyway the problem is the following:>
When loading or reading a file I would like to know ALL
the functions, blocks, etc..that where actived while loading the
file. There is no such command like "source loaded-script"
(Im now always using [ loaded: read %example.r ]) but thats a too
workaround..
I always have to look inside the script to know what is loaded
befor I can even know what im loading or activating with a read.
I never know what functions are activated at that time, perhpas they
even overwrite my current ones? (okay a protect could work here)..
Does anyone know what im talking about here?? ..I hope so.. :-)
Thanks in advance,
(R)egards,
Norman.
[2/7] from: sunandadh:aol at: 17-Mar-2002 19:35
Norman:
> When loading or reading a file I would like to know ALL
> the functions, blocks, etc..that where actived while loading the
> file. There is no such command like "source loaded-script"
> (Im now always using [ loaded: read %example.r ]) but thats a too
> workaround..
I'm no guru here, but here's a solution that works if your functions are
_not_ defined inside objects. The idea is:
1. capture current System/words
2. Load the script(s)
3. Examine new words added to system/words. Those of type Function! are what
you are after.
Sample code, including showing the object/function shortcoming:
;; Capture existing words
existing-words: copy first system/words
;; ---- run a script that does the following:
myfunc: func [] [print 1]
myobj: make object! [myobjfunc: func [] [print 2]]
;; Spot the new words
new-words: sort difference existing-words first system/words
foreach new-word new-words [
print [new-word type? get to-word new-word]
]
I don't know an easy way to tell if a word has changed -- but if you are
running an untrusted script, 'protect has got to be basic insurance.....I
suppose you could make a block of all words which are functions, and their
molded checksum. After loading the script, check again to see if they are
still functions with the same checksum.
But protect _that_ block (or make it local) and all the words you need to
check the checksums. Otherwise your checking could be subverted (My code
above naively assumes that 'sort, 'difference, etc retain their expected
meaning after running your script).
Sunanda.
[3/7] from: greggirwin:mindspring at: 17-Mar-2002 21:25
Hi Norman,
<< When loading or reading a file I would like to know ALL
the functions, blocks, etc..that where actived while loading the
file. There is no such command like "source loaded-script"
(Im now always using [ loaded: read %example.r ]) but thats a too
workaround.. >>
I think someone did cook up a function to look at system/words, then look at
it again after loading a script, then using DIFFERENCE, or something like
that.
You could also, depending on the script you're loading, load it as a block
and then use make object! on it to bind it to a parent object (just for
reflection purposes), then probe that object to see what it contains.
--Gregg
[4/7] from: rotenca:telvia:it at: 18-Mar-2002 11:35
> I don't know an easy way to tell if a word has changed -- but if you are
> running an untrusted script, 'protect has got to be basic insurance.....I
> suppose you could make a block of all words which are functions, and their
> molded checksum. After loading the script, check again to see if they are
> still functions with the same checksum.
Query/clear system/words
... (make something)
print mold query/clear system/words
You can look also at http://www.rebol.org/advanced/securedo.html
---
Ciao
Romano
[5/7] from: joel:neely:fedex at: 18-Mar-2002 6:01
Hi, Norman,
This isn't exactly an answer to the question as you posed it,
but here's something I do that helps deal with the situation.
Rather than having a REBOL file (*.r) contain a collection of
various parts, I prefer to
1) make sure that a single source file contains components
of a single specific concept, and
2) wrap the entire collection in an object.
I used to create source files that read like this:
REBOL [
...
]
foo: make object! [
...
]
with only a single object per source file. If the object
contained a method that was intended for stand-alone use,
that method was usually named RUN , so that I could type
at the console something like
generate-html/run %filename
If I wanted to be able to use the function from the command
line, I'd simply follow the object definition with an
evaluation of the RUN method with appropriate arguments.
The above strategy would help avoid clobbering globally-
defined words (or words defined in another source file)
and would allow the listing of the object just loaded to
see all its content.
More recently, I've started defining "bare objects" without
assigning a name in the file, such as
REBOL [
...
]
make object! [
...
]
This way I can say
glorp: load %sourcfilename.r
either at the command prompt or within another source file,
and control the scope of the loaded object more precisely.
However, the other benefits above still apply.
HTH!
-jn-
[Robolinth--nodep--dds--nl] wrote:
> Hello All,
> I hope a Rebol guru inhere can answer me the folloing question.
<<quoted lines omitted: 22>>
> [rebol-request--rebol--com] with "unsubscribe" in the
> subject, without the quotes.
--
; Joel Neely [joel--neely--fedex--com] 901-263-4460 38017/HKA/9677
REBOL [] do [ do func [s] [ foreach [a b] s [prin b] ] sort/skip
do function [s] [t] [ t: "" foreach [a b] s [repend t [b a]] t ] {
| e s m!zauafBpcvekexEohthjJakwLrngohOqrlryRnsctdtiub} 2 ]
[6/7] from: g:santilli:tiscalinet:it at: 18-Mar-2002 12:59
Hi SunandaDH,
On Monday, March 18, 2002, 1:35:12 AM, you wrote:
Sac> I don't know an easy way to tell if a word has changed -- but if you are
>> query/clear system/words
== [end! unset! error! datatype! context! native! action! routine! op! function! object!
struct! library! por
t! any-type! any-word!...
>> a: 1
== 1
>> set: "changed"
== "changed"
>> query/clear system/words
== [set a]
Regards,
Gabriele.
--
Gabriele Santilli <[g--santilli--tiscalinet--it]> -- REBOL Programmer
Amigan -- AGI L'Aquila -- REB: http://web.tiscali.it/rebol/index.r
[7/7] from: jason:cunliffe:verizon at: 18-Mar-2002 12:46
> More recently, I've started defining "bare objects" without
> assigning a name in the file, such as
<<quoted lines omitted: 4>>
> ...
> ]
Interesting. Yes that's the way Vanilla formats all the dynasnips in /apps
./Jason
Notes
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted