3 ms·
My guess is that you didn't try @skrishnamurthi suggestion: > Did you try the `sin(pi / 6)` example? You'll find that Pyret produces a rather interesting resul
by epidemian 5y ago
My guess is that you didn't try @skrishnamurthi suggestion:
> Did you try the `sin(pi / 6)` example? You'll find that Pyret produces a rather interesting result that is also instructive.
The result of this doesn't feel like magic and doesn't resemble "JavaScript's truthiness and type coersion" at all IMO.
Here's a live code editor where you can try it out: https://code.pyret.org/editor https://code.pyret.org/editor
I found it to be a very refreshing and intuitively-guiding experience :)
---
Spoiler alert!
So, fist i had to find how to access pi and sin(), which was simple enough googling for documentation. Typing `num-sin(PI / 6)` on he editor already gives an interesting result:
~0.49999999999999994
That ~ there looks suspicious!
Then i tried `num-sin(PI / 6) == 1 / 2`, which seems to be syntactically invalid and yields an awesome error message:
Reading this expression errored:
num-sin(PI / 6) == 1 / 2
The == and / operations are at the same grouping level. Add parentheses to group the operations, and make the order of operations clear.
Kudos to the Pyret team for such a nice error message!
So finally, adding those missing parens, `num-sin(PI / 6) == (1 / 2)`, yields another informative and useful error message:
Attempted to compare a Roughnum to an Exactnum for equality, which is not allowed:
The left side was:
~0.49999999999999994
The right side was:
0.5
Consider using the within function to compare them instead.
All in all, i'm very impressed with the clarity and approachability of the language. Thanks @skrishnamurthi for the suggestion of trying this out! :D
- kazinator 5y agoWhat's the point of an infix syntax that demands obvious. unnnecessary parentheses, as a matter of correctness? "grouping level" is a cringe-inducing dumbing down of proper terminology. It suggests associativity, but associativity does not have levels. It must be referring to "precedence". = and / are not at the same level of precedence in basic mathematics! In elementary school you learn y = x / 2 without requiring parentheses. It makes sense to require parentheses when exotic, unfamiliar operators are involved for which the precedence and associativity would be hard to remember. Not for operators drilled into your head by sixth grade.