Which language is better for creating DSLs, Clojure or Haskell?

Another Quora answer. Part of my increasing admiration for the virtues of EDN in Clojure.

Which language is better for creating DSLs, Clojure or Haskell?

Clojure has a slightly different philosophy than most Lisps, I think.
In Clojure you’d be more likely to make your “DSL” in EDN (“Extensible Data Notation”, which is a bit like JSON but with more features). It’s completely integrated with / interoperable with Clojure itself. You can embed EDN anywhere in a Clojure program, and embed Clojure function calls anywhere in an EDN data-structure.
And you get “parsing” for free.
That’s how languages like hiccup are built.
So if you just want to make “a DSL” (ie. convenient high-level domain specific notation for an application) then 99% of the time, a hiccup-like EDN dialect is going to be fine, and you don’t have to write anything at all.
In that sense, code you don’t have to write is better than code you do.
If you need a specific DSL with a specific syntax which isn’t EDN (or s-expressions) then you’ll be back to writing your own parser.
Here, Clojure has its own Yacc-like and parser-combinator libraries. I’m not sure they’re very different from Haskell’s. But you don’t have Haskell’s algebraic data-types, so there’s no type system helping you. I guess it’s a bit more effort to get a Clojure DSL right using Instaparse etc. than in Haskell.
There is Spec, which does some of the job but is certainly more verbose and less elegant than Haskell’s algebraic data.
So yeah, Haskell probably wins for writing general DSLs but if you just want to make small, simple domain-specific notations for things in your application, and don’t mind the EDN look, then Clojure is fine. That’s trivially easy.

Hazel

Further to the previous post. The talk on Hazel is fascinating.

I’ve been thinking for a while about the importance of being able to program “in your own order” ie. fill the blanks of your decision making about your program as and when you have that information available to you / or as you feel like tackling that problem. And leaving the undecideds and unknowns until later.

Holes in Hazel and other theorem provers offer that capacity in the small. And obviously tied to some advanced type theory which is a bit beyond me, but I think I grok the basic ideas. And, yes, having a formalization of the unknowns is a powerful idea.

ThoughtStorms is nothing but LinkBins

If ThoughtStorms is looking a bit busy but weird these days, it’s because it’s starting to become my “bookmarking” application.
I’m not quite sure where I’m going with this, but for a while I’ve had a bookmarklet to add interesting pages to the ThoughtStorms LinkBin page.
Now I have a new way to route those links to other pages. It’s still pretty disorganized and controlled after that … but I think this is useful. (At least to me) and it gives a public (if slightly delayed) view of what I’m thinking about.
ThoughtStorms is still, slowly, evolving.
The code is pushed to the WIP on Github, my self-hosted public repo and a new Gitlab repo.
It will find its way into the thoughtstorms pip package soon …

Pharo and a new Smalltalk

On Quora, I’m often ranting about Smalltalk. And how I’d like to see a “clean-slate” reinvention. Much as Clojure is a clean-slate reinvention of Common Lisp.
Over on this answer I was asked what I think of Pharo.
My response veered off somewhat :
I’ve had a quick look at Pharo. And it’s certainly quite nice. An improvement on Squeak.
But I have a more radical / somewhat idiosyncratic desire. Which I know is probably not something that actual Smalltalk people relate to. But I think it would be a winner.
What I think is, that part of the “cruft” I’d like to see a “blank slate” Smalltalk get rid of, is the “desktop metaphor” and all those silly little overlapping windows, icons, pull out menus etc. Morphic and whatever else.
That doesn’t mean go to something like GNU Smalltalk. No, I still want a live environment that’s Smalltalk all the way down.
I just don’t think anyone wants a desktop metaphor in 2018.
If I’m going to write a “desktop” app, then I don’t want it stuck inside another non-standard app. And if I’m not going to write a “desktop app” I don’t want the overhead of having to think about and implement that kind of interface.
What I think Smalltalk should look like in 2018 is something like Jupyter / iPython notebook. Or, at a pinch, Hypercard.
I open “Smalltalk” (whether that’s a browser-based version equivalent to Amber, LivelyKernel or Peter Fisk ‘s Smalltalk Express, or a desktop version like Pharo or Squeak), and what I see is a “smart notebook” type metaphor :
A single page that takes up the whole window. To which I can start adding “cells” or “cards” containing either code or “literate” styled documentation, or output produced by the code.
You’d still have tools like the Class Browser etc. But they’d be integrated within the same UI. Ie. the class browser is just more “pages” in the notebook. There’s no workspace or transcript because every page can have live code on it.
This UI is immediate. And focused on “do something”. You don’t have to learn how to navigate around a non-standard UI because it’s the conventions we’re already used to from the web and our mobile devices. Navigation between pages, appending “cells” or “cards in the stream” the kind we’re used to in chat apps.
Other UI conventions would be services that look like bots in Slack or Telegram eg. services at a name which can be invoked in a cell on any page through a little dialogue. And there would be notification streams too. “RecentChanges”, recently generated output. Messages from other users (it should be easy to share individual pages with other users)
I think if you took the underlying Smalltalk engine / VM / image. Stripped out all the legacy “desktop UI” stuff, and replaced with a simpler “multi-page notebook” metaphor, then it could be massively more compelling to people. It then becomes a “personal notebook” for doing little sketches / experiments.
If it’s also “social” ie. has chat streams. Or is like the Smallest Federated Wiki. Or has other ways to sync sketches and pages etc. then this would be spectacular.
And the Smalltalk VM / infrastructure is perfect for it.
But right now, anyone who looks into Smalltalk to see what all the fuss is about is confronted with an alien / non-standard ugly desktop, full of unfamiliar tools. Sure, that “Welcome to Pharo” window with all the tabs is an improvement on other systems. But it’s still not good enough.
I open Pharo, and I don’t know what to “do”. How to start playing around and doing something useful and fun.

Why is my phone so useless?

Why is my phone so useless?
I mean I’m a programmer. I can make it do what I want, can’t I?
And yet, actually, I’m as bad as anyone. Allowing my phone and its apps. to define my activities.
I still depend on the laptop for all the things that are for me. My phone makes me a consumer of other people’s services and channels me in its own direction.
I don’t have an answer to this. So I’m just making a ThoughtStorms page to track it.

Microsoft adds Python to Excel

Several years late, it seems M$ is considering making Python native to Excel.
I wrote a … you guessed it … Quora answer as to why this makes sense for Microsoft.

Python has become massively popular with the data and machine learning communities in the last few years.
Tools like JuPyter are increasingly popular and serious interfaces for data-modellers who previously would have used Excel.
It absolutely makes sense for Microsoft try to embed Excel and itself into that emerging Python data ecosystem by making Python a first-class citizen (ie. default, guaranteed to be there) of Excel.
Not just a third-party add on for those who know about it and can make the effort to install it.
Not only does Python need to be standard within Excel, but access to pip and all the Python libraries needs to be there too. So that Excel becomes the equivalent of Anaconda
That’s the way that M$ can keep Excel relevant in the new data age.
This is not only a good idea for Microsoft. It’s the difference between Excel remaining a major player in data modelling and analysis tools, vs. declining into obscurity.

Gmail Snooze

Is GMail Snooze basically building Mind Traffic Control into your email client?

Well, it’s about time Google did something radical to improve GMail. There’s still so much untapped potential in the mail-box. And at least email is an open protocol that we should defend against moving to walled rivers like Facebook and Slack etc.

Working with the file system is too verbose. Let's make it more like JQuery!

Working with the file system in Python is too verbose.
Seriously.
Every time I want to do something with files I need to remember whether it’s the os or sys library that I need to import. I need to remember or look up half a dozen other functions to grab particular bits of metadata from those files.
I’ve written countless nested loops or recursive functions to walk the tree of files over the years.
And often I want to do something quick to a bunch of files, start writing shell-script. Then realize I hate and can’t remember shell-script and think it would be so much easier in Python. Then I open the editor to try to write my code in python, and I realize it’s too much trouble and go back to mashing around in bash again.
And then I remembered JQuery with its refreshingly easy abstractions for maneuvering in, and manipulating a tagged tree-shaped data-structure. And the file-system is just a tree, right? So why does it have to be hard? Why shouldn’t working with files just be like working with JQuery?
This is such an obvious idea, I’m sure someone must have done it.
But I couldn’t find it. So I had to write it myself a couple of months ago.
So, let me present … FSQuery . Now available on PyPI and GitHub.
Here’s what it looks like :
[cc lang=”python”]
from fsquery import FSQuery
fsq = FSQuery(path).Match(“.js$”).NoFollow(“vendor”).FileOnly()
for n in fsq :
print n.abs
[/cc]
You create an FSQuery object with a path to the root of the files you’re interested in. You then load up extra filters / queries on the query by chaining them together.
Finally you can treat the whole thing as an iterable collection and loop through its results.
It returns object of class FSNode, which represent nodes in the file-system, either files or directories. The modifier FileOnly(), restricts the query to only return files. You only need to add this once to the query.
The NoFollow() method tells the query to avoid directories that match the name. But has no effect on file names. In the above example, “vendor.txt” would still be included in the results if that file is anywhere other than under the vendor directory. (This beats just piping find through grep in the terminal.) You can add as many NoFollow filters as you like to a query.
On the other hand, Match() is an inclusive filter. Only files whose names are explicitly matched end up in the results. However, this filter isn’t applied to directories. FQuery will still explore and return directories whether they match this or not. You will usually want to combine a Match with a FilesOnly to get the effect you want (eg. in this case, all the .js files anywhere except under the vendor directory)
We can even look inside files with the Contains filter, eg.
[cc lang=”python” nowrap=”0″]
fsq = FSQuery(path).NoFollow(“vendor”).Ext(“py”).Contains(“GNU Lesser General Public License”).FileOnly()
[/cc]
Note that this is implemented purely in Python in a very non efficient way. (Ie. I just open up each file and run through it looking for the string.) It can be slow with large chunks of the file system.
Note also the Ext() filter for file-name extensions. This is easier than regexing the whole file-name if you’re just looking for files of type “py”. Be aware that if you try to have two Ext() filters on the same query, you will get no files returned. No file can have two different extensions at the same time.
More documentation, and more advanced tricks can be seen on the GitHub site. This is also the first library I’ve put on PyPI. So installing in your own project is as simple as
[cc]pip install fsquery[/cc]