<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Nim on Roads Less Taken</title><link>https://goran.krampe.se/categories/nim/</link><description>Recent content in Nim on Roads Less Taken</description><generator>Hugo</generator><language>en</language><lastBuildDate>Wed, 21 Apr 2021 00:00:00 +0000</lastBuildDate><atom:link href="https://goran.krampe.se/categories/nim/index.xml" rel="self" type="application/rss+xml"/><item><title>Spry Error Handling</title><link>https://goran.krampe.se/2021/04/21/spry-error-handling/</link><pubDate>Wed, 21 Apr 2021 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2021/04/21/spry-error-handling/</guid><description>&lt;p>Work on &lt;a href="https://sprylang.se" target="_blank" rel="noopener noreferrer">Spry&lt;/a>
 continues&amp;hellip; in small spurts. :) One thing that I have pushed ahead of me for far too long is &lt;strong>error handling&lt;/strong>. People interested in Spry have been asking about it and yes, I decided to start getting a handle on it.&lt;/p>
&lt;p>In fact, I wrote this article &lt;strong>last year&lt;/strong> but forgot to get it done and published!&lt;/p>
&lt;p>Error handling is an interesting topic, earlier it wasn&amp;rsquo;t really much controversy around it but the advent of new techniques (Optionals etc) in combination with languages making&amp;hellip; &amp;ldquo;interesting&amp;rdquo; choices (I am looking at you Go) has made this subject fairly hot. So what do we want in Spry??&lt;/p></description></item><item><title>Revisiting Spry</title><link>https://goran.krampe.se/2020/06/05/revisiting-spry/</link><pubDate>Fri, 05 Jun 2020 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2020/06/05/revisiting-spry/</guid><description>&lt;p>After a period of slower progress I got reignited regarding &lt;a href="https://sprylang.se" target="_blank" rel="noopener noreferrer">Spry&lt;/a>
. So far I have written &lt;a href="http://goran.krampe.se/categories/spry/" target="_blank" rel="noopener noreferrer">a lot of articles&lt;/a>
 about Spry, and during this time things have evolved and changed.&lt;/p>
&lt;p>So I am now trying to &amp;ldquo;clean house&amp;rdquo; on where Spry stands today. This sweep through the old articles is a first step, then I will update the language manual to be 100% in sync with the implementation.&lt;/p>
&lt;p>Let&amp;rsquo;s go through the articles from the beginning!&lt;/p></description></item><item><title>Writing Arduinobot in Nim</title><link>https://goran.krampe.se/2017/10/26/writing-arduinobot-in-nim/</link><pubDate>Thu, 26 Oct 2017 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2017/10/26/writing-arduinobot-in-nim/</guid><description>&lt;p>In the &lt;a href="https://project.ecraft2learn.eu/" target="_blank" rel="noopener noreferrer">eCraft2Learn project&lt;/a>
 which Evothings is participating in we were looking at various ways
&lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 is an awesome programming language and this article is a &lt;strong>whirlwind-copy-paste-into-your-terminal-as-you-read-thing&lt;/strong> to show how you install Nim, write a small program, compile it and package it in a very short time.&lt;/p>
&lt;p>To spice it up, for &lt;strong>no specific reason at all&lt;/strong>, we are doing it all inside a &lt;a href="http://linuxcontainers.org" target="_blank" rel="noopener noreferrer">Linux Container&lt;/a>
 - a fast virtual environment to work in. It&amp;rsquo;s just a nice way to have a clean environment and to ensure that you as a reader see the same results as I do.&lt;/p></description></item><item><title>Nim crash course in LXC</title><link>https://goran.krampe.se/2017/10/24/nim-crash-course-inside-lxc/</link><pubDate>Tue, 24 Oct 2017 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2017/10/24/nim-crash-course-inside-lxc/</guid><description>&lt;p>&lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 is an awesome programming language and this article is a &lt;strong>whirlwind-copy-paste-into-your-terminal-as-you-read-thing&lt;/strong> to show how you install Nim, write a small program, compile it and package it in a very short time.&lt;/p>
&lt;p>To spice it up, for &lt;strong>no specific reason at all&lt;/strong>, we are doing it all inside a &lt;a href="http://linuxcontainers.org" target="_blank" rel="noopener noreferrer">Linux Container&lt;/a>
 - a fast virtual environment to work in. It&amp;rsquo;s just a nice way to have a clean environment and to ensure that you as a reader see the same results as I do.&lt;/p></description></item><item><title>Benchmarking Spry vs Squeak</title><link>https://goran.krampe.se/2016/08/26/benchmarking-spry-vs-squeak/</link><pubDate>Fri, 26 Aug 2016 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2016/08/26/benchmarking-spry-vs-squeak/</guid><description>&lt;p>&lt;a href="http://sprylang.org" target="_blank" rel="noopener noreferrer">Spry&lt;/a>
 is evolving quite nicely during my night hours. Focusing on performance is however still premature, but I do want to verify that I am not barking up the wrong tree, like &amp;hellip; in the wrong forest even. So I make trivial benchmarks from time to time, just to see and learn.&lt;/p>
&lt;p>Some background on the Spry implementation may be interesting. Spry is implemented in Nim as a &lt;strong>direct AST interpreter&lt;/strong>, it&amp;rsquo;s not a JIT, in only about 2000 lines of code. It has a &lt;strong>recursive classic &amp;ldquo;naive&amp;rdquo; design&lt;/strong> and uses a &lt;strong>spaghetti stack of activation records&lt;/strong>, all allocated on the heap relying fully on Nim&amp;rsquo;s GC to do it&amp;rsquo;s work. It also relies on Nim&amp;rsquo;s method &lt;strong>dynamic dispatch&lt;/strong> in the interpreter loop for dispatching on the different AST nodes. Blocks are true closures and control structures like &lt;code>timesRepeat:&lt;/code> are implemented as primitives, normally &lt;strong>not cheating&lt;/strong>. Suffice to say, there are LOTS of things we can do to make Spry run faster!&lt;/p>
&lt;p>The philosophy of implementation is to keep Spry very small and &amp;ldquo;shallow&amp;rdquo; which means we rely as much as possible on the shoulders of others. In this case, primarily Nim and it&amp;rsquo;s superb features, performance and standard library.&lt;/p>
&lt;p>Enough jibbering, let&amp;rsquo;s do some silly damn lies - ehrm, I mean silly tests!&lt;/p></description></item><item><title>Spry Performance</title><link>https://goran.krampe.se/2016/05/24/spry-performance/</link><pubDate>Tue, 24 May 2016 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2016/05/24/spry-performance/</guid><description>&lt;p>When writing Spry I am so far mainly ignoring performance. The general execution of Spry code will be a regular interpreter (although stackless I hope) and not a JIT. But that doesn&amp;rsquo;t prevent us from playing around and learning something!&lt;/p>
&lt;p>In this article I do some silly experiments around interpreter startup time and fooling around with 40 million element arrays. As usual, I am fully aware that the languages (Pharo Smalltalk, NodeJS, Python) I compare with a) have lots of other ways to do things b) may not have been used exactly as someone else would have done it. A truck load of salt required. Now&amp;hellip; let&amp;rsquo;s go!&lt;/p>
&lt;img src="https://goran.krampe.se/spry/thetruth.jpg" alt="The" style="display:block; margin:0 auto;"></description></item><item><title>Nim meets Arduino</title><link>https://goran.krampe.se/2016/02/25/nim-meets-arduino/</link><pubDate>Thu, 25 Feb 2016 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2016/02/25/nim-meets-arduino/</guid><description>&lt;p>I now work as the Team Lead at &lt;a href="http://evothings.com" target="_blank" rel="noopener noreferrer">Evothings&lt;/a>
 and our &lt;strong>open source&lt;/strong> product is a Workbench for creating &lt;strong>mobile HTML5 applications focused on IoT&lt;/strong>, by editing and running them &lt;strong>live on the mobile device&lt;/strong> inside our spiced up Cordova based &amp;ldquo;Evothings Viewer&amp;rdquo;.&lt;/p>
&lt;p>I am of course partial here - but the tool is really easy to use, doesn&amp;rsquo;t force you into any specific framework or editor, enables a very quick development cycle and has tons of examples, tutorials, docs and some special IoT focused libraries like for example around BLE (Bluetooth Low Energy). You can have your code running on your phone literally within 1-2 minutes and you don&amp;rsquo;t need to install XCode or the Android tools, you can even run it just fine from your trusty Linux laptop! Just &lt;a href="http://evothings.com/download" target="_blank" rel="noopener noreferrer">go for it&lt;/a>
. Ok, enough of the sales talk&amp;hellip;&lt;/p>
&lt;p>Since we are specializing in the IoT space we have our office filled to the brink with toys&amp;hellip; eh, I mean &lt;strong>IoT devices&lt;/strong> of all kinds from all different vendors. Two IoT communication standards are particularly important in this space, and that&amp;rsquo;s &lt;strong>BLE and MQTT&lt;/strong>. I have already written three &lt;a href="http://goran.krampe.se/2015/12/14/evothings-meets-phoenix/" target="_blank" rel="noopener noreferrer">blog&lt;/a>
 &lt;a href="https://evothings.com/evothings-does-mqtt-with-bluemix/" target="_blank" rel="noopener noreferrer">posts&lt;/a>
 &lt;a href="https://evothings.com/evothings-does-mqtt-with-vernemq-or-emqtt/" target="_blank" rel="noopener noreferrer">around&lt;/a>
 MQTT using Evothings. Now I am instead focusing on BLE and particularly the &lt;strong>embedded device side of the story&lt;/strong>.&lt;/p>
&lt;img src="https://goran.krampe.se/evothings/mediatek-linkit-one.png" alt="LinkIt-ONE" style="float:left; margin:0 1em 1em 0;">

&lt;p>This led me to round up a bunch of devices at the office that are fairly technically capable and have BLE support. The one I selected was the &lt;a href="http://www.seeedstudio.com/wiki/LinkIt_ONE" target="_blank" rel="noopener noreferrer">LinkIt ONE development board&lt;/a>
 from &lt;a href="http://labs.mediatek.com" target="_blank" rel="noopener noreferrer">MediaTek&lt;/a>
 &amp;amp; &lt;a href="http://www.seeedstudio.com" target="_blank" rel="noopener noreferrer">Seeed Studio&lt;/a>
. It&amp;rsquo;s an insanely feature packed little board (GSM/GPRS, GPS, Wifi, BLE, sound output, SD card) with decent computing power (ARM7 EJ-S, 16Mb flash, 4Mb RAM) while still remaining in the &amp;ldquo;medium&amp;rdquo; embedded space I would say, still ruling out plain Linux and regular tools. I consider the &lt;a href="https://www.raspberrypi.org">Raspberri Pi&lt;/a> or &lt;a href="http://getchip.com">C.H.I.P&lt;/a> and similar machines to be in the &amp;ldquo;large&amp;rdquo; embedded space, they are real computers and you can basically use whatever you like to develop on those.&lt;/p>
&lt;p>The medium and small devices can be programmed using for example &lt;a href="https://github.com/espruino" target="_blank" rel="noopener noreferrer">Espruino&lt;/a>
 or &lt;a href="http://micropython.org" target="_blank" rel="noopener noreferrer">Micropython&lt;/a>
 (two very interesting projects) but in many cases, for more demanding applications, &lt;strong>C/C++ is still king&lt;/strong> simply because of size and performance advantages. And also the fact that hardware vendor SDKs are typically in C/C++. But &lt;strong>could there be an alternative language out there?&lt;/strong>&lt;/p>
&lt;ul>
&lt;li>A language that is just as fast and small that easily can use all these C/C++ SDKs?&lt;/li>
&lt;li>A language with a syntax similar to Python made to be easy to write and read?&lt;/li>
&lt;li>A language with soft realtime GC and a sane advanced type system with generics?&lt;/li>
&lt;li>A language with a good standard library and friendlier than C++?&lt;/li>
&lt;li>A language with compile time hygienic AST based macros written in the language itself?&lt;/li>
&lt;li>A language offering an imperative style and not forcing OO if you don&amp;rsquo;t want to?&lt;/li>
&lt;/ul>
&lt;p>Yep! Read on to find out&amp;hellip;&lt;/p></description></item><item><title>Guts of Ni</title><link>https://goran.krampe.se/2015/09/22/guts-of-ni/</link><pubDate>Tue, 22 Sep 2015 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2015/09/22/guts-of-ni/</guid><description>&lt;p>This article describes some core parts of the current implementation of the Ni (now known as &lt;a href="https://goran.krampe.se/spry" >Spry&lt;/a>
) language. It&amp;rsquo;s not a tutorial, introduction or manual. It&amp;rsquo;s in &lt;strong>fact kinda incoherent - but so is Ni&lt;/strong> :)&lt;/p></description></item><item><title>Who says Ni?</title><link>https://goran.krampe.se/2015/09/16/who-says-ni/</link><pubDate>Wed, 16 Sep 2015 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2015/09/16/who-says-ni/</guid><description>&lt;p>Ni is my &lt;a href="https://goran.krampe.se/spry" >own little language&lt;/a>
 heavily influenced by &lt;a href="http://www.world.st" target="_blank" rel="noopener noreferrer">Smalltalk&lt;/a>
 but also other sources like Rebol, Forth, Lisp, Self and Nim. Ni is a bit strange, but it&amp;rsquo;s not academic and really meant to become something useful.&lt;/p>
&lt;p>So put on your helmet and let me take you to the shrubbery&amp;hellip;&lt;/p></description></item><item><title>Nim and super</title><link>https://goran.krampe.se/2015/05/06/nim-and-super/</link><pubDate>Wed, 06 May 2015 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2015/05/06/nim-and-super/</guid><description>&lt;p>As I described in &lt;a href="https://goran.krampe.se/2014/10/29/nim-and-oo" >the&lt;/a>
 &lt;a href="https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii" >earlier&lt;/a>
 &lt;a href="https://goran.krampe.se/2014/10/31/nim-and-oo-part-iii" >posts&lt;/a>
 Nim didn&amp;rsquo;t support &amp;ldquo;super calls&amp;rdquo; when using &lt;strong>methods&lt;/strong> instead of statically bound &lt;strong>procs and generics&lt;/strong>. My article caused a little bit of discussion around this on IRC and Andreas decided to implement the mechanism he already had planned - but had not fully decided a good name for.&lt;/p>
&lt;p>The other day Nim 0.11.2 &lt;a href="http://nim-lang.org/news.html#Z2015-05-04-version-0-11-2-released" target="_blank" rel="noopener noreferrer">was released&lt;/a>
 and it includes this mechanism. Let&amp;rsquo;s have a look how it works in my sample code&amp;hellip;&lt;/p></description></item><item><title>Nim</title><link>https://goran.krampe.se/2015/03/26/nim-voodoo/</link><pubDate>Thu, 26 Mar 2015 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2015/03/26/nim-voodoo/</guid><description>&lt;p>Having been a die hard Smalltalker since 1994 I have finally found a new language and community that I am investing myself in. All the Ruby, Python, various JVM languages, C# and Mono etc - none has managed to capture my interest. Ruby and Python always felt like pale shadows of Smalltalk and I really don&amp;rsquo;t want to be tied to the Java eco system, no matter what. And so on and on, lots of languages looking interesting but not being able to withstand my deeper look. As a Smalltalker I probably have acquired a particular taste.&lt;/p>
&lt;p>Since a few months I am however deeply into Nim. I have written a slew of articles about Nim, and at our company we have decided to bet hard on it. So far I have written a little utility called blimp in Nim, and I have helped creating Urhonimo - the Nim wrapper of the Urho3D game engine.&lt;/p>
&lt;p>With a deeper understanding of Nim, although I am far from good at it, what is it that makes me recommend you to try it?&lt;/p></description></item><item><title>Nim visits GTUG Stockholm</title><link>https://goran.krampe.se/2015/03/26/nim-visits-gtug/</link><pubDate>Thu, 26 Mar 2015 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2015/03/26/nim-visits-gtug/</guid><description>&lt;p>Yesterday I had the pleasure of presenting the programming language &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 at the &lt;a href="https://sites.google.com/site/stockholmgtug/" target="_blank" rel="noopener noreferrer">Stockholm GTUG&lt;/a>
.
This evening we were around 50 people, I would guess mainly developers, listening to three presentations:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://rust-lang.org" target="_blank" rel="noopener noreferrer">Rust&lt;/a>
, by &lt;a href="https://www.linkedin.com/in/johanburell" target="_blank" rel="noopener noreferrer">Johan Burell, EVRY&lt;/a>
&lt;/li>
&lt;li>&lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
, by Göran Krampe, 3DICC&lt;/li>
&lt;li>&lt;a href="http://golang,org" target="_blank" rel="noopener noreferrer">Go&lt;/a>
, by &lt;a href="https://www.linkedin.com/in/marcusolsson1" target="_blank" rel="noopener noreferrer">Marcus Olsson, Citerus&lt;/a>
&lt;/li>
&lt;/ul>
&lt;p>Now, that&amp;rsquo;s a pretty fitting trio of languages! :) This article is a little followup because I failed to mention so much stuff&amp;hellip;&lt;/p></description></item><item><title>Nim seq</title><link>https://goran.krampe.se/2014/12/03/nim-seq/</link><pubDate>Wed, 03 Dec 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/12/03/nim-seq/</guid><description>&lt;p>One of the most important aspects in a language is how powerful and easy it is to use its collection/container types. At least that is my feeling coming from Smalltalk where the Collection classes and their rather rich protocols are used extensively and also cover String and Array and much more. If you peek into the current leading open source Smalltalk - &lt;a href="http://pharo.org" target="_blank" rel="noopener noreferrer">Pharo&lt;/a>
 - you can see &lt;code>Collection allSubclasses size&lt;/code> evaluate to &lt;strong>78&lt;/strong>. Of course, lots of those are special subclasses and not for general use, but fact remains that a strong language &lt;strong>needs a strong library of good collections&lt;/strong>.&lt;/p>
&lt;p>In Smalltalk I can for example run this:&lt;/p>
&lt;div class="highlight">&lt;pre tabindex="0" class="chroma">&lt;code class="language-smalltalk" data-lang="smalltalk">&lt;span class="line">&lt;span class="cl">&lt;span class="ss">#(&lt;/span>&lt;span class="m">1&lt;/span> &lt;span class="m">2&lt;/span> &lt;span class="m">3&lt;/span> &lt;span class="m">4&lt;/span> &lt;span class="m">5&lt;/span>&lt;span class="ss">)&lt;/span> &lt;span class="nf">select:&lt;/span> [&lt;span class="o">:&lt;/span>&lt;span class="nv">x&lt;/span> &lt;span class="o">|&lt;/span> &lt;span class="nv">x&lt;/span> &lt;span class="nf">isOdd&lt;/span> ] &lt;span class="nf">thenCollect:&lt;/span> [&lt;span class="o">:&lt;/span>&lt;span class="nv">x&lt;/span> &lt;span class="o">|&lt;/span> &lt;span class="nv">x&lt;/span> &lt;span class="nf">*&lt;/span> &lt;span class="m">3&lt;/span> ]
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/div>&lt;p>This is actually a single method call taking two closures, one to perform a &amp;ldquo;filtering&amp;rdquo;, and one to perform a &amp;ldquo;map&amp;rdquo;. This is not a standard message in &amp;ldquo;good old&amp;rdquo; Smaltalk-80, but it has eventually been added since the usage pattern is so common. To me personally a &lt;strong>modern language needs similar power&lt;/strong> or I would go nuts. :)&lt;/p></description></item><item><title>Nim and OO, Part IV</title><link>https://goran.krampe.se/2014/11/30/nim-and-oo-part-iv/</link><pubDate>Sun, 30 Nov 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/11/30/nim-and-oo-part-iv/</guid><description>&lt;p>As I described in &lt;a href="https://goran.krampe.se/2014/10/29/nim-and-oo" >the&lt;/a>
 &lt;a href="https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii" >earlier&lt;/a>
 &lt;a href="https://goran.krampe.se/2014/10/31/nim-and-oo-part-iii" >posts&lt;/a>
 Nim didn&amp;rsquo;t support &amp;ldquo;super calls&amp;rdquo; when using &lt;strong>methods&lt;/strong> instead of statically bound &lt;strong>procs and generics&lt;/strong>. My article caused a little bit of discussion around this on IRC and Andreas decided to implement the mechanism he already had planned - but had not fully decided a good name for.&lt;/p>
&lt;p>The other day this mechanism &lt;a href="https://github.com/Araq/Nimrod/commit/105a0616a9da7c9c85adfa488a1db42eb17daafb" target="_blank" rel="noopener noreferrer">entered the devel branch&lt;/a>
 which means it will be official in the next release of Nim, which I suspect will be out before the end of 2014. It should be noted that devel is mainly undergoing bug fixing, so unless you are paranoid it&amp;rsquo;s pretty usable. Now&amp;hellip; of course I had to try out super calls in my sample code&amp;hellip;&lt;/p></description></item><item><title>Squeak to Nim, come in Nim...</title><link>https://goran.krampe.se/2014/11/03/squeak-to-nim/</link><pubDate>Mon, 03 Nov 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/11/03/squeak-to-nim/</guid><description>&lt;p>In my exploration of &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 the turn has come to see how we can use Nim together with &lt;a href="http://squeak.org" target="_blank" rel="noopener noreferrer">Squeak&lt;/a>
.&lt;/p>
&lt;p>Squeak (and Pharo) has two basic mechanisms of interfacing with the C world:&lt;/p>
&lt;ul>
&lt;li>&lt;a href="http://stephane.ducasse.free.fr/FreeBooks/CollectiveNBlueBook/greenberg.pdf" target="_blank" rel="noopener noreferrer">Squeak VM plugins&lt;/a>
. That pdf is old, but still fairly accurate I guess.&lt;/li>
&lt;li>&lt;a href="http://wiki.squeak.org/squeak/1414" target="_blank" rel="noopener noreferrer">Squeak FFI&lt;/a>
, Foreign Function Interface.&lt;/li>
&lt;/ul>
&lt;p>The VM plugins are basically a controlled way to introduce new &amp;ldquo;named&amp;rdquo; primitives in Smalltalk that can be invoked from Smalltalk. A plugin can be built either linked into the VM binary (statically) or as a dynamically loaded library (dll, so, dylib etc). When &amp;ldquo;all else fails&amp;rdquo; a plugin is the way to go, but they are a bit awkward to work with.&lt;/p>
&lt;p>Then we have the FFI which is a generic way to dynamically call dynamically loaded libraries. In other words, no compilation step needed - just type the correct Smalltalk line and the library will load and the calls work. Now&amp;hellip; sure, the FFI mechanism is a bit slower, since it needs to look at arguments and make the proper type conversions for the call. But the FFI is heavily used in the commercial Terf system, in fact, all the OpenGL calls are done through it. So its quite proven, and not that slow.&lt;/p>
&lt;p>&lt;strong>NOTE:&lt;/strong> There are in fact several FFIs today, the old one, the one called Alien and Pharo is brewing a new one called UFFI.&lt;/p>
&lt;p>Let&amp;rsquo;s see if we can use the good old FFI with Nim.&lt;/p></description></item><item><title>Nim and OO, Part II</title><link>https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii/</link><pubDate>Fri, 31 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii/</guid><description>&lt;p>In the &lt;a href="https://goran.krampe.se/2014/10/29/nim-and-oo" >previous article&lt;/a>
 when I explored OO mechanisms in &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 I felt I dropped the ball a bit in my Fruit example. This is a followup.&lt;/p>
&lt;p>In that article we first implemented some Fruit &amp;ldquo;classes&amp;rdquo; mixing methods and procs. Then I presented a cleaned up version using methods only, and a teeny template in order to reuse a base method. This template was needed since Nim currently doesn&amp;rsquo;t have a &amp;ldquo;call-next-method-matching&amp;rdquo; for multimethods like Dylan or CLOS have. This is being discussed and I think all agree that there needs to be &lt;strong>some&lt;/strong> mechanism so that you can call a &amp;ldquo;next lesser match&amp;rdquo; of all matching multimethods.&lt;/p>
&lt;p>But I also wrote that the example &lt;strong>can be written perfectly well using generics and procs only&lt;/strong>, thus ensuring static binding and maximum speed. But the &amp;ldquo;super call&amp;rdquo; problem also existed for procs, and the template hack was just a hack. After more experimentation I now &lt;strong>think I found the proper Nim way&lt;/strong> to do this so let&amp;rsquo;s take a look&amp;hellip;&lt;/p></description></item><item><title>Nim and OO, Part III</title><link>https://goran.krampe.se/2014/10/31/nim-and-oo-part-iii/</link><pubDate>Fri, 31 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/31/nim-and-oo-part-iii/</guid><description>&lt;p>So previously in &lt;a href="https://goran.krampe.se/2014/10/31/nim-and-oo-part-ii" >Nim and OO Part II&lt;/a>
 we saw how we could solve the &amp;ldquo;super call&amp;rdquo; issue using only procs and generics in &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
. This means that all code is statically bound.&lt;/p>
&lt;p>But if you have read all these article you know I also tried the more appropriate mechanism for OO - so called &lt;strong>methods&lt;/strong>. In Nim a proc is a regular statically bound function, simple and fast. A &lt;strong>method&lt;/strong> on the other hand uses dynamic multimethod dispatch on the &lt;strong>runtime types&lt;/strong> of all object parameters. The easy way to do objects in Nim (with inheritance of behavior) is using methods - but of course, this means dynamic lookup that has a runtime cost, but quite small as we will see.&lt;/p>
&lt;p>Time for benchmarking!&lt;/p></description></item><item><title>Nim and OO</title><link>https://goran.krampe.se/2014/10/29/nim-and-oo/</link><pubDate>Wed, 29 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/29/nim-and-oo/</guid><description>&lt;p>&lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 is presented as an &lt;strong>imperative&lt;/strong> language. And yes, it has some of its roots in the Pascal line of languages, but it also has a set of powerful abstraction mechanisms making it very suitable for object oriented programming. And when I write &lt;em>&amp;ldquo;object oriented&amp;rdquo;&lt;/em> I am referring to a broader flexible sense of OO in which objects can be formulated with attached behavior, polymorphism between different objects, some kind of reuse model of code (inheritance etc) and some type of dynamic dispatch.&lt;/p>
&lt;p>Since I am a &lt;a href="http://www.squeak.org" target="_blank" rel="noopener noreferrer">long time&lt;/a>
 &lt;a href="http://pharo.org" target="_blank" rel="noopener noreferrer">Smalltalker&lt;/a>
 that is my main reference for &lt;em>&amp;ldquo;good OO&amp;rdquo;&lt;/em> and not the &amp;hellip; monstrous OO often seen in Java or C++. Its hard to explain the differences, but let me just say that OO in Smalltalk is elegant and natural, very much like in Ruby or Python - but ever so more streamlined. Smalltalk is a dynamically strongly typed reflective language with a heavily closure based style.&lt;/p>
&lt;p>In this article I will try to make &amp;ldquo;sense&amp;rdquo; out of how to do OO in Nim.&lt;/p></description></item><item><title>Nim Socket Server</title><link>https://goran.krampe.se/2014/10/25/nim-socketserver/</link><pubDate>Sat, 25 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/25/nim-socketserver/</guid><description>&lt;p>In learning &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 I decided to implement a trivial Socket server, very small, as an example. Its &lt;strong>not a useful HTTP server&lt;/strong> (it just returns a hard coded HTTP response so we can benchmark it using HTTP tools), and its &lt;strong>not async&lt;/strong> - there are other such examples in the Nim examples directory and in its stdlib. No, I wanted to write a more classical threaded socket server to see how easy that is - especially with the new APIs in Nim &lt;a href="https://github.com/Araq/Nimrod/tree/bigbreak" target="_blank" rel="noopener noreferrer">&amp;ldquo;bigbreak&amp;rdquo;&lt;/a>
 - and see how it performs.&lt;/p>
&lt;p>The new &amp;ldquo;bigbreak&amp;rdquo; branch that will become Nim 0.10.0 soon-ish has a bunch of new stuff in the networking area. Its replacing the single &lt;code>sockets&lt;/code> module with a low level &lt;code>rawsockets&lt;/code> module, and a higher level &lt;code>net&lt;/code> module. And there is a new &lt;code>selectors&lt;/code> module that abstracts over different modern IO polling mechanisms. This means that a single API will use &lt;strong>epoll on Linux, kqueue on BSD/OSX, old select on the other Unices and IO Completion ports on Windows&lt;/strong>. At the moment epoll, select on &amp;ldquo;other Unices&amp;rdquo; and IO Completion ports works. kqueue is on the todo.&lt;/p>
&lt;p>So without further ado&amp;hellip;&lt;/p></description></item><item><title>I missed Nim</title><link>https://goran.krampe.se/2014/10/20/i-missed-nim/</link><pubDate>Mon, 20 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/20/i-missed-nim/</guid><description>&lt;p>A year ago I wrote an article trying to round up &lt;a href="http://goran.krampe.se/2013/09/07/new-languages-this-century" target="_blank" rel="noopener noreferrer">new languages since year 2000&lt;/a>
 and what I think of them by just&amp;hellip; glancing at them, or otherwise playing with them. I ended up sifting out the 4 most interesting in my not so humble opinion - &lt;a href="http://golang.org" target="_blank" rel="noopener noreferrer">Go&lt;/a>
, &lt;a href="http://www.rust-lang.org" target="_blank" rel="noopener noreferrer">Rust&lt;/a>
, &lt;a href="http://dartlang.org" target="_blank" rel="noopener noreferrer">Dart&lt;/a>
 and &lt;a href="http://julialang.org" target="_blank" rel="noopener noreferrer">Julia&lt;/a>
. Now a year has passed and&amp;hellip;&lt;/p>
&lt;p>&lt;strong>I discover that I missed Nim(Nimrod)!&lt;/strong>&lt;/p>
&lt;p>&lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 was born somewhere around 2006-ish and is clearly a very serious language to consider, but is going suspiciously under the radar. Having reviewed this language more closely (and still doing so) I can safely say that &lt;strong>for me&lt;/strong> it actually easily &lt;strong>tops this list&lt;/strong>.&lt;/p>
&lt;p>I have already posted &lt;a href="http://goran.krampe.se/categories/nim" target="_blank" rel="noopener noreferrer">a few articles about Nim&lt;/a>
, but this one is meant as a &lt;em>followup&lt;/em> to &lt;a href="http://goran.krampe.se/2013/09/07/new-languages-this-century" target="_blank" rel="noopener noreferrer">that article&lt;/a>
 trying to make amends :).&lt;/p>
&lt;p>&lt;em>&lt;strong>NOTE:&lt;/strong> Technically &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 is still called &amp;ldquo;Nimrod&amp;rdquo; up to and including the &lt;a href="http://nim-lang.org/news.html#Z2014-10-19-version-0-9-6-released" target="_blank" rel="noopener noreferrer">0.9.6-release that was done yesterday&lt;/a>
. But for the upcoming 0.10.0 and onward its &lt;strong>Nim&lt;/strong>. Short and sweet.&lt;/em>&lt;/p></description></item><item><title>Nim wrapping C</title><link>https://goran.krampe.se/2014/10/16/nim-wrapping-c/</link><pubDate>Thu, 16 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/16/nim-wrapping-c/</guid><description>&lt;p>Nim has all the language mechanisms needed to smoothly interoperate with C and C++. The rather &lt;a href="https://github.com/Araq/Nimrod/tree/devel/lib/wrappers" target="_blank" rel="noopener noreferrer">large collection of wrapped C libraries&lt;/a>
 (and that&amp;rsquo;s only those in the standard libs) is also a testament to this fact. In this article I explain my personal findings testing out the waters of wrapping a simple C library.&lt;/p>
&lt;p>The basic approach to wrapping a simple C library is:&lt;/p>
&lt;ol start="0">
&lt;li>Install Nim.&lt;/li>
&lt;li>Install c2nim using Babel or manually clone c2nim from github and build it.&lt;/li>
&lt;li>Use c2nim to translate the C header file(s) to a so called Nim wrapper.&lt;/li>
&lt;li>Make a small test showing it works.&lt;/li>
&lt;li>Write a so called &lt;em>&amp;ldquo;impure&amp;rdquo;&lt;/em> intermediary library that uses the wrapper (next article)&lt;/li>
&lt;li>Make a test green and declare Victory (next article)&lt;/li>
&lt;/ol>
&lt;p>Okidoki&amp;hellip; (roll up sleeves)&lt;/p></description></item><item><title>Bootstrapping Nim(rod)</title><link>https://goran.krampe.se/2014/10/15/bootstrapping-nim/</link><pubDate>Wed, 15 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/15/bootstrapping-nim/</guid><description>&lt;p>Technically &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
 is still called &lt;a href="http://nimrod-lang.org" target="_blank" rel="noopener noreferrer">Nimrod&lt;/a>
 up to and including upcoming bugfix version 0.9.6. But then with the next version 0.10.0 it will be just &lt;strong>Nim&lt;/strong>. Currently Nimrod is at &lt;a href="http://nimrod-lang.org/news.html#Z2014-04-21-version-0-9-4-released" target="_blank" rel="noopener noreferrer">0.9.4&lt;/a>
. And oh, the current development version is 0.9.5 which will become 0.9.6 when released - the &amp;ldquo;odd and even&amp;rdquo; versioning scheme.&lt;/p>
&lt;p>Nim can be a bit funky to get started with, typically due to a slight lack of documentation in certain areas that may be obvious to Nimmers (or Nimsters? Knights who say Nim?). This article tries to fill a few mental holes in the first steps.&lt;/p>
&lt;p>Also, &lt;strong>Nimsters like to do it in Nim&lt;/strong> - and often the reasons for this are very good, like maintaining portability or minimizing dependencies. Just don&amp;rsquo;t expect the classic autoconf dance here. As a Smalltalker I am fully versed in the &lt;a href="http://en.wikipedia.org/wiki/Not_invented_here" target="_blank" rel="noopener noreferrer">NIH syndrome&lt;/a>
 - which of course doesn&amp;rsquo;t always have to be a bad thing. Thankfully Nimmers also seem to balance it with a strong tradition of &lt;a href="https://gcc.gnu.org" target="_blank" rel="noopener noreferrer">standing on the shoulders of giants&lt;/a>
.&lt;/p>
&lt;p>So building Nim isn&amp;rsquo;t &lt;strong>hard&lt;/strong>, but it&amp;rsquo;s also not &lt;strong>obvious&lt;/strong> what is going on. There are of course &lt;a href="http://nimrod-lang.org/download.html" target="_blank" rel="noopener noreferrer">binary installers&lt;/a>
 available too, but hey, we want to hack!&lt;/p></description></item><item><title>Here Comes Nim!</title><link>https://goran.krampe.se/2014/10/13/here-comes-nim/</link><pubDate>Mon, 13 Oct 2014 00:00:00 +0000</pubDate><guid>https://goran.krampe.se/2014/10/13/here-comes-nim/</guid><description>&lt;p>I just posted an article comparing some silly benchmarks between Cog Smalltalk and LuaJIT2. Now&amp;hellip; let&amp;rsquo;s take a look at one of the latest &amp;ldquo;Cool Kids&amp;rdquo; on the language front, Nimrod - or as it has been renamed - &lt;a href="http://nim-lang.org" target="_blank" rel="noopener noreferrer">Nim&lt;/a>
.&lt;/p></description></item></channel></rss>