>= : 'Didn't think I'd EVER use it for anything. I was wrong.
Phil Pilgrim (PhiPi)
Posts: 23,514
I've publicly disparaged the choice of => for greater-than-or-equal and >= for the seemingly useless "compare the variable with the expression and assign it the result of the comparison". I mean, who would ever use that for anything? It takes a variable with a numerical type and, essentially, changes its type to Boolean.
Well, I've been working on an object for the new S2 (Scribbler II) robot and came up with a use for this obscure operator for the line sensor accessor function. (The line sensors are now analog, BTW, but there's still a need for a line/no-line detector.) Here's what I came up with:
Who'd have thunk it?
-Phil
Well, I've been working on an object for the new S2 (Scribbler II) robot and came up with a use for this obscure operator for the line sensor accessor function. (The line sensors are now analog, BTW, but there's still a need for a line/no-line detector.) Here's what I came up with:
[b]PUB[/b] line_sensor(side, threshold) ' If threshold => 0 ' Return the value of the line sensor on side (LEFT or RIGHT), ' compared to the threshold. (If threshold is zero, substitute 64.) ' Return: false == dark; true == light ' If threshold < 0 ' Return analog value of line sensor. [b]if[/b] (side == LEFT) [b]result[/b] := results[noparse][[/noparse]*ADC_L_LIN] >> 8 [b]elseif[/b] (side == RIGHT) [b]result[/b] := results[noparse][[/noparse]*ADC_R_LIN] >> 8 [b]if[/b] (threshold == 0) [b]result[/b] >= 64 [b]elseif[/b] (threshold > 0) [b]result[/b] >= threshold
Who'd have thunk it?
-Phil
Comments
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Chris Savage
Parallax Engineering
·
I'm surprised that side can equal Left twice
and that result likes the funny face with the big nose.
It makes you wonder what life was like before Boolean.
You have now ruined one of the most infamous of the Prop Gotchas. (Though honestly I love the fact that most of those gotchas exist because of a philosophy of really extreme consistency, which some other platforms could learn a lesson from.)
-Phil
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Jon McPhalen
Hollywood, CA