<story><title>Show HN: Awk-JVM – A toy JVM in Awk</title><url>https://github.com/rethab/awk-jvm</url></story><parent_chain><item><author>rethab</author><text>Author here.&lt;p&gt;As I wrote in the README, this uses GAWK instead of plain AWK. Conveniences of GAWK over AWK in a nutshell:
- functions
- several additional functions (eg. bit shifting)&lt;p&gt;But even GAWK lacks some things that are very common in other languages:
- no variable scope: imagine a calling another function in a for loop and the other function again running a for loop. if both loops use &amp;#x27;i&amp;#x27; as the counter, good luck. the workaround for this is to declare the local variables as parameters that are not passed (and separate them with four spaces) 
- cannot return array from a function. the workaround is to use pass-by-reference (not sure if the precise definition is applicable here)
- arrays cannot be assigned to another variable. workaround is to loop over array and assign it value by value.&lt;p&gt;If anybody knows better workarounds, please let me know :)</text></item></parent_chain><comment><author>wahern</author><text>It might be useful to provide an example using POSIX od(1) instead of hexdump(1). hexdump is actually a BSD utility. The Debian Linux version is ported from FreeBSD, while the Red Hat version is a pale imitation provided as a wrapper, IIRC, around the od implementation.[1] `od -An -tu1 -v` should suffice.&lt;p&gt;[1] I wrote a single-file hexdump implementation so know far too much about it: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;25thandclement.com&amp;#x2F;~william&amp;#x2F;projects&amp;#x2F;hexdump.c.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;25thandclement.com&amp;#x2F;~william&amp;#x2F;projects&amp;#x2F;hexdump.c.html&lt;/a&gt;</text></comment>
<story><title>Show HN: Awk-JVM – A toy JVM in Awk</title><url>https://github.com/rethab/awk-jvm</url></story><parent_chain><item><author>rethab</author><text>Author here.&lt;p&gt;As I wrote in the README, this uses GAWK instead of plain AWK. Conveniences of GAWK over AWK in a nutshell:
- functions
- several additional functions (eg. bit shifting)&lt;p&gt;But even GAWK lacks some things that are very common in other languages:
- no variable scope: imagine a calling another function in a for loop and the other function again running a for loop. if both loops use &amp;#x27;i&amp;#x27; as the counter, good luck. the workaround for this is to declare the local variables as parameters that are not passed (and separate them with four spaces) 
- cannot return array from a function. the workaround is to use pass-by-reference (not sure if the precise definition is applicable here)
- arrays cannot be assigned to another variable. workaround is to loop over array and assign it value by value.&lt;p&gt;If anybody knows better workarounds, please let me know :)</text></item></parent_chain><comment><author>mzs</author><text>Nice project! It&amp;#x27;s only very old awks that don&amp;#x27;t support functions (like BSD awk does and nawk does on SunOS but &amp;#x2F;usr&amp;#x2F;bin&amp;#x2F;awk doesn&amp;#x27;t) and the GNU docs have an implementation of strtonum: &lt;a href=&quot;https:&amp;#x2F;&amp;#x2F;www.gnu.org&amp;#x2F;software&amp;#x2F;gawk&amp;#x2F;manual&amp;#x2F;html_node&amp;#x2F;Strtonum-Function.html&quot; rel=&quot;nofollow&quot;&gt;https:&amp;#x2F;&amp;#x2F;www.gnu.org&amp;#x2F;software&amp;#x2F;gawk&amp;#x2F;manual&amp;#x2F;html_node&amp;#x2F;Strtonum-...&lt;/a&gt;</text></comment>