[REBOL] Context - code included
From: rotenca::telvia::it at: 8-Sep-2001 18:32
Thank you for your previous message, i'll answer asap.
Here it is my idea of special-global-local words. written as code.
In the yesterday message i misinterpreted some of your code (and of your mind,
of course).
Now i think to understand well your idea of Special Word.
So in my code there are now only Special Word e Very Special Word.
I have written a modified version of Visualize-Context.
Happy to know your idea and my bug...
---
Ciao
Romano
-----
rebol[
Title: "Analyze a word"
Date: 30/7/2001
File: %myword.r
Email: [rotenca--libero--it]
Author: "Romano Paolo Tenca"
Version: 1.0.0
Category: [text util 3]
Purpose: {
find the type of a Rebol word
Visualize-Context redefined
many functions are a modified version of the
originals of Ladislav Mecir
to reflect the very special words
}
]
binded?: func [
{determines, if a Word is defined in any context}
word [any-word!]
] [
not error? try [error? get/any :word]
]
loaded?: func [
{determines, if a Word is defined in system-words}
word [any-word!]
] [
found? find first system/words word
]
vspecial?: func [
{determines, if a Word is a Very Special Word}
word [any-word!]
] [
found? all [
not binded? word
not loaded? word
]
]
special?: func [
{determines, if a Word is a Special Word}
word [any-word!]
] [
found? all [
not binded? word
loaded? word
]
]
global?: func [
{find out, if the given Word is a Global Word}
word [any-word!]
] [
found? all [
loaded? word
same? word bind word 'system
]
]
local?: func [
{find out, if the given Word is a Local Word}
word [any-word!]
] [
found? all [
binded? word
not global? word
]
]
local-unloaded?: func [
{find out, if the given Word is a Local Word not loaded in system/words}
word [any-word!]
] [
found? all [
binded? word
not loaded? word
]
]
in-object?: func [
{find out, if the given Word is defined in a object-context}
word [any-word!]
/local self
] [
found? all [
binded? word
not same? 'self bind 'self word
equal? object! type? get/any bind 'self word
]
]
in-use?: func [
{find out, if the given Word is Local to a func or use block}
word [any-word!]
] [
found? all [
local? word
not in-object? word
]
]
v-c: visualize-context: function [
{
Returns a copy of context words binded to the context
ATTENTION:
for a word local to use or func, return only the loaded? word
for an un-binded word returns []
}
word [word!] {one Word of the given Context}
] [result b-word] [
result: copy []
any [
if not binded? word [result]
if global? word [bind/copy first system/words 'system]
if in-object? word [bind/copy first get bind 'self word word]
foreach s-word first system/words [
if not same? s-word b-word: bind s-word word [
append result b-word
]
]
result
]
]
what?: func [word [word!]] [
if loaded? word [print "loaded?"]
if binded? word [print "binded?"]
if vspecial? word [print "vspecial?"]
if special? word [print "special?"]
if global? word [print "global?"]
if local? word [print "local?"]
if in-object? word [print "in-object?"]
if in-use? word [print "in-use?"]
if local-unloaded? word [print "local-unloaded?"]
print ""
]
;examples
what? 'do
what? first first system/words
use [a] [what? a]
halt