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

Removing a field

 [1/4] from: chalz::earthlink::net at: 16-Oct-2004 23:13


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: "1.2.1.3.1 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? Also, if it's not a 'field', what is it called, in REBOL? Thanks. --Charles

 [2/4] from: AJMartin:orcon at: 17-Oct-2004 8:55


Charles wrote:
> Can I delete a field, make it no longer a part of the object?
No, that can't be done currently.
> Also, if it's not a 'field', what is it called, in REBOL?
It's simply a word and the value that the word refers to. --- Andrew Martin ICQ: 26227169 http://www.rebol.it/Valley/ http://valley.orcon.net.nz/ http://valley.150m.com/

 [3/4] 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 []
<<quoted lines omitted: 18>>
>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 [] ]

 [4/4] from: carl:cybercraft at: 17-Oct-2004 9:33


Ladislav provided a work around, and here's another (for simple objects)...
>> msg: third make system/standard/email []
== [To: none CC: none BCC: none From: none Reply-To: none Date: none Subject: none Return-Path: none Organizati on: none Message-Id:...
>> msg: make object! head remove remove find msg to-set-word 'Subject >> probe msg
make object! [ To: none CC: none BCC: none From: none Reply-To: none Date: none Return-Path: none Organization: none Message-Id: none Comment: none X-REBOL: "1.2.1.3.1 http://WWW.REBOL.COM" MIME-Version: none Content-Type: none Content: none ] Subject: gone! -- Carl Read On Saturday, 16-October-2004 at 23:13:41 you wrote,

Notes
  • Quoted lines have been omitted from some messages.
    View the message alone to see the lines that have been omitted