Sep 25

For a long time, I’ve been building GNU Emacs for OS X with the carbon interface enabled. It’s been alright, true enough. But recently I stumbled upon Aquamacs, and it’s like all of my emacs prayers have been answered.

Take Aquamacs, add Markdown Mode and possibly weblogger.el, and you have the strongest blogging tool ever conceived. I feel funny being so excited about that, but I suppose I spend more time blogging than programming, nowadays! Strange…

Anyway, I’ve noticed that since I’ve been using that setup, my posts on my main blogs like move the markets and unaspected tend to be longer and better organized. The only drawback is that when I want to post a picture, so far I still have to go to my wordpress web interface to get the pics uploaded and processed into thumbnails, etc. Maybe if wordpress has APIs for all that, I can hack it into emacs as well. We’ll see…

The most recent version of Aquamacs has soft newlines available as an option, similar to what I think longlines mode did. This is a great feature to have, along with options in the edit menu to insert or remove the hard newlines in a buffer. I find that soft newlines work much better when I post my markdown output to wordpress, as wordpress converts hard newlines to <br/> tags. Yuck!

Sep 23

When designing a programming language, I always reach a few decision points where I have to choose between two options that both sound good to me. One of those is whether to allow variable arguments (a la scheme), or do automatic currying (a la haskell). Other languages have these features, but I pick on scheme and haskell because they are my favorites, and I use both often.

Anyway, I like both of these features, and use them a lot in languages that provide them. Sadly, it doesn’t seem too clean to have both at the same time. To curry you need to know how many arguments are coming, and to accept zero arguments you can’t auto-curry. They just aren’t very compatible features.

I mean, in scheme you can define the + function to take any number of arguments, including no arguments at all:

(+ 1 2)        ; valid
(+ 1 2 3 4 5)  ; valid
(+)            ; valid

That’s really cool. Haskell’s idiom seems to be to define a second function that accepts a list as an argument:

1 + 2   -- or "sum [1,2]" of course
sum [1, 2, 3, 4, 5]
sum []

You might think that the list-accepting function takes care of the issue on haskell’s end. But, it accepting a variable number of arguments turns out to be really useful in a variety of contexts, like map:

(map + '(1 2 3))                    ; valid
(map + '(1 2 3) '(4 5 6))           ; valid
(map + '(1 2 3) '(4 5 6) '(7 8 9))  ; valid

… whereas in haskell we need both map and the zipWith family to handle a similar task:

map id [1,2,3]
zipWith (+) [1,2,3] [4,5,6]
zipWith3 (\a b c-> a+b+c) [1,2,3] [4,5,6] [7,8,9]

Note that in the third case, we can’t use the sum function, since zipWith3 doesn’t pass the 3 arguments as a list. I suppose a version of map could be made which takes a function that operates on lists, along with a list of lists to zip over:

mapVariable sum [[1,2,3],[4,5,6],[7,8,9]]

… and for all I know that function’s already in the GHC libraries somewhere. But, making list versions of everything certainly doesn’t feel very efficient or haskell-like to me.

So, in this example, I’d say the scheme style definitely wins, in terms of using similar-looking code to accomplish similar-looking tasks.

However, I don’t see how I can support scheme-style variable args and also allow familiar auto-currying haskellisms like: map (+1) lst. In scheme, that example would look like:

(map (lambda (x) (+ 1 x)) lst)

It’s just not the same! With srfi-26, you can type:

(map (cut + 1 <>) lst)  ; srfi-26

… which is slightly nicer, I guess. But only slightly.

The automatic currying is also very useful when defining functions. I often write functions like:

fooize = map foo

… which in scheme must be much more explicit about grabbing the parameter and passing it to the function:

(define (fooize lst) (map foo lst))

So, we’ve defintely lost some brevity. However, I usually come down on the scheme side of this argument when designing little extension languages. I think it looks very clean to be able to use the same function name on variable numbers of arguments, and I can still manually curry functions even if it is more verbose.

Are there any valid compromises? Like, say, auto-curry all functions that don’t accopt variable numbers of arguments? Or auto-curry all functions until you have at least as many arguments as you need to fully apply the function? Those options seem confusing at best, and don’t work very well anyway for the toy cases like the + function. If your language has macros, then you can do like some people have done and make macros that allow you to auto-curry individual functions:

(define-curried (foo x y z) (+ x (/ y z)))
((foo 3) 1 2)
((foo 3 1) 2)

But, again, this leads to confusing programs in my opinion… where different functions seem to get different treatment. I haven’t been able to come up with any workable compromises… so when I put together a language, I just pick one approach or the other.

Sep 4

Here’s a tip for when you notice you are editing a file with silly dos
^M endings in emacs. I know it doesn’t really matter, but I can’t
stand seeing the little (DOS) notice sitting in the mode line. So:

Just introduce a change to the file, like hit the spacebar and then
delete the space, or whatever. This way, emacs will want to write out
the file next time you save it. Then use this command:

C-x RET c utf-8-unix

… and when it prompts you for the command to run as utf-8-unix, ask
it to save the file: C-x C-s

Now you have a utf8-encoded file with unix line endings. Perfect!