Properly implemented switch-case would be nice ...

This WebDNA talk-list message is from

2002


It keeps the original formatting.
numero = 41574
interpreted = N
texte = >>If we're going to talk about real programming languages, then why >>is the webdna language missing a [case] function? I use the [case] >>functions all the time in my desktop db programming, but it's still >>not available in webdna ... Why not??? > >It's been available since 4.0. >[Switch Value]Series of [Case]...[/Case] contexts[/Switch] Yeah, I should have said Why is the webdna language missing a PROPERLY IMPLEMENTED or a STANDARD IMPLEMENTATION of the [case] function?Sure, webcat has something named switch-case. But it offers virtually *none* of the functional capabilities of other scripting languages ...First of all, the webdna version of case cannot handle comparisons having different values. In webdna you get to do this:[switch value=a] [case value=[a]] response #1[/case] [case value=[b]] response #2[/case] [case value=[c]] response #3[/case] [default] response #4[/default] [/switch]... which limits one side of the comparison to only one value which is preset to a. And this is FAR MORE LIMITED than in other scripting languages. The following example shows how it is done in other languages and how it could have been implemented in webcat in order to make it far more useful to us:[switch] [case a=b] response #1[/case] [case c=d] response #2[/case] [case e=f] response #3[/case] [default] response #4[/default] [/switch]As you can see in this example, there's no pre-defined value in the switch tag. Instead, each case can accept whatever two values you feel like comparing -- just like individual showif's have always been able to do.The other stupid things the webdna version of switch-case does is to display *all* matching cases instead of only the first one. Hell, if I wanted to display ALL the matching cases, I would use a series of showif's ... :(I really think someone dropped the ball on this feature. After all, the whole concept of case statements in other scripting languages is to select ONLY THE FIRST MATCH from a series of possible matches, and to ignore all other matches.But the way webcat does it is bizarre. Instead of getting only the first match, you get *all* the matching cases -- just like a series of showif's. And if all it's doing is duplicating the capabilities of a series of showif's, then who needs it?Here's an example. When you run this code you get all three responses instead of just the first one, because every case is a match:[text]a=a[/text] [text]b=a[/text] [text]c=a[/text][switch value=a] [case value=[a]] response #1[/case] [case value=[b]] response #2[/case] [case value=[c]] response #3[/case] [default] response #4[/default] [/switch]Yet in other scripting languages you get only response #1 because that is the first match. And other than the added 'default' option, the same thing can be done with this simper showif code:[showif a=[a]] response #1[/showif] [showif a=[b]] response #2[/showif] [showif a=[c]] response #3[/showif]So what is the actual purpose of webcat's implementation of switch-case? Is it only to provide a default option? Here, take a look at the following code and imagine for a moment that your goal is to display only the first matching response to your visitor. If webcat's case-default feature were implemented like it is in other languages, it would produce only ONE matching response out of these 19 different possibilities:[switch value=a] [case value=[b]]response #1[/case] [case value=[c]]response #2[/case] [case value=[d]]response #3[/case] [case value=[e]]response #4[/case] [case value=[f]]response #5[/case] [case value=[g]]response #6[/case] [case value=[h]]response #7[/case] [case value=[i]]response #8[/case] [case value=[j]]response #9[/case] [case value=[k]] [switch value=m] [case value=[n]]response #10-1[/case] [case value=[o]]response #10-2[/case] [case value=[p]]response #10-3[/case] [case value=[q]]response #10-4[/case] [case value=[r]]response #10-5[/case] [case value=[s]]response #10-6[/case] [case value=[t]]response #10-7[/case] [case value=[u]]response #10-8[/case] [default]response #10-9[/default] [/switch] [/case] [default]response #11[/default] [/switch]But webcat's strange implementation will actually display every matching responses. Which means if [b] thru [k] are equal to a and if [n] thru [u] are equal to m, the first 17 responses will be displayed.So how are we to use switch-case to display only the first matching case?I think what we really need is a more standard implementation of switch-case -- one that will display only the FIRST matching case and ignore the rest.SMSI, can you please consider adding an optional match=first parameter to the existing switch-case code? If you ever do this, we will finally have the ability to show only the first matching response, and this is very useful.Of course this will not give switch-case the ability to use more than one value in its comparisons, but that could be an upgrade feature for another time ... right?:) Sincerely, Kenneth Grome--------------------------------------------------- WebDNA Professional Training and Development Center 175 J. Llorente Street +63 (32) 255-6921 Cebu City, Cebu 6000 kengrome@webdna.net Philippines http://www.webdna.net ---------------------------------------------------------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://search.smithmicro.com/ Associated Messages, from the most recent to the oldest:

    
  1. Re: Properly implemented switch-case would be nice ... (Kenneth Grome 2002)
  2. Re: Properly implemented switch-case would be nice ... (Alain Russell 2002)
  3. Re: Properly implemented switch-case would be nice ... (Aaron Lynch 2002)
  4. Properly implemented switch-case would be nice ... (Kenneth Grome 2002)
>>If we're going to talk about real programming languages, then why >>is the webdna language missing a [case] function? I use the [case] >>functions all the time in my desktop db programming, but it's still >>not available in webdna ... Why not??? > >It's been available since 4.0. >[Switch Value]Series of [Case]...[/Case] contexts[/Switch] Yeah, I should have said Why is the webdna language missing a PROPERLY IMPLEMENTED or a STANDARD IMPLEMENTATION of the [case] function?Sure, webcat has something named switch-case. But it offers virtually *none* of the functional capabilities of other scripting languages ...First of all, the webdna version of case cannot handle comparisons having different values. In webdna you get to do this:[switch value=a] [case value=[a]] response #1[/case] [case value=[b]] response #2[/case] [case value=[c]] response #3[/case] [default] response #4[/default] [/switch]... which limits one side of the comparison to only one value which is preset to a. And this is FAR MORE LIMITED than in other scripting languages. The following example shows how it is done in other languages and how it could have been implemented in webcat in order to make it far more useful to us:[switch] [case a=b] response #1[/case] [case c=d] response #2[/case] [case e=f] response #3[/case] [default] response #4[/default] [/switch]As you can see in this example, there's no pre-defined value in the switch tag. Instead, each case can accept whatever two values you feel like comparing -- just like individual showif's have always been able to do.The other stupid things the webdna version of switch-case does is to display *all* matching cases instead of only the first one. Hell, if I wanted to display ALL the matching cases, I would use a series of showif's ... :(I really think someone dropped the ball on this feature. After all, the whole concept of case statements in other scripting languages is to select ONLY THE FIRST MATCH from a series of possible matches, and to ignore all other matches.But the way webcat does it is bizarre. Instead of getting only the first match, you get *all* the matching cases -- just like a series of showif's. And if all it's doing is duplicating the capabilities of a series of showif's, then who needs it?Here's an example. When you run this code you get all three responses instead of just the first one, because every case is a match:[text]a=a[/text] [text]b=a[/text] [text]c=a[/text][switch value=a] [case value=[a]] response #1[/case] [case value=[b]] response #2[/case] [case value=[c]] response #3[/case] [default] response #4[/default] [/switch]Yet in other scripting languages you get only response #1 because that is the first match. And other than the added 'default' option, the same thing can be done with this simper showif code:[showif a=[a]] response #1[/showif] [showif a=[b]] response #2[/showif] [showif a=[c]] response #3[/showif]So what is the actual purpose of webcat's implementation of switch-case? Is it only to provide a default option? Here, take a look at the following code and imagine for a moment that your goal is to display only the first matching response to your visitor. If webcat's case-default feature were implemented like it is in other languages, it would produce only ONE matching response out of these 19 different possibilities:[switch value=a] [case value=[b]]response #1[/case] [case value=[c]]response #2[/case] [case value=[d]]response #3[/case] [case value=[e]]response #4[/case] [case value=[f]]response #5[/case] [case value=[g]]response #6[/case] [case value=[h]]response #7[/case] [case value=[i]]response #8[/case] [case value=[j]]response #9[/case] [case value=[k]] [switch value=m] [case value=[n]]response #10-1[/case] [case value=[o]]response #10-2[/case] [case value=[p]]response #10-3[/case] [case value=[q]]response #10-4[/case] [case value=[r]]response #10-5[/case] [case value=[s]]response #10-6[/case] [case value=[t]]response #10-7[/case] [case value=[u]]response #10-8[/case] [default]response #10-9[/default] [/switch] [/case] [default]response #11[/default] [/switch]But webcat's strange implementation will actually display every matching responses. Which means if [b] thru [k] are equal to a and if [n] thru [u] are equal to m, the first 17 responses will be displayed.So how are we to use switch-case to display only the first matching case?I think what we really need is a more standard implementation of switch-case -- one that will display only the FIRST matching case and ignore the rest.SMSI, can you please consider adding an optional match=first parameter to the existing switch-case code? If you ever do this, we will finally have the ability to show only the first matching response, and this is very useful.Of course this will not give switch-case the ability to use more than one value in its comparisons, but that could be an upgrade feature for another time ... right?:) Sincerely, Kenneth Grome--------------------------------------------------- WebDNA Professional Training and Development Center 175 J. Llorente Street +63 (32) 255-6921 Cebu City, Cebu 6000 kengrome@webdna.net Philippines http://www.webdna.net ---------------------------------------------------------------------------------------------------------------- This message is sent to you because you are subscribed to the mailing list . To unsubscribe, E-mail to: To switch to the DIGEST mode, E-mail to Web Archive of this list is at: http://search.smithmicro.com/ Kenneth Grome

DOWNLOAD WEBDNA NOW!

Top Articles:

Talk List

The WebDNA community talk-list is the best place to get some help: several hundred extremely proficient programmers with an excellent knowledge of WebDNA and an excellent spirit will deliver all the tips and tricks you can imagine...

Related Readings:

WebCatalog stalls (1998) TPC Connect (1999) TCP Connect/send and CGI (2003) search results not sorted with 'cl' (1998) [if] (2003) WebCat2b13MacPlugIn - [include] (1997) Help! WebCat2 bug (1997) Behind the Scenes. . . (1998) One Hour Email (2002) restarting service remotely on NT (1997) More than 2 sort specs? (2003) Where's Cart Created ? (1997) Dubble Sku's in a Database (1999) Trouble with formula.db (1997) MATH PROBLEM (1997) Re:mac hack (1997) [click][/click] (1999) Adding up line items. (2000) WebCatalog 2.0 & WebDNA docs in HTML ... (1997) Associative lookup style? + bit more (1997)