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

[REBOL] Re: Removing a field

From: lmecir:mbox:vol:cz at: 17-Oct-2004 9:37

Charles napsal(a):
> Here's a little question. Suppose I do something like >msg: make system/standard/email [] >probe msg >make object! [ > To: none > CC: none > BCC: none > From: none > Reply-To: none > Date: none > Subject: none > Return-Path: none > Organization: none > Message-Id: none > Comment: none > X-REBOL: " http://WWW.REBOL.COM" > MIME-Version: none > Content-Type: none > Content: none >] > >Suppose I wish to remove a field, like Comment or X-REBOL. How would I do >that? Can I ... delete a field, make it no longer a part of the object? >
you cannot remove a field (I call it attribute) from an existing object, but you can create a new object having only the attributes you really need e.g. as follows: o: make object! [a: 1 b: 2 c: 3] o: exclude-attributes o [a b] the EXCLUDE-ATTRIBUTES function is an "easy exercise for the reader" :-) -Ladislav P.S. here is my homework: exclude-attributes: func [ {exclude some attributes} original [object!] {the original object} attributes [block!] {attributes to exclude} /local new-spec to-set result ] [ ; exclude the 'spec word new-spec: exclude first original [self] ; exclude other attributes new-spec: exclude new-spec attributes ; remember attributes that need to be set to-set: copy new-spec repeat i length? new-spec [poke new-spec i to set-word! new-spec/:i] insert tail new-spec none ; create an empty new object result: make object! new-spec ; set the attributes in result foreach attribute to-set [type? set/any bind attribute in result 'self get/any bind attribute in original 'self] ; make sure to obtain copies where appropriate make result [] ]