A stab at the sealer in E
Ka-Ping Yee
ping@lfw.org
Tue, 2 Nov 1999 19:44:55 -0800 (PST)
On Tue, 2 Nov 1999, Chip Morningstar wrote:
> Ping ventures:
> > define BrandMaker make(name) {
> > ...
> > }
>
> Now, for an extra 5 points, can you do it *without* using object EQ (or
> random numbers)?
Yeah, like this:
define BrandMaker make(name) {
define table := [] # I don't know how to make an empty Map.
define sealer {
to seal(contents) : any {
define envelope { }
table[envelope] := contents
envelope
}
}
define unsealer {
to unseal(envelope) : any {
if table has(envelope) {
table[envelope]
}
else {
throw(UnsealingException(
"envelope not sealed by matching sealer"))
}
}
}
[sealer, unsealer]
}
... although i suppose you could call it cheating because it
still uses object identity. Happily, however, i think it does
not fall prey to the attack described in MarkM's other message.
-- ?!ng