{"id":2440,"date":"2022-08-30T15:24:53","date_gmt":"2022-08-30T15:24:53","guid":{"rendered":"https:\/\/unknownerror.org\/index.php\/2014\/01\/12\/erlang-checking-for-unbound-variables-collection-of-common-programming-errors\/"},"modified":"2022-08-30T15:24:53","modified_gmt":"2022-08-30T15:24:53","slug":"erlang-checking-for-unbound-variables-collection-of-common-programming-errors","status":"publish","type":"post","link":"https:\/\/unknownerror.org\/index.php\/2022\/08\/30\/erlang-checking-for-unbound-variables-collection-of-common-programming-errors\/","title":{"rendered":"Erlang &#8211; checking for unbound variables-Collection of common programming errors"},"content":{"rendered":"<p>If you (try to) refer to an unbound variable in an expression, it&#8217;s a compilation error. In particular, after<\/p>\n<pre><code>{ok, After} = ts_dynvars:lookup(last, DynVars),\n<\/code><\/pre>\n<p>there are only two possibilities: if the pattern matches, <code>After<\/code> <em>is<\/em> bound, and can be used; if it doesn&#8217;t, an exception will be thrown, and code which tries to work with <code>After<\/code> will never be executed.<\/p>\n<p>UPDATE:<\/p>\n<blockquote>\n<p>are you telling me there is no way to branch code execution in the situation in which the pattern does not match<\/p>\n<\/blockquote>\n<p>Of course there is:<\/p>\n<pre><code>case ts_dynvars:lookup(last, DynVars) of\n  {ok, After} -&gt; ...;\n  _ -&gt; ... %% or other patterns\nend\n<\/code><\/pre>\n<p>but the compiler won&#8217;t let you use <code>After<\/code> in other branches or after <code>case<\/code> (unless <em>all<\/em> branches bind <code>After<\/code>).<\/p>\n<blockquote>\n<p>is this exception not catchable at all<\/p>\n<\/blockquote>\n<p>It is:<\/p>\n<pre><code>try\n  {ok, After} = ts_dynvars:lookup(last, DynVars),\n  ...\ncatch\n  _:_ -&gt; ...\nend\n<\/code><\/pre>\n<p>but again, you won&#8217;t be able to use <code>After<\/code> in <code>catch<\/code> sections or after <code>try<\/code> ends (you can bind a <em>new<\/em> variable named <code>After<\/code>, of course).<\/p>\n<p id=\"rop\"><small>Originally posted 2014-01-12 20:47:49. <\/small><\/p>","protected":false},"excerpt":{"rendered":"<p>If you (try to) refer to an unbound variable in an expression, it&#8217;s a compilation error. In particular, after {ok, After} = ts_dynvars:lookup(last, DynVars), there are only two possibilities: if the pattern matches, After is bound, and can be used; if it doesn&#8217;t, an exception will be thrown, and code which tries to work with [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[1],"tags":[],"class_list":["post-2440","post","type-post","status-publish","format-standard","hentry","category-uncategorized"],"_links":{"self":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2440","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/comments?post=2440"}],"version-history":[{"count":0,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/posts\/2440\/revisions"}],"wp:attachment":[{"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/media?parent=2440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/categories?post=2440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/unknownerror.org\/index.php\/wp-json\/wp\/v2\/tags?post=2440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}