What's wrong with this equation?

I ran into an issue that looks like a compiler issue involving interpretation of equation formulae:

"Equation Issue"

Place is a room.

When play begins:
	let A be 10;
	let B be 5;
	let c be given by c=(A+2)/(B+1) where c is a number;
	say "c = [c]." 

The Problem message is:

Problem. You wrote ‘let c be given by c= (A+2)/ (B+1) where c is a number’ : but this is a phrase which I don’t recognise, perhaps because it uses brackets ‘(’ and ‘)’ or braces ‘{’ and ‘}’ in a way that doesn’t make sense to me. Each open ‘(’ or ‘{’ has to have a matching ‘)’ or ‘}’.

The same occurs in both 6M62 and 10.1.2.

2 Likes

This isn’t a serious attempt at an answer but could it be related to escaping special characters? There’s a lot of programming languages where /( behaves differently than (, and none of the sample formulas have a denominator in parentheses.

1 Like

It works if you write it with more spaces:

	let c be given by c = (A+2) / (B+1) where c is a number;
3 Likes

Interesting. Is that working as designed?

No idea.

Well, the workaround is good enough for my purposes. Thank you, zarf.

Yeah, the I7 compiler is frequently very finicky about spaces around arithmetic operators, so to avoid frustration I now always try to remember to separate them with a space front and back.

In this case, as it happens, the only change needed from your version is a space before the slash.

I know that’s how it is for normal statements like:

now c is a + 3;

because the + is basically an alternate for plus, but all this time I thought that in the context of an equation spaces weren’t even allowed!

1 Like

I think you’re on to something here, mathbrush. The Problem message does reference the possibility that there are unbalanced parentheses, which implies that one of the parentheses is being read as something else. It also seems that adjacency of the slash and parenthesis are important, because the issue can be bypassed with spacing.

What doesn’t makes sense to me is that putting a space before the slash is the minimum change needed to avoid the error. It seems as though the )/ is being read as a unit instead of the /(.

This definitely doesn’t seem like correct behavior to me, though. I haven’t found anything in the documentation to suggest that a forward slash can be part of any kind of escape sequence.

2 Likes

This also seems to be indicated by the error message, which inserts a space after the / but not before:

Problem. You wrote ‘let c be given by c= (A+2)/ (B+1)

I think this must be simply a compiler bug in the equation-reader, and as a result of it the )/ is not being recognised as a ) followed by a /, hence comments about mismatched brackets.

I’ll report it…

1 Like

It’s not only the / operator, it also fails with -. But it works with + and *.
(A+2)/B fails while A/(B+1) works, so it a problem with )/ and not /(.

I skimmed Equations.w but there’s nothing obvious.
One comment suggests MINUS and DIVIDE are somewhat different: Line 1603

Thanks, I’ve updated the bug report

1 Like