switch and datatype
[1/8] from: rotenca::telvia::it at: 6-Jul-2001 21:50
Switch can make switch datatype? I can't make it work:
>> tipo: string! switch tipo [ string! [print "switched"]]
== none --- Saluti Romano Paolo Tenca
[2/8] from: sterling:rebol at: 6-Jul-2001 13:18
The issue is that [string!] in a block is actually a word: type? first [string!] == word! Do either: switch type?/word "a string" [ string! [print #switched] ] or switch string! reduce [ string! [print #switched] ] The first is better because it does not have to reduce this possibly large block. Sterling
[3/8] from: rotenca:telvia:it at: 6-Jul-2001 23:02
> The issue is that [string!] in a block is actually a word: > type? first [string!] > == word!
> Do either: > switch type?/word "a string" [ > string! [print #switched] > ]
The only method i've found: tipo: string! switch to-word mold tipo [string! [print "switched"]]
> or > switch string! reduce [ > string! [print #switched] > ]
tipo: string! switch tipo compose [ (reduce string!) [print "switched"]]
> The first is better because it does not have to reduce this possibly > large block.
Compose reduce a little.
ciao (my english is bad) romano paolo tenca
[4/8] from: g:santilli:tiscalinet:it at: 7-Jul-2001 14:52
Hello Romano! On 06-Lug-01, you wrote: RT> tipo: string! switch to-word mold tipo [string! [print RT> "switched"]] Is there any reason you can't use: tipo: 'string! or tipo: type?/word value-to-check RT> tipo: string! switch tipo compose [ (reduce string!) [print RT> "switched"]] You can remove the REDUCE here. RT> Compose reduce a little. Hmm... I don't this it will be any faster (slower, maybe). Anyway, you'll usually do this only once so this is not a problem. Also, notice that:
>> switch string! ["" [print "A-ha!"]]
A-ha! which is probably simples, provided you're dealing with types that can be represented literally (lexically?). Regards, Gabriele. -- Gabriele Santilli <[giesse--writeme--com]> - Amigan - REBOL programmer Amiga Group Italia sez. L'Aquila -- http://www.amyresource.it/AGI/
[5/8] from: rotenca:telvia:it at: 17-Jul-2001 2:02
> 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.
[6/8] from: max:ordigraphe at: 17-Jul-2001 11:41
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"  "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
[7/8] 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
<<quoted lines omitted: 109>>>[rebol-request--rebol--com] with "unsubscribe" in the >subject, without the quotes.
Rod Gaither Oak Ridge, NC - USA [rgaither--triad--rr--com]
[8/8] from: max:ordigraphe at: 18-Jul-2001 11:44
hi Rod and others who responed, Interest there IS, so FILES there will be :-) I am in the process of buiding my reb site and will push the files there. It should all be done before the end of friday. I'll fix up the files into a tidy distribution and push this on the list... as I improve them, I'll just post a little note. I'll also build a little demo applet which shows how to use the tools. be prepared for a shit load of stuff... I will even post EPIC. An extremely easy to use web page builder... by easy, I mean, you gran'ma will be able to build pages... ;-) its a natural-language driven almost syntax-free system. its still at version one but if there is interest, I have a four page document about how I can improve it, with one feature per line... 'till next time, 10-4 -Max
- Quoted lines have been omitted from some messages.
View the message alone to see the lines that have been omitted