Hello [EMAIL PROTECTED],
I think the script below might (somewhat) solve the GC problem...
It stores all the original objects in a local (to the function) block.
The big problem is, that only functions can be made public, without getting into some
really funny bahaviour :-)
REBOL []
make-hidden: func [
"Make an object! with hidden words"
public [block!] "Words that should be public to the outside"
prototype [block!] "Prototype block!, like used with make object!"
/local temp pub
] [
list: []
temp: make object! prototype
append list temp ; store the objects here to avoid GC problems
pub: copy []
foreach word public [
append pub bind load rejoin ["" word ": get in temp '" word] 'temp
]
make object! pub
]
; --- tests below this point ---
test-object: make-hidden [set-a sum] [
a: 1
b: 2
set-a: func [num] [a: num]
sum: func [] [a + b]
]
test-object2: make-hidden [set-a sum] [
a: 4
b: 5
set-a: func [num] [a: num]
sum: func [] [a + b]
]
; heavy use of recycle, to be able to spot GC problems
recycle/on recycle/torture
print mold test-object
recycle/on recycle/torture
print test-object/sum
recycle/on recycle/torture
test-object/set-a 3
recycle/on recycle/torture
print test-object/sum
recycle/on recycle/torture
print mold test-object2
recycle/on recycle/torture
print test-object2/sum
recycle/on recycle/torture
test-object2/set-a 3
recycle/on recycle/torture
print test-object2/sum
; --------------------------
Best regards
Thomas Jensen
On 16-Jun-00, [EMAIL PROTECTED] wrote:
> Tim Lesher:
>> Some of the Rebol documentation mentions "hidden" object values, and says
> to see the Rebol user's guide for more information. However, looking at the
> /core user's guide (2.2.0), I can't find any mention of how to make a hidden
> object value. Is this possible, and if so, how?
>
> Here's some stuff you might not know about objects:
>>> o: make object! [
> [ A: 1
> [ B: 2
> [ C: 3
> [ ]
>>> first o
> == [self A B C]
>>> second o
> == [
> make object! [
> A: 1
> B: 2
> C: 3
> ] 1 2 3]
>
> By using 'first and 'second, you can access parts of the object.
>
> For hiding stuff in objects, you can use a technique like this:
>
>>> oh/f
> ** Script Error: Invalid path value: f.
> ** Where: oh/f
>>> oh: make object! [
> [ F: none
> [ use [A B] [
> [ A: "AAAA"
> [ B: "BBBB"
> [ set 'F func [] [print [A B]]
> [ ]
> [ ]
>>> probe oh
>
> make object! [
> F: func [][print [A B]]
> ]
>>> oh/f
> AAAA BBBB
>
> BUT! The first use of 'recycle (or allowing the Rebol Garbage Collector to
> function) and then issuing:
>
>>> oh/f
>
> crashes Rebol. Which is annoying. :-(
>
> Andrew Martin
> Environmentally sound Rebol...
> ICQ: 26227169
> http://members.xoom.com/AndrewMartin/
> -><-