I was writing some Python last night. I couldn't stay on Lisp forever, as much as I'd like to. The code I'm writing has to run on a machine that I don't have control over, so I can't install something like SBCL or even a Scheme implementation. So I'm stuck with the next best thing: Python.
Flowing along test-driven development lines, I was writing some unit tests, and this... "thing" struck me a few times. I was repeating code. Most of it I was able to do away with by abstracting the common bits into helper functions, but there's only so far you can go. I'm still stuck with two unit testing classes that do similar things, but test fundamentally different input classes.
To my dismay, I discovered something.
I disliked writing Python.
Which is weird, because I consider Python a pretty decent language. And there was only one thing from Lisp that I missed: macros. With them, I never would have had to repeat a thing in the first place, and I wouldn't be stuck with two similar unit test classes with nearly the same structure: I'd just write a macro for it.
The sayings were true: Lisp does make programming in any other language unbearable.
Maybe the way to make my units tests more elegant will come to me in a dream or something. Le sigh.
Saturday, April 26, 2008
Tuesday, April 15, 2008
Back-tick-style macros in Scheme
Somebody has been lying to me.
Observe a contrived Common Lisp macro:
Here's a similar macro in Scheme:
Apparently, nobody told me that back-tick-style macros were supported in Scheme. In fact, all I've heard about Scheme macros is stuff about unneeded "pattern matching" involved in using macros.
The people who have claimed this appear to be lying scumbags. Scheme has the back-ticks, the comma, the comma-at, even GENSYM, meaning it's pretty much capable of the same simple macro style that Common Lisp users are used to.
Maybe there's more to it. Hygienic macros and that pattern matching stuff fit somewhere in Scheme.
Observe a contrived Common Lisp macro:
(defmacro print-line (x)
`(format "~a~%" ,x))
Here's a similar macro in Scheme:
(define-macro (print-line x)
`(begin
(display ,x)
(newline)))
Apparently, nobody told me that back-tick-style macros were supported in Scheme. In fact, all I've heard about Scheme macros is stuff about unneeded "pattern matching" involved in using macros.
The people who have claimed this appear to be lying scumbags. Scheme has the back-ticks, the comma, the comma-at, even GENSYM, meaning it's pretty much capable of the same simple macro style that Common Lisp users are used to.
Maybe there's more to it. Hygienic macros and that pattern matching stuff fit somewhere in Scheme.
Friday, April 11, 2008
Inferior Python mode
I just discovered that Emacs has an inferior mode for Python. This means I can get hacking away on a Python file, and send the code to a process right away. It's not the same as being able to alter a running program image, like in Common Lisp or Arc, but for small files, it's damn close.
James is going to freak when I tell him about this.
James is going to freak when I tell him about this.
Subscribe to:
Posts (Atom)