Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Compiled SWITCH does not honor multiple case values #611

Closed
hostilefork opened this issue Dec 15, 2013 · 4 comments
Closed

Compiled SWITCH does not honor multiple case values #611

hostilefork opened this issue Dec 15, 2013 · 4 comments
Assignees
Labels
status.built A change in codebase has been done to address the ticket. status.tested The change in code has been manually tested and verified to fix the issue. type.review Ticket describes a possible improvement.
Milestone

Comments

@hostilefork
Copy link

In the Red interpreter (and in Rebol) you get "x is either a one or a two" if you write:

x: 2
switch x [
    1 2 [print "x is either a one or a two"]
]

But if you use Red's -c option to compile this code, it will not print anything. Changing x to 1 will print the message, however.

Using "0.4.1, 13-Dec-2013/23:19:35-5:00"

@dockimbel
Copy link
Member

Multiple keys in switch are not currently supported in the compiler. The issue is the handling of the blocks-as-keys cases, they are currently supported by the compiler, but they prevent the multiple keys support then because the compiler cannot statically determine which values are keys and which ones are action blocks.

I really want to support multiple keys in the compiler too, so I think that we'll change the tradeoff and not allow block-as-key in the compiler. If the user really needs it, he will just wrap the switch in a do [...] block and let the interpreter handle it at runtime.

@hostilefork
Copy link
Author

Changing the bias sounds like a plan, but I don't think the compiler and interpreter should have different semantics. If the compiler rejects something the interpreter will allow, then that may just be the answer to this kind of situation.

@dockimbel
Copy link
Member

Sure, we don't want to have different semantics, but we'll encounter such cases that will be resolved one by one as we progress towards 1.0.

There is a not-yet-implemented last-resort fallback strategy for the compiler when facing not statically analyzable code: invoke the interpreter on the code instead of trying to compile it. But the cost can be very high as from that code position, everything until the current block tail will be interpreted (as we can't statically determine where an expression ends if we can't analyze it at compilation time).

@iArnold
Copy link
Contributor

iArnold commented Feb 15, 2015

I suggested /block refinement for the blocks-as-key handling. @ dockimbel countered this with /only refinement as option. Personally I feel /only says little about the way in which the handling differs, /block is more descriptive.
There could be also an alternative for switch with blocks-as-key: 'FORK

I want to mention some other point to the 'switch and that is I like Red/System way of dealing with the default better than the /default Red and Rebol are using.

I sincerely hope this issue will be fixed soon, since my projectcode makes heavily use of these multiple case situations and the rewriting makes them unpretty code.

@dockimbel dockimbel removed the Red label Mar 27, 2016
@dockimbel dockimbel added this to the 0.6.1 milestone May 10, 2016
@dockimbel dockimbel self-assigned this May 10, 2016
@dockimbel dockimbel modified the milestones: 0.6.1, 0.6.2 Jun 29, 2016
@dockimbel dockimbel added status.built A change in codebase has been done to address the ticket. status.tested The change in code has been manually tested and verified to fix the issue. and removed status.reviewed Ticket has been reviewed and accepted for further processing. labels Jul 23, 2016
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status.built A change in codebase has been done to address the ticket. status.tested The change in code has been manually tested and verified to fix the issue. type.review Ticket describes a possible improvement.
Projects
None yet
Development

No branches or pull requests

3 participants