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

[REBOL] Re: Unable to use Switch and Datatypes..

From: jelinem1:nationwide at: 7-May-2001 11:12

Verified the problem here - that behavior doesn't seem right. Some simple testing:
>> some-type: word!
== word!
>> switch/default some-type [word! [print "ok"]][print "not ok"]
ok
>> some-type: type? 'aword
== word!
>> switch/default some-type [word! [print "ok"]][print "not ok"]
not ok Seems like the literal word! doesn't match to the return of 'type?. To support this, see below. Note that the return of 'type? is forced into the case section of the switch, and it works:
>> case1: [x [print "ok"]]
== [x [print "ok"]]
>> change case1 type? 'aword
== [[print "ok"]]
>> print mold case1
[word! [print "ok"]]
>> switch/default type? 'aword case1 [print "not ok"]
ok Looks like a bug to me. As a work-around, if you don't want to violate your case-statements like that, you could 'form or 'mold the results of 'type? and use strings for the comparisons (yeah it's kinda strange, but 'mold returns a string on datatypes). - Michael Jelinek Scott Dunlop <[scott--dunlop--home--com]>@rebol.com on 05/07/2001 09:07:30 AM From: Scott Dunlop <[scott--dunlop--home--com]>@rebol.com on 05/07/2001 09:07 AM Please respond to [rebol-list--rebol--com] Sent by: [rebol-bounce--rebol--com] To: [rebol-list--rebol--com] cc: Subject: [REBOL] Unable to use Switch and Datatypes.. Is this a bug or a feature? The following code, which I would expect to generate 'A word is a word.', outputs 'A word is not always a word.', indicating that word! is not equivalent to word! for the purposes of switch. This also appears to be the case with the string! datatype. The interesting thing is that [word! == word!] returns true. switch/default type? 'aWord [ word! [ print "a word is a word."] ] [ print "A word is not always a word." ] Thanks in advance for any suggestions people have for working around this, aside from a long chain of Either statements.. --Scott.