Rehashing Switch

Anything beyond the basics in using the LiveCode language. Share your handlers, functions and magic here.

Moderators: Klaus, FourthWorld, heatherlaine, kevinmiller, robinmiller

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7572
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rehashing Switch

Post by dunbarx » Tue Apr 06, 2021 9:44 pm

Stam.
wouldn't the lack of 'break' break the fall-through from case to case
Not sure what you mean. "Break" must stay and do what it always did, leave the control structure entirely if its case fires. Do you mean if one has a mixed string of cases, with "break" and "continue" sprinkled throughout?

In that case the different gadgetry would have to be carefully ordered, and much of the mindlessness would be lost.

I like the idea of an entirely new structure, that only allows "continue", even if that word is now superfluous, and need not be included at all:

Code: Select all

selectcase
  case 1 = 1
    add 1 to accum
  case 2 = 3
    add 1 to accum
  case 2 = 2
    add 1 to accum
One would get "2".

This is not the same as a switch structure without "break"

Code: Select all

   switch
      case 1 = 1
         add 1 to accum
      case 2 = 3
         add 1 to accum
      case 2 = 2
         add 1 to accum
   end switch
where one gets '3".

Craig

richmond62
Livecode Opensource Backer
Livecode Opensource Backer
Posts: 5590
Joined: Fri Feb 19, 2010 10:17 am
Location: Bulgaria

Re: Rehashing Switch

Post by richmond62 » Wed Apr 07, 2021 7:38 am

and much of the mindlessness would be lost
It probably would, but I have a feeling that morons who want to "program computers"
wouldn't get as far as a switch statement in the first place. 8)

stam
Posts: 335
Joined: Sun Jun 04, 2006 9:39 pm
Location: London, UK

Re: Rehashing Switch

Post by stam » Wed Apr 07, 2021 6:38 pm

All i'm saying is please don't break the current (standard across many languages) switch statement ;)
Diversity is always fun and there's 100 ways to skin a cat 'n' all, so bring in something with a new name rather than break a standard -- my view anyway!

jacque
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 5917
Joined: Sat Apr 08, 2006 8:31 pm
Location: Minneapolis MN
Contact:

Re: Rehashing Switch

Post by jacque » Wed Apr 07, 2021 7:18 pm

I'm afraid I still don't understand why we need a change. Re-ordering the switch statement would give the result Craig wanted. So would one-line "if" statements.

Code: Select all

switch
    case 1 = 1
      add 1 to accum
    case 2 = 2
      add 1 to accum
      break
    case 2 = 3
      add 1 to accum
  end switch
Jacqueline Landman Gay | jacque at hyperactivesw dot com
HyperActive Software | http://www.hyperactivesw.com

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7572
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rehashing Switch

Post by dunbarx » Wed Apr 07, 2021 9:44 pm

Jacque.

it is not having to worry about re-ordering that I think would be the main benefit. Again, I know a little analysis is worth a million lines of code. I wish I knew who said that.

But let us say that the cases are not as explicit as " 2 = 2". What if, and I do this all the time, you have "x = y"? One cannot necessarily know how to order those sorts of things, because the may not lend themselves to analysis:

Code: Select all

switch
  case x = y and a = b
  break
  case x <> y and a > b
  break
  case x < y or a > b
  break
   
It is the ability to lay out totally separate and independent case studies (mmmph, ahem). The order of cases is not important, since each one is evaluated entirely on its own boolean merits, regardless of its position in the flow.

And yes, a string of one-line if statements will do, because, er, each is evaluated entirely independently.

I don't believe it will happen. We can all live without it. But I can dream, can't I?

Craig

bogs
Posts: 5249
Joined: Sat Feb 25, 2017 10:45 pm

Re: Rehashing Switch

Post by bogs » Wed Apr 07, 2021 10:53 pm

dunbarx wrote:
Wed Apr 07, 2021 9:44 pm
But I can dream, can't I?
I dunno, I'd clear it with Mr. Bigglesworth first, cause if Mr. Bigglesworth gets upset, people DIE!
Image

mwieder
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 3238
Joined: Mon Jan 22, 2007 7:36 am
Location: Berkeley, CA, US
Contact:

Re: Rehashing Switch

Post by mwieder » Thu Apr 08, 2021 7:55 pm

Craig-

You're trying to shoehorn *four* variables into a conditional construct that is designed to handle a single one.

dunbarx
VIP Livecode Opensource Backer
VIP Livecode Opensource Backer
Posts: 7572
Joined: Wed May 06, 2009 2:28 pm
Location: New York, NY

Re: Rehashing Switch

Post by dunbarx » Thu Apr 08, 2021 8:52 pm

Mark.

All I originally wanted can be summarized in just about my very first comment on the matter, to have a control structure that would evaluate every single one of an unordered number of conditionals, based strictly on the individual boolean merits of each such conditional.

"Switch" cannot do this at all. A string of separate "if/then" conditionals certainly can, but is not as compact as "switch". Boo Hoo, I know.

And I cannot understand the position that if I just ordered my conditionals nicely, "switch" works just fine. It does not, because however ordered, it will, if using "break", either ignore a valid downStream case, or if not using "break', execute an invalid downStream case.

This has been beaten to a pulp over the two large threads that discussed this.

I just wrote a string of eleven one-line "if/then" lines. Works just fine.:wink:

Craig

Post Reply

Return to “Talking LiveCode”