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

[REBOL] inserting new properties into existing objects

From: james::mustard::co::nz at: 22-Nov-2002 12:04

In the following example below the intention is to create a series of base fish objects and then extend one of them in the most efficient possible way. I have used a function for the base class and also a food class. After this I have modified onefish by reassigning it a modified clone of itself. Something similar was done to onefish's first food source. My question is this, apart from cloning+extending is there a faster/more efficient way to make new properties and assign them values? (especially if I have a 1024x768 image of each fish stored with data..) food: func [f-food [string!]][ make object! copy [ foodname: f-food ] ] fish: func [f-grade [string!] f-species [string!] f-foods [block!]][ make object! copy/deep [ size: f-grade species: f-species favourite-foods: copy [] foreach f f-foods [ append favourite-foods food f ] ] ] onefish: fish "X-Large" "Mackeral" ["krill" "smaller fish"] twofish: fish "Large" "Cod" ["slow fish"] redfish: fish "Medium" "Snapper" ["blue cod"] bluefish: fish "Small" "Bluefin Tuna" ["fish"] probe onefish ;purpose to add 2 new properties to onefish onefish: make onefish [area: "5a" taste: "A-Grade"] probe onefish onefish/favourite-foods/1: make onefish/favourite-foods/1 [decay-time: forever ] probe onefish halt