Just the other day, while programming in Scala, I was thinking how nice it is that Haskell hides non-strictness (a.k.a. laziness) underneath, so no obnoxious lazy stream creation/forcing needs to be done. And then it struck me: how cool would it be to treat Promises in a language the same way that Haskell treats lazy values? Would such a language even make sense? How would you program in such a language?
Let's explore! You can find all the code included in this post in a more useful form here.
Promiseimplementation written in Scheme, with support for asynchronous resolving & error rejection, which we'll need in order to explore this weird proposition:
(define *promises* '()) (define (make-promise value state then handle thunk) (list '&promise value state then handle thunk)) ;; Field accessors omitted. (define (promise fun) (let* ((val '()) (state 'pending) (on-resolve id) (on-reject id) (resolve (lambda (v) (set! val v) (set! state 'resolved) (on-resolve val))) (reject (lambda (e) (set! val e) (set! state 'rejected) (on-reject val))) (then (lambda (t) (if (equal? state 'resolved) (t val) (set! on-resolve t)))) (handle (lambda (h) (if (equal? state 'rejected) (h val) (set! on-reject h)))) (p (make-promise (lambda () val) (lambda () state) then handle (lambda () (fun resolve reject))))) (set! *promises* (cons p *promises*)) p))
After a lengthy break I'm back to the UPNOD series. This time we'll take a closer look at the dynamic random-access memory (DRAM) circuitry present on the PCB:
As usual, all of my findings can be found here.Continue reading
Recently, I came across this post about implementing custom type systems using Prolog and it inspired me to revisit an old logic-programming-related project of mine.
About a year and a half ago I took a shot at using Prolog for type reconstruction (a.k.a. type inference), but that resulted in a load of not much for one reason or another. I did write this Rule-based system shortly thereafter, however I did not give much thought to using it for type reconstruction. Let's change it...
(assert! (: map (-> ((-> (?a) ?b) (list ?a)) (list ?b))))
A second installment in the UPNOD series, this time we'll take a look into the reset circuitry of the telco card.
As the title implies, this circuit is responsible for generating a proper Z80' reset sequence. Z80, being a rather dumb piece of clever electronics, may boot up in an undesirable undefined state and requires a few cycles of special treatment to properly initialize internal register values. This circuit does just that - it generates the initial reset pulse and handles reset signals coming from other parts of the board, all while maintaining proper synchronization.Continue reading
Cranking out another post took me way longer than I had anticipated when I rebooted this blog, but I got sidetracked by another quick hardware project that turned out to be way more involved and equally more fun than I originally thought...
I've designed an Atari 400/800/XL/XE standard cartridge compatible board that can hold up to 127 different standard 8KB and 16KB game ROMs at the same time. It's memory chip agnostic and features software game selection & a few neat hacks.Continue reading
Since my last actual post on this blog I have acquired a new class of hobbies - electronics. Most recently, reverse engineering of really old computers. This series of posts will be about a vintage eighties TelCo computer-card-thing marked UPNOD CARD0117 TN64 I bought on a local auction:
All my findings will be posted on this blog and the accompanying data will be gathered in this GitHub repository.Continue reading
Finally got around to rebooting my old dev-blog! This time instead of fighting my way against some new unforgiving piece of blogging software I've decided to write my own piece of even less forgiving blogging software.
Let's see how it goes this time...
In case you are wondering, here are some questions & answers regarding λ-blog:Continue reading
Lately I've been banging around a lot in order to get up to speed with Erlang/OTP and its various web-server libraries, and I figured I could share some of my findings here for future reference and in general for The Greater Good.
As you might have already noticed, this benchmark concerns two of the most well knows Erlang web-server libraries, MochiWeb and Cowboy, and it aims to explore their behaviour under some considerable load.
The server in question uses two communication protocols, HTTP and WebSocket, so as an added benefit we'll see how these two compare. Unfortunately, MochiWeb doesn't have a built-in support for WebSocket, so an external library was needed. The rather simple client API is defined as:
- http://host/poll/N - an HTTP chunked reply with one chunk of data sent every N seconds,
- ws://host/wspoll/N - a WebSocket connection with one chunk sent every N seconds.
With Google Reader being discontinued and everyone looking for alternatives I've decided to look for a little less "standard" solution, and hey, it turns out Emacs can be a pretty powerful RSS reader.
News Ticker is a built-in Emacs feed reader that doesn't get much attention for some reason. It is feature-rich, handles both RSS 2.0 and Atom feeds and has quite a bunch of tweakable options. Here's a simple setup to start with:
(require 'newsticker) ; W3M HTML renderer isn't essential, but it's pretty useful. (require 'w3m) (setq newsticker-html-renderer 'w3m-region) ; We want our feeds pulled every 10 minutes. (setq newsticker-retrieval-interval 600) ; Setup the feeds. We'll have a look at these in just a second. (setq newsticker-url-list-defaults nil) (setq newsticker-url-list '("...")) ; Optionally bind a shortcut for your new RSS reader. (global-set-key (kbd "C-c r") 'newsticker-treeview) ; Don't forget to start it! (newsticker-start)
This is a follow-up post to Gamification showing how I use it and what purpose does it serve me.
In summary, I'm a kind of control freak who likes all sorts of stats (such as my systems stats or a projects repo stats) displayed neatly all over the place, and it was only a matter of time before I started monitoring myself, and so I wrote a tiny tool, Gamify, that integrates with Emacs' Org-Mode and tracks my skills, their dependencies and their development.