Warning: ob_start(): non-static method wpGoogleAnalytics::get_links() should not be called statically in /home/w01fe/w01fe.com/wordpress/wp-content/plugins/wp-google-analytics/wp-google-analytics.php on line 259
A Blog. » Programming

Archive for Programming

Treat LaTeX command definitions as Textmate symbols

I wanted LaTeX newcommand/renewcommand definitions to show up in the Textmate symbol list, so I could use the Cmd-Shift-T shortcut to jump to them. To accomplish this, I first went to the “LaTeX Language” entry in the bundle editor, and added this block to the “patterns” section:

{	name = 'latex.definition';
	match = '(\\)(newcommand|renewcommand)\{[^\}]+\}';

Then, I created a new LaTeX Preference with scope selector “latex.definition”, and contents:

{	showInSymbolList = 1;
	symbolTransformation = '


Reversing the order of Clojure’s exception chains in SLIME

When debugging a complex Clojure project with SLIME, I would often find myself chasing chains of exceptions as much as 20 levels deep to get to the true cause of a problem. I finally tired of the “11111111111”-look-“0000000000” exercise, especially since in my experience the most useful stack traces are almost always the innermost ones.

Thus, I decided to modify swank-clojure to present exceptions in the opposite order: rather than starting with the caught exception and providing the option to examine its “Cause”, start with the innermost cause and allow examining its “Source”. In addition to providing the must useful stack traces up front, this also means that the first thing you see in the SLDB window is the real exception, not a mess of RuntimeExceptions.

For the interested, I posted the change on GitHub; it’s my first real change to anything SLIME, so take care if you decide to use it.


Dynamic type hints in Clojure macros

Sometimes, one wants to write a Clojure macro to assist in Java interoperability, where the object types are determined by the arguments to the macro. In this situation, the normal strategy of using a #^class type hint doesn’t work, since the class isn’t known at read time. Here’s a very contrived example, where the macro declare-first-char defines a function first-char, which calls the (.charAt % 0) method on its argument. The class for the type hint is passed as an argument to the macro.

user> (set! *warn-on-reflection* true)
user> (defmacro declare-first-char [cls]
	(let [x (gensym)]
	  `(defn first-char [~(with-meta x {:tag cls})] 
             (.charAt ~x 0))))
user> (declare-first-char String)
#'user/first-char ; No reflection warning!
user> (first-char "test")

The key here is the [~(with-meta x {:tag cls})] fragment, which replaces the normal [#^String x#] version that could be used if the type was known in advance.

Comments (1)

« Previous entries Next Page » Next Page »