Mailing List Archive: 49091 messages
  • Home
  • Script library
  • AltME Archive
  • Mailing list
  • Articles Index
  • Site search
 

[REBOL] Re: Hack

From: joel:neely:fedex at: 28-Dec-2001 17:50

Hi, again, Sunanda, [SunandaDH--aol--com] wrote:
> On a related subject, I'd like a way to get the name of an object. > Example: > > MyObject: make object! [a: 0 b: 0 c: 0] > MyFunc MyObject > ... > MyFunc: func [obj [Object!]][ > > if error? [obj/a] [ > Print [?? "is missing its 'a' variable"] > ] ; if > ] ;func > > where we replace the "??" with the magic hack to dereference obj > into "MyObject". >
If you really want your objects to have human-readable identities, you can add that easily: MyObject: make object! [ID: "George" a: 0 b: 0 c: 0] MyFunc: func [obj [object!]] [ if error? [obj/a] [ print [obj/ID "is missing its 'a' member"]] ] which also works in the more general, anonymous cases: MyObjects: copy [] MyProto: make object! [ID: "none" a: 0 b: 0 c: 0] repeat i 20 [ append MyObjects make MyProto [ID: join "obj-" i]] foreach ob MyObjects [MyFunc ob] for i 1 20 1 [MyFunc MyObjects/:i]
> ... for precise functional > equivalence, I need to add in the check that Obj is an object. >
Which demonstrates that: 1) REBOL really doesn't support the conventional view of objects very well, since I don't have any way to use the function argument spec to state that I only what a particular *kind* of object... 2) Perhaps the problem could be solved by making sure that MYFUNC never gets called on anything that wasn't created from an appropriate prototype -- but that's a code design issue and (see the previous point) not something that REBOL explicitly supports with language mechanisms. -jn-