TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

An Erlang WAT-story about guards and guards

52 pointsby elbrujohalconalmost 9 years ago

5 comments

yetihehealmost 9 years ago
In erlang 'and' has higher priority than comparisons. So 'is_integer(X) and X > 0' is interpreted as '(is_integer(X) and X) > 0'. 'andalso' has lower priority than comparisons so it is interpreted as we expect.
njharmanalmost 9 years ago
I really don&#x27;t understand the aversion?, lack of use? of parenthesis. Back in college (before C++ was released to give you time scale) some C class, spent a lot of time on operator precedence. I was like, why bother? Just use parens, be explicit, clear and never ever have to learn or be bit by any language&#x27;s precedence ever!<p>Ever.
pepeszaalmost 9 years ago
Just FYI. Brujo is close to being expert in Erlang. This post is a more of a &quot;warning for juniors&quot; than &quot;damn, today I&#x27;ve discovered something new&quot;.<p>And there is nothing really WAT about it. Just part of rather simple Erlang language grammar.
评论 #12050032 未加载
评论 #12048956 未加载
评论 #12050018 未加载
Lucalmost 9 years ago
I always use &#x27;,&#x27; and &#x27;;&#x27; in guards. Maybe I&#x27;m weird but it feels wrong using the short-circuit operators knowing that guards are always short-circuited anyway. Also they take up too much space :)
评论 #12049829 未加载
chriswarboalmost 9 years ago
Reminded me of `and`, `or`, etc. precedence in PHP, e.g. <a href="http:&#x2F;&#x2F;php.net&#x2F;manual&#x2F;en&#x2F;language.operators.precedence.php#117390" rel="nofollow">http:&#x2F;&#x2F;php.net&#x2F;manual&#x2F;en&#x2F;language.operators.precedence.php#1...</a>