On Thursday, January 14, 2021 at 7:27:15 PM UTC+1, K.S. Bhaskar wrote:
I prefer the DO M command:
DO ONE:a=1,TWO:a=2
...
Better yet:
IF a=1 DO ONE
ELSE IF a=2 DO TWO
ELSE DO ELSE
I know that many people don't like indirection, but the M[UMPS]y way of doing this would be:
in the initialization:
Set Goto(1)="ONE",Goto(2)="TWO"
and in the actual "switch":
Goto @$Get(Goto(a),"ELSE")
Given the ideas about GOTO, a
Do @$Get(Goto(a),"ELSE")
might be preferable.
(Of course, I'm assuming here that variable a would never have an empty value).
In article <b02a86ba-f8bb-4eb7...@googlegroups.com>,
Mark Dawson <mark.r...@gmail.com> wrote:
...To defend against the subroutine not preserving $TEST one should write it as IF a=1 DO ONE IF 1
Better yet:
IF a=1 DO ONE
ELSE IF a=2 DO TWO
ELSE DO ELSE
ELSE IF a=2 DO TWO IF 1
--
-- Rod --
rodd(at)polylogics(dot)com
I know that many people don't like indirection, but the M[UMPS]y way of doing this would be:
in the initialization:
Set Goto(1)="ONE",Goto(2)="TWO"
and in the actual "switch":
Goto @$Get(Goto(a),"ELSE")
Given the ideas about GOTO, a
Do @$Get(Goto(a),"ELSE")
might be preferable.
(Of course, I'm assuming here that variable a would never have an empty value).
The benefit of the switch statement and the M analog is single entry to a block of code at the top (the GOTO statement) and a single exit (the DONE label) at the bottom. If you use DO, you either have to add GOTOs to get to the end of the block, or youhave blocks of code scattered around, and the reader loses the contextual locality. IMHO, the next best alternative is IF … ELSE IF … ELSE which loses a little readability, but has the single entry + single exit benefit.
Interestingly, you doesn't said anything about further evolving of M. Regards,
Julius
<snip>
My understanding is that the value of $TEST is preserved when invoking another procedure via a DO command (as well as an argumentless DO or function call) -- it's put onto the stack and comes off again when processing returns.
Is that not the case?
Why does C need a switch statement, when the same logic can be implemented with if…then…else? The reason is that the switch statement is more readable.
Maury said: "...You can NEW $T..." on January 16.
No, that is not Standard.
--George
On 1/23/2021 3:08 PM, George Timson wrote:I proposed a new language, MSH, which eliminates many of the problems of the M language. It does not require indirection, while maintaining the capabilities of this design. Introduced the CASE command, I believe that this command is necessary in the
Maury said: "...You can NEW $T..." on January 16.
No, that is not Standard.
--George
Sorry, my oversight. I should have said that it is in the MDC draft standard but, in fact, is already implemented in some of the current versions in the field. Verify it works with your version before assuming it does.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 399 |
Nodes: | 16 (2 / 14) |
Uptime: | 39:34:57 |
Calls: | 8,336 |
Calls today: | 13 |
Files: | 13,155 |
Messages: | 5,891,234 |
Posted today: | 1 |