1. switch statement - case doesn't accept sequence elements?

Is this a bug? Cannot use a sequence element for the 'case' comparison.

constant numbers = {34553, 235452} 
 
procedure CheckNum(atom number) 
 
	switch number do 
		case numbers[1] then 
			puts(1,"Base location\n") 
		case numbers[2] then 
			puts(1,"Second location\n") 
	end switch 
	 
end procedure 
 
CheckNum(34553) 

crashes with:


C:\...\test.ex:6
<0066>:: expected 'then' or ',', not '['
case numbers[1] then
^


Press Enter

this, of course, works:

sequence numbers = {34553, 235452} 
 
procedure CheckNum(atom number) 
 
	switch number do 
		case 34553 then 
			puts(1,"Base location\n") 
		case 235452 then 
			puts(1,"Second location\n") 
	end switch 
	 
end procedure 
 
CheckNum(34553) 
new topic     » topic index » view message » categorize

2. Re: switch statement - case doesn't accept sequence elements?

evanmars said...

Is this a bug? Cannot use a sequence element for the 'case' comparison.

According to the manual, "The <val> in a case must be either an atom, literal string, constant or enum." I guess "atom" doesn't mean an element of a sequence that happens to be an atom? I have run into this as well, except i was trying to use an element of a sequence that was a string. I had to use an if statement in cases like this.

new topic     » goto parent     » topic index » view message » categorize

3. Re: switch statement - case doesn't accept sequence elements?

ryanj said...
evanmars said...

Is this a bug? Cannot use a sequence element for the 'case' comparison.

According to the manual, "The <val> in a case must be either an atom, literal string, constant or enum." I guess "atom" doesn't mean an element of a sequence that happens to be an atom? I have run into this as well, except i was trying to use an element of a sequence that was a string. I had to use an if statement in cases like this.

It should probably say 'literal number' instead of atom. You can't use variables in case statements, period.

new topic     » goto parent     » topic index » view message » categorize

4. Re: switch statement - case doesn't accept sequence elements?

jimcbrown said...
ryanj said...
evanmars said...

Is this a bug? Cannot use a sequence element for the 'case' comparison.

According to the manual, "The <val> in a case must be either an atom, literal string, constant or enum." I guess "atom" doesn't mean an element of a sequence that happens to be an atom? I have run into this as well, except i was trying to use an element of a sequence that was a string. I had to use an if statement in cases like this.

It should probably say 'literal number' instead of atom. You can't use variables in case statements, period.

I see. What is the reason for that? Improved performance over an if statement?

new topic     » goto parent     » topic index » view message » categorize

Search



Quick Links

User menu

Not signed in.

Misc Menu