On the way home this afternoon I was asked to explain Clojure’s reify macro, and apparently I did quite well, as an “Aha!” moment resulted. So I shall endeavour to explain reify here in the hope that such a moment might be available to others.
Reify derives from the Latin res, or “thing.” So reify fundamentally means “make a thing out of….
Protocols and Datatypes
Clojure protocols are similar to Java interfaces: They define a set of methods/functions purely by their signatures without providing implementation details. Declaring that a class implements an interface (in Java) or that a record implements a protocol (in Clojure) is a contract that specifies that the given class or record, in order to be valid, will provide concrete implementations of those methods/functions.
But sometimes we don’t need a reusable entity with reusable implementations that we can instantiate willy-nilly; sometimes we just need a thing that implements those methods.
In Java, anonymous inner classes can fulfill this purpose. In Clojure, we have reify.
That Nameless Thing
OK, it’s not really going to be nameless… let’s say we have a putative protocol as follows:
I have to start this post by saying I’ve been a dogmatic Vim partisan since the 1990’s, when I started using vi on the Solaris and Irix boxen I had access to, and then on my own machines when I got started with Linux in 1994.
I flamed against Emacs on Usenet, called it all the epithets (Escape Meta Alt Ctrl Delete, Eight Megs And Constantly Swapping (8 megs was a lot then), Eventually Mangles All Computer Storage)… I couldn’t stand the chord keys and lack of modality.
Even once I got heavily into Lisp I still tried to stick with Vim, or tried LightTable, or Atom, or SublimeText. But then one day I hit a wall and Emacs (plus cider-mode and slime and a few other packages) was the obvious solution. Now I’m out there evangelizing Emacs (I’m writing this post in the Markdown major mode plus some helpful minor modes) and I figure I’d offer some advice for those looking to convert to the Church of Emacs.
I’m sitting in the first session of the Code.org K-5 PD
It’s my first time in Las Vegas. We went to In-N-Out Burger (required if I
travel out west), and I hit a $2k jackpot on penny slots. Not bad. And now
we’re getting an overview of the K-5 Code.org curriculum. It’s pretty exciting.
I learned to code when I was 5. Learning BASIC on a TI 99/4A. This is pretty much
my first computer:
It’s August 19th, the day we remember why the lucky stiff’s poignant departure
from the internet. ruby-jokes would hate to
part with the Whyday tradition of hacking on something just for fun and releasing
it into the wild.
So it’s with great ambivalence we announce whynot,
a gem that does irresponsible things because… why not?
whynot is for when you really just don’t care. It started as a single monkey-patch
to Kernel, called maybe. maybe takes a block, and may or may not yield the
result. So for instance:
About half the time, this will return 6. The other half, nil.
About three minutes after I pushed whynot to Github, Micah Gates
added some kernel methods that allowed for a little more specificity: mostly,
which will execute your code about 2/3 of the time, and occasionally, which
has about a 1 in 5 chance of actually executing your code.
But wait, there’s more!
Just in time for the 0.0.4 release this afternoon, I decided sometimes, the truth
doesn’t matter. Or, at least, you just don’t care. So I added meh. Sometimes
true, sometimes false, whatever. When you really don’t care, just do this:
I really wanted to create a global value like true or false that was neither
truthy nor falsey, but I’m not sure whether that’s possible, and I have a feeling
it would require some C-extension hackery if it is.
Perhaps for a future release?
As always, pull requests are welcome, and use at your own risk.
I’ve always taken a hands-off approach to moderating comments, feeling that it was a form of censorship to restrict discussion even on my own blog. It’s worked pretty well; I feel like prior to yesterday, I’ve deleted less than three comments in the three years I’ve maintained this blog.
But yesterday’s post, I’m Telling :: Employer-Tattling and The Decline of Agency, brought in some of the nastiest of trolls, and I had to re-evaluate that policy. The post also got so many comments I was going crazy trying to weigh my anti-censorship views against comments that bordered on hate speech.
The other night Twitter was abuzz with controversy and drama, as per usual. One of those threads (which I’ll get to momentarily) invovled what I’ll refer to as “employer-tattling,” and Jon Soeder (laudably without drawing attention to the ongoing echo chamber), tweeted this:
If somebody says something vile on the internet, it is not your place to notify their employer. You are setting a terrible precedent.
I fucking hate this school. All the teachers too. Well, there are a few exceptions, but few enough it doesn’t really matter.
There are a few saving graces. Molly, that redhead in fourth period I’m dying to fuck. There’s a party Friday, maybe that’ll happen. At least I’ll be drunk enough not to care about this shithole for a few hours.
Had a test today. Fucking Mr. Blum walked over to my desk and watched me solve quadratic equations. Grabbed the calculator out of my hand when he saw me using the program I wrote to solve them. Old fucking moron doesn’t even know what these piece of shit TI-83’s are capable of. Thought I was cheating.
While I’m planning a full “overview” reflection on EduCon 2.6, I was (pardon the pun) privileged to participate in a conversation entitled “The Privileged Voices in Education”, facilitated by Audrey Watters and Jose Vilson. Audrey has written about the session on her blog, and Jose has written about it on his blog, so you can refer to those for context. But I want to talk about my takeaways from that wonderful session and what came after while it’s fresh in my mind, and then work on a more general EduCon post.
This is a Hard Topic to address in a meaningful way that actually effects change. It’s a hard topic to broach in general. I applaud Audrey and Jose for creating this EduCon session, for their facilitation of the conversation, and I’m in awe of how civil, insightful, and enlightening the discourse was.
Let me start by confessing: as often happens, I was unable to make it through the discussion without saying something (at the very least) bothersome. I talked about my initial reaction to #edchat, a hashtag-based recurring event for educators on Twitter, as an offhand preface to the difficulty of certain discussions in diverse media. Tom Whitby, founder of #edchat, was in the room. This actually opened a (in my opinion) constructive dialogue ex post facto, but I’ll return to this later.
The Ruby Jokes team has a new gem for you that was designed, tested, and released in about an hour this afternoon: taint_aliases. You can get the full details on GitHub, but I thought a friendly introduction might make for an enlightening blog post.
Grundle Your Objects
You see, not everyone prefers the word “taint”. Some people are very clinical, and say ‘perineum’. Others prefer ‘grundle’ or ‘fleshy fun bridge’. We wanted to give you options, so taint_aliases makes a variety of synonyms available to you.