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

[REBOL] Re: R: Re: R: Re: switch and datatype

From: rgaither:triad:rr at: 17-Jul-2001 13:04

Hi Max, That sounds great! I would love to have a copy as I'm sure many folks would. Thanks, Rod. Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com] 7/17/2001 11:41:44 AM, "Maxim Olivier-Adlhoch" <[max--ordigraphe--com]> wrote:
>Hi, > >I am not sure I catched this thread correctly (I havent' read the prior >posts, sorry) but I built an object loader/saver/translator three days >ago and it does really nice tricks. > >I convert the object into a tag-list of value and data pairs (the values >being contained in blocks, so as to make the switch word safe to use). > >But the real kicker is that I only save out string, integer and block >data. Any other datatype is ignored. > >I realized that "switch" does not work on datatypes! values so, I simply >did >to-string type? for the switch function to work... as in: > >switch to-string type? :switch-value [ > "integer" [print "integer selected"] > "string" [print "string selected"] > "block" [print "block selected"] >] > >note that the ":" in ":switch-value" is ESSENTIAL! Otherwise, any >function! values are EVALUATED BEFORE returning. > >My code also detects if the values are empty or null (depending on >datatype this will be: "" [] or 0) and only adds them to the tag pair IF >they aren't empty. cause when you'll create the empty object... that's >the value they'll get by default :-)... what's the point in using up >memory for nothing !? > >then If I want to use any value of the tag-pair, I just do: > >value: switch tag-name > >where an example of the tag list's data (as discussed above) looks like: > >[ > "name" ["john doe"] > "age" [31] > "skills" [["carpenter" "programmer" "writter"]] >] > >If anyone is interested in the actual code, (I do not have in with me >:-( I will gladly give-it out. You could add and remove datatypes at >will, to custom tailor it to your needs. I also plan on adding some >refinements like /all to force it to supply all tags even if empty (but >still of appropriate datatype). > >The neat thing is that when storing the object's data using the tag >system above, you can COMPLETELY change the data structure, remove and >even add new fields to an object and NOTHING WILL crash. So improving >one's data and increasing the data in your app isnt too dangerous... as >the objects grow, the new fields just get empty values (and if you >ever -remove- data in an object, it STILL stays safe ;-). It will only >set the tags it recognises in an object and get the tags which actually >have data. transfering data between irrelevent objects is also easy, >since you just transfer matching data from one object to another, and >then (again), only the fields which actually have data (saves space AND >increases speed). > >this system makes it REALLY easy to save and load objects to-from disk. > >Maybe everything I say is common-knowledge, maybe its total alien to >some of you... I don't know yet... as I'm not yet too sure of the level >of the people on the list (I know some of you are far More advanced than >me though... writing proper dialects and stuff like that! (time... >there's never enough of it) > >I just like helping newbies, And its hard to know how much of these are >on the list... which is why some of my posts go a little beyond the >exact thread I reply to. > >CIAO! > >-Max > >> -----Original Message----- >> From: [rebol-bounce--rebol--com] >> [mailto:[rebol-bounce--rebol--com]]On Behalf Of >> Romano Paolo Tenca >> Sent: Monday, July 16, 2001 8:03 PM >> To: [rebol-list--rebol--com] >> Subject: [REBOL] R: Re: R: Re: switch and datatype >> >> >> > Hello Romano! >> > >> > On 06-Lug-01, you wrote: >> >> My answer is a little slow... >> >> > RT> tipo: string! switch to-word mold tipo [string! [print >> > RT> "switched"]] >> > >> > Is there any reason you can't use: >> > >> > tipo: 'string! >> >> yes: because it is calculated >> >> >> > or >> > >> > tipo: type?/word value-to-check >> >> I did not know this refinement! Thank You. It is the same >> answer of RT. >> >> > Also, notice that: >> > >> > >> switch string! ["" [print "A-ha!"]] >> > A-ha! >> >> I know: it is the same with Find, Select >> >> > Regards, >> > Gabriele. >> >> ciao >> romano >> >> -- >> To unsubscribe from this list, please send an email to >> [rebol-request--rebol--com] with "unsubscribe" in the >> subject, without the quotes. >> >> > >-- >To unsubscribe from this list, please send an email to >[rebol-request--rebol--com] with "unsubscribe" in the >subject, without the quotes. >
Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]