More On SQL For Arbitrary Data

In response to my recent post on Making Ad Hoc SQL Tables From Org Tables, commenter Fritz Grabo points to another, more general system, for doing the same thing. As Grabo points out, the method depends on the external package dsq from Multiprocess Labs. That package allows SQL queries on a number of different data types.

Grabo’s contribution is ob-dsq.el, a package that integrates dsq into the Emacs Org Babel framework. You can get an idea for what it is and how it works from his blog post. Even though my knowledge of SQL is limited, I can see how useful a facility like this can be. If you have a reasonable facility with SQL and are an Emacs user, this seems like it would be a worthwhile package. SQL is a wonderfully expressive way of querying tables and it’s nice to bring it to bear from Emacs. It’s another win if you’re committed to the reproducible research way of working.

The shortest way of seeing what’s going on is to read Grabo’s blog post. If, after reading that, you decide to adopt the system, the other links should tell you everything you need to know.

Posted in General | Tagged , | Leave a comment

Zamansky: Learning Elisp #15

Mike Zamansky has published the latest video in his Learning Elisp series. This is (probably) the last video in his emoji replacement project. In the last video, Zamansky showed how to turn his emoji replacement code into a minor mode. This video cleans things up a bit and explores two other aspects of programming in Elisp.

First off, he shows how configure the minor mode to use either the replace or overlay method for substituting an emoji for a keyword. That’s done with a boolean variable, of course, but rather than use it to test which function to call after every screen update, he uses it to set a function variable that is installed in the appropriate hook.

He mentions, but does not elaborate on, the need to use funcall to actually call the function in the variable. That doesn’t matter here because the variable is used by hook mechanism and not called directly by Zamansky’s code.

The second aspect is how to define the boolean variable. He first considers using devar instead of setq but explains that the proper way of doing it in this instance is with defcustom. Doing it that way allows the user to set the variable using the Emacs Custom interface. That way, the variable can be set once and the values will persist between Emacs invocations but can still be changed whenever the user desires.

Even if you’re familiar with Lisp from, say, Common Lisp or Scheme, the defcustom form will be new and is worth learning about. The video is 11 minutes, 59 seconds so you’ll probably have to schedule some time but as usual with Zamansky’s videos, it will be time well spent.

Posted in General | Tagged , | Leave a comment

Making Ad Hoc SQL Tables From Org Tables

This is the coolest thing. Charles Choi—who contributions I’ve written about several times—has a really surprising post on turning Org tables into ad hoc SQL tables. There are a couple of things that make this a worthwhile endeavor:

  1. It’s easy to do
  2. SQL queries that you make on the SQL table are output as a RESULTS block just like any other Org Babel invocation.

If you’re used to using SQL to query a database table and generate new tables or other results, this a a really handy thing. Choi has an example of a query on a simple table that would hard to do otherwise. The SQL table is held in memory and no actual database is generated, just a table corresponding to the Org table but you can make normal SQL queries on that table and export the results to your Org file.

For those who are familiar with SQL spells this is a tremendous capability. You can operate on “normal” Org tables in the same way you do on SQL database tables. Take a look at Choi’s post and his example to see how handy this can be.

Posted in General | Tagged , | Leave a comment

Racket and SICP

As I’ve written—seemingly hundreds of times—I’m a huge fan of Abelson and Sussman’s Structure and Interpretation of Computer Programs (SICP). In my opinion, it is one of the best—arguably the best—books on Computer Science. I read it relatively late in my career (I was already a senior developer and team lead) and it completely changed the way I thought of our discipline. I learned many, many things that I didn’t know or only dimly understood before.

When I worked through SICP, I used Guile Scheme to play with the examples and work through the problems. That was good but Guile isn’t the Scheme described and used in SICP. That was a version of MIT Scheme. For those of you who want to work through SICP in the original Scheme, Racket has two collections that offer SICP Scheme and the picture language from the book.

I don’t know that this is a big thing: after all, the book isn’t really about Scheme: it’s about computer science and just happens to use Scheme for its examples. Still, a lot of the examples in SICP would be difficult with a non-LISP language and if you consider SICP an historical as well as a Computer Science work, you might enjoy using the original version of Scheme as you read through the book. Happily, Racket makes this possible.

Posted in General | Tagged | Leave a comment

Denote Dynamic Blocks

For some time, Protesilaos Stavrou (Prot) has been working on an Emacs note taking application that he calls Denote. The system is vaguely reminiscent of a Zettlekasten and has a bunch of nice features. It doesn’t depend on Org mode but integrates nicely with it. You can even set up a Denote capture buffer in Org mode.

As I say, the project has been on-going for some time so there’s lots of information and videos about it. The basic idea is that each note is given a unique name that includes a fine grained time stamp, a title, some optional tags, and an extension. That uniqueness and predictability make it easier to organize your notes.

The purpose of this post is to describe Prot’s latest video reporting on an extension to Denote’s dynamic blocks. The TL;DR is that Denote has a special type of note—called a Meta note—that is denoted by the meta tag. The idea of a Meta note is that it contains information about a collection of other notes. That may include, for example, a commentary or summary of the affiliated notes but it’s also possible to (automatically) include links to those notes. The latest changes, described in the video, provide a way of directly including all or part of the associated notes in the Meta file.

I haven’t paid too much attention to Denote until I saw this video. I felt that Org met my note taking needs and didn’t see a reason to adopt a separate application just for notes. After watching Prot’s video, I may give it a try. I like what he’s done with dynamic blocks. Take a look at the video for the details. It’s only 11 minutes, 46 seconds long so it should be easy to fit in. It may convince you to try out the Denote note taking system.

Posted in General | Tagged | Leave a comment

Winner Mode

Ken Huang over at whatacold’s space has a very useful post on Emacs’ winner mode. I was familiar with the name “winner mode” long before I started using it but the name seemed slightly off-putting and offered no clue as to what it did so I ignored it. Later, I somehow discovered1 what it actually did and I’ve been a dedicated user ever since.

The TL;DR is that it will restore your previous window configuration(s). The typical use case is that you perform some temporary action, such as invoking HELP, and afterwards want to return your window configuration to what it was. Winner mode maintains a stack of window configurations so you can restore configurations older than the previous one.

You can also move forward to reestablish the last replaced configuration. The problem with that is that you can move forward only one configuration but I’ve never found that a problem because I almost never want to do that.

One potential problem that Huang points out is that moving back several configurations can be awkward because the default binding is Ctrl+c
, which is slightly hard to type. Huang offers a nice solution for this: a hydra that you invoke with Ctrl+c w and then simply type p to move backward for each configuration.

If you’re a winner-mode user, you may be interested in his hydra. If you want to see it in action, Huang has an embedded video demonstrating winner mode and the hydra. The video is just over 12 minutes so plan accordingly.

Footnotes:

1

Oh. It turns out it was yet more good advice from Phil.

Posted in General | Tagged | Leave a comment

Pike’s Rules Of Programming

I may have mentioned this before but someone recently posted Rob Pike’s 5 Rules of Programming. The rules are simple and beautiful, almost obvious, but very often ignored. The five rules can be condensed into three principles:

  1. Your intuition stinks. If you’re not measuring program performance, you’re flying blind.
  2. Complicated algorithms are generally not worth the overhead.
  3. Data structures, not code are the secret to good programs.

The five rules drill down on those principles a bit and are worth printing out and putting up besides your monitor. As I say, we all tend to forget them and it’s almost always to our detriment. When guys like Pike, Brooks, and Thompson recommend a course of action, it behooves us to pay attention.

Posted in General | Tagged | Leave a comment

Interactive Java

Those of you who have been around Irreal for awhile have heard me preach the gospel of interactive (or exploratory) programming before. I consider it the absolute best and most pleasing way to program. The problem is that it requires a REPL, which not every language offers.

Java is one of those languages that does have a REPL although you almost never hear about it. As far as I can tell, the REPL is merely a way of letting you type in a line input and get the corresponding output: not too useful.

Not too useful unless you’re using Musa Al-hassy’s REPL driven development package. It enables you to use interactive programming techniques with Java as well as several other languages.

Here he is putting together a Java-based photo display application using the interactive programming method. Notice how it’s easy to experiment by making a small change to see how things work before writing the more complex code that does what you want for the final application.

I don’t know Java at all so I can’t comment on whether or not is code is optimal or even good but I do know about interactive programming and can report that he’s captured the method very well. If you’re a Java programmer—or, really, a user of any other REPL enabled language—you should definitely take a look at this video. The video is only 10 minutes, 18 seconds so it should be easy to find some time for it.

Posted in General | Tagged | Leave a comment

Should I Learn Elisp?

Fate_sc over at the Emacs subreddit asks if he should bother to learn Elisp. He’s fairly new to Emacs and is willing to learn Elisp but wonders if it would be worth his while. You see this type of question a lot.

One of Fate_sc’s concerns is that Elisp is “not like” other programming languages and is therefore hard to learn. It’s true that Lisps are different from most other languages but that’s actually a good thing. It’s good because the language has virtually no syntax and is easy to learn. What does make it difficult is the huge run time library. There are hundreds of functions performing all sorts of tasks and in Lisp virtually all actions are realized through functions.

The thing is, though, you don’t have to learn the entire library to be productive. As I’ve said previously, even after more than 15 years I still don’t know all—or even a majority—of the available functions. But as with learning Org, there’s no need to master the whole library to be productive. You can, as Mike Zamansky is currently demonstrating over at C’est La Z, program significant functionality with just a little Emacs. In short, it’s a long journey but one in which you can be highly productive along the way.

The commenters to Fate_sc’s post all agree that it is worthwhile but that each user has to decide for themselves what level of mastery is appropriate for their needs. And it is, as I say, a lot like learning Org: you first learn just enough to make some simple configurations, then a simple editing function, and, then before you know it, you’ll be able to add significant functionality to your Emacs.

Update [2023-11-27 Mon 10:28]: Added link to the reddit post.

Posted in General | Tagged , | Leave a comment

Zamansky: Learning Elisp #14

Mike Zamansky is back with the next chapter in his Learning Emacs video series. The most recent episodes considered writing a framework to replace certain keywords with an emoji. That started with code to simply replace the keyword with the emoji and moved on to using overlays to display the emoji in the display without altering the underlying text.

The current video considers how to make that code into a minor mode. That turns out to be pretty simple. There’s a macro that handles most of the details for you. You just fill in some parameters and everything else is taken care of.

This is a short video—only 8 minutes, 32 seconds—but Zamansky promises to expand on it in coming episodes. I’ve known—in a vague way—for a long time that making a minor mode was pretty easy but I didn’t realize until this video how simple it is. Once you’ve written the code to do whatever it is the mode is supposed to do, making it into a minor mode boils down to a simple macro call.

I’m looking forward to the future videos that flesh out the process a bit more. Even if you don’t want to publish your minor mode, it can still be useful for streamlining your local workflow. If you do want to share, the process is pretty easy.

Posted in General | Tagged , | Leave a comment