(think)

An online novel about the Source, the Force, the real life and everything in between...

Clojure-mode 3.0

clojure-mode 3.0 is out!

It’s one of the most ambitious releases in recent times and brings much improved font-locking across the board. Other notable changes include dropping support for Emacs 23 (CIDER doesn’t support it either) and removing some deprecated features (most notably the functionality for switching between code and its test; see Projectile for an awesome replacement of the old feature).

An extensive list of the changes is available here.

This version also marks the introduction of an automated test suite (currently it consists mostly of font-lock tests), which should make it easier to do changes in the future.

Next step – indentation improvements and decoupling clojure-mode from lisp-mode. Both tasks are related. We’ve been deriving much from lisp-mode since day 1 and this has worked reasonably well so far, but the truth is that Clojure is not Common Lisp (or Emacs Lisp for that matter) and would benefit from a more refined syntax table, indentation rules, etc.

When (if) this will happen? Sadly, I have no idea… Help is definitely welcome! If you don’t have the time to help out with code or docs you can still support my work on clojure-mode (and all my other projects) via gittip.

Support via Gittip

That’s all for now, folks! Enjoy the new clojure-mode!

SICP Distilled

SICP Distilled is one of the most interesting Kickstarter projects I’ve seen in a while.

Its creator Tom Hall is planning to create some nice companion resources for SICP with code examples in Clojure. In his own words:

It’s a long book, with lots
of exercises and lots of people I know have started, loved it, but
somehow not finished.

Abelson and Sussman themselves highlight the important lessons of SICP
in their paper `Lisp: A Language For Stratified Design` and I have my
own favourite bits.

As the book itself is available online for free I want to make the
perfect accompaniment to it - an ebook summarising the key ideas,
short videos describing them, screencasts of solving some of the
exercises, translation of the examples into Clojure, example projects,
partial solutions for you to complete (similar to `4clojure` and `Clojure
koans`) and a place to discuss solving them with people and hopefully
keep momentum and get it finished!

Something to be enjoyed alongside SICP, rather than completely replace it.

Maybe some ideas come out a little different in Clojure, or I take a
slightly novel approach (hence idiosyncratic), maybe I miss something
out (hence tour, sorry), but I hope we can have some fun along the
way.

Tom Hall SICP Distilled

I’m one of those many people who never did finish SICP (although I hope to do that some day), so I can totally relate to Tom’s words. I’ve already backed his campaign and I hope more of you will do the same!

The Elements of Style in Ruby #14: Variable Interpolation

Most experienced Rubyists probably know that there are two ways to interpolate instance, class and global variables into strings.

1
2
3
4
5
# compact notation (works only for instance/class/global vars)
"this is #$some_var"

# standard notation (works for any expression)
"this is #{$some_var}"

As you’ve noticed you can leave out the {} which can’t be left out for any other expression. Some people find this interpolation syntax concise and elegant, but I’ll argue that it should be avoided. Here’s why:

  • You can’t use this notation in every possible scenario:
1
2
3
4
5
# this is fine
puts "#{@variable}string_straight_after_without_space"

# but this means something totally different
puts "#@variablestring_straight_after_without_space"

This means that using the compact notation only when applicable forces you to introduce some inconsistency in your code. This is rarely good…

  • You’re using different notations for the same basic operation (interpolation), without getting anything in return. That’s not the same with semantic use of single and double quoted strings or fail and raise.
1
2
3
4
5
6
7
# using compact
"this is #@x"
"this is #{x}"

# using standard
"this is #{@x}"
"this is #{x}"
  • It’s easy to make a mistake in the context of a regular expression (as interpolation works in regexp literals). Recently I saw the following regexp – /[0-9.(),;:!?%#$?\x27\x22_+=\\\/\-]*/. There’s a subtle problem with it, that’s not obvious (unless you have a good editor, that is). The sequence #$? is interpreted as interpolation of the global variable $? (a.k.a. $CHILD_STATUS) and this regexp doesn’t work as intended.

This scenario shows that the syntax was ill-conceived.

  • Non-experience Rubyists probably don’t know about the compact interpolation notation. Few books and tutorials mention it these days, so using it your code will confuse at least some of the people reading it.

It seems to me that Ruby will be better off without a special syntax for variable interpolation. Ideally it would be removed in Ruby 3 and we’ll have one less thing to worry about in our Ruby code.

That’s all for today, folks!

As usual I’m looking forward to hearing your thoughts here and on Twitter!

The State of Some Emacs Packages for Clojure Development

There are quite a few packages in the “official” clojure-emacs GitHub organization, but many of them have been deprecated recently with the release of CIDER 0.7. Unfortunately not everyone is aware of this yet and I often see tickets related to those deprecated projects. In this short post I’ll outline the deprecations and provide a bit of background for them.

clojure-test-mode

The venerable clojure-test-mode was deprecated in favor of cider-test (which is bundled with CIDER 0.7). clojure-test-mode featured quite a lot of inlined Clojure code, which made the package very hard to maintain and reworking it to use nREPL middleware was a no-brainer for us. clojure-test-mode will be removed from the clojure-mode repo at some point. It also interferes with CIDER’s initialization, so you’re strongly encouraged to get rid of it.

Down the road we might extend cider-test to support other test frameworks as well (which should be feasible with different middleware providing the same interface).

company-cider

company-cider was deprecated, because company-mode integration was added to CIDER itself (making company-mode the officially supported and recommended completion library).

ac-nrepl

ac-nrepl has been superseded by ac-cider. ac-cider has a simpler codebase and leverages the compliment-based completion introduced in CIDER 0.7. We’ll probably remove ac-nrepl at some point in the future to avoid the confusion between the two.

cider-inspect

cider-inspect was absorbed into CIDER 0.7.

cider-tracing

cider-tracing was superseded by middleware-based tracing support integrated in CIDER 0.7.

Epilogue

Those deprecations are also mentioned in the documentation of the respective packages, but I feel it’s nice to have them listed together in a single document. Most of the packages will also emit load-time deprecation warnings.