91
Cyanide
7y

# I wrote an answer, in my exam, about the precedence of operators. Took a random example: "3+4*6", and explained that "*" has higher precedence, so "4*6" would be executed first and so on. Long story short, this was the last line in my answer: "The answer is 27, not 42."

• 3
Why do I have this feeling that i would probably do the same as you did.. ðŸ˜‚
• 0
• 0
@Charon92 Why not? Also, that's not the point of this rant.
• 4
@irene string processing has no room for your "rules of math" :p
• 4
@irene I think evem this is debatable.. saw a discussion a while ago that there are 'different types' of math.. not sure if it was a hoax or not.. was too fucked up to even imagine the other option to be real..
• 2

He could've been talking about boolean algebra, which is just usual algebra rules applied to base 2, with a few twists.

In "3 + 4 * 6", for example, addition would be equivalent to an OR operation because of the "A + 0 = A" identity, and multiplication would be an AND operation because of the "A * 0 = 0" identity. And since there's no precedence in book algebra unless denoted by braces, the equation would evaluate left to right, one result at a time, such that "3 + 4 * 6" would equal 0 ("3 + 4 = 0" and "0 * 6 = 0").

Not sure if this is entirely relevant but bool algebra seems alien enough to some people to the extent they'd say it's "another kind of math", at least to me.
• 1
@GnomoP I think hats why they teach people not to write vague statements and remove any ambuiguity...

The same applies for normal maths - the rules are universal but there can be some ambiguous or implied statements rather than clearly defined, explicitly stated orders.

And then when you get to coding a calculator, if people don't write the code to perform things in the right order.. it also breaks down. Code does what you told it to do, not what you intended. E.g. if someone wrote a function that takes the string as input and just recursively unwraps it from left to right...
• 3
There are languages which evaluate strictly right-to-left or left-to-right. See https://en.m.wikipedia.org/wiki/...
• 2
Smalltalk is one language I have used that evaluates left to right, but thats because it has messages instead of operators.
• 2
@GnomoP never heard of bool algebra & I studied math.. so unless it was discussed after I dropped out or I know it under some other name (language diff + and or and other terminology seems familiar to me under something roughly translated to 'discreete structures' ) I have to google.. but either way that guys discussed elementary school math, so no way we did ^ => and other logical stuff back then..at least not in our schools.
• 1
Lol but 42 is the meaning of life!
• 1
@illusion466
@EventSubscriber
public void onLater(LaterEvent event) {
if(event.time == time.later) { //check against time discontinuation
}
}
• 1
@irene If you're doing infix math in Forth you deserve an award :D
• 1
@irene Postfix with operator precedence ðŸ˜µ
• 1
@irene Implementing a FIFO in Forth? Why, though?
• 1
@irene Now I understand what you meant. I was confused because Forth is based on a LIFO and anything FIFO in Forth seemed rather cumbersome.
• 1
@irene Wouldn't be very useful, unless you specified to what depth the stack should be reversed. Whole-stack reversal sounds like a recipe for unpredictable behaviour.

I just DDW a bit and actually found a proposed infix Forth. Of course, it instantly loses all its simplicity.
http://complang.tuwien.ac.at/anton/...
• 2
I sincerely hope you're talking about The Hitchhikers Guide To The Galaxy. Also - Deep Thought wtf
• 1
@404-js Yes. And yes.
• 2