[REBOL] Re: [ A world of words ] naming convention, namespace, namespace pollut
From: rebol:meurrens at: 2-Jun-2003 11:19
Hello Greg,
At 12:20 28/05/2003 -0600, you wrote:
>You *can* actually create private words, with a USE block, but I
>haven't used this technique much myself in real applications.
>
> o: make object! [
> get-a: set-a:
> get-b: set-b:
> none
> use [_a _b] [
> _a: _b: none
> get-a: does [_a]
> set-a: func [value] [_a: value]
> get-b: does [_b]
> set-b: func [value] [_b: value]
> ]
> ]
The miscellaneous methods proposed on this list
(and, to me, by private mail from other rebollers)
to create PRIVATE things ....
;;;;;;;;;;;;;;;;;;;;
REBOL []
use [ priv1 ] [ o1: make object! [ priv1: 1 =pri: does [ priv1 ] ] ] ;;;
priv1 remains a *PUBLIC* INSTANCE WORD
use [ priv2 ] [ priv2: 2 o2: make object! [ =pri: does [ priv2 ] pri=:
func[a][priv2: a] ] ] ;;; priv2 is a PRIVATE STATIC WORD
o3: make object! [ =pri: none use [priv3] [ priv3: 3 =pri: does [ priv3 ]
] ] ;;; priv3 is a PRIVATE STATIC WORD
o4: make object! [ a:41 use [] [ b: 42 ] ] ;;; a INSTANCE WORD ;;; b
GLOBAL WORD
o22: make o2 []
;;;;;;;;;;;;;;;;;;;;;;;;
... only apply for so-called "static variables"
{
; =pri ; pronounce "get pri"
; pri= ; pronounce "set pri"
}
Just run the above mini script and, then, try :
priv1 ; error
priv2 ; error
priv3 ; error
o1/priv1 ; 1 ; !!!!!!!!!!!!! PUBLIC
o2/priv2 ; error
o22/priv2 ; error
o3/priv3 ; error
o1/=pri ; 1
o2/=pri ; 2
o22/=pri ; 2
o3/=pri ; 3
o22/pri= 22 ; 22
o22/=pri ; 22
o2/=pri ; 22 ; !!!!!!!!!!!! STATIC
Of course, it does not make difference as far as you only create underived
singletons (o1, o3)
(objects with just ONE instance).
But in ordinary situations (o2, o22, ...), it means that,
AFAIK (????? I hope I am wrong...),
there is no way to create PRIVATE INSTANCE WORDS
:-(
My own convention is to prefix their name with an "underscore"
and to destroy with energy any script that would contain
a "/" followed by a "_"
Something very easy to detect automatically :-)
HTH
</marc>
>-- Gregg
Prof. Ir Marc Meurrens, Brussels (be)
TEL: +32 (0)2 537 2812
FAX: +32 (0)2 537 7645
EMAIL: [marc--meurrens--org]
URL: http://www.meurrens.org/
REB: http://rebol.mksa.net/
PGPKEY: http://www.meurrens.org/pgp/
Please don't mail me attached files, instead, use my 'exchange area' :
EXCHANGE AREA: http://www.meurrens.org/exchange/
(HTTP/FTP upload/download of temporary/persistent files)