MochiKit by Example
Ryan Wilcox has recently written an excellent article for Linux Journal: MochiKit by Example. Check it out!
from __future__ import * Ryan Wilcox has recently written an excellent article for Linux Journal: MochiKit by Example. Check it out!
simplejson is a simple, fast, complete, correct and extensible JSON (RFC 4627) encoder/decoder for Python 2.3+. It is pure Python code with no dependencies.
simplejson 1.7 is a minor update that improves encoding performance with an optional C extension to speed up str/unicode encoding (by 10-150x or so), which yields an overall speed boost of 2x+ (JSON is string-heavy). Additionally 1.7 adds support for encoding unicode code points outside the BMP to UTF-16 surrogate code pairs (specified by the Strings section of RFC 4627).
In the comments of my post on Erlang Mode for Emacs Tobbe pointed me at the new Distel repository for Distel. I had originally tried to install Distel last year when I began with Erlang but it didn't work. It works now! Here's the deal.
Check out Distel. In my case I'm going to check it out to /Users/bob/src/distel:
$ cd /Users/bob/src $ svn co http://distel.googlecode.com/svn/trunk distel
Configure and compile Distel:
$ ./configure $ make
Configure Distel and configure Erlang mode, ensure that the inferior Erlang shell has an explicit node name of emacs so that Distel can connect to the. Here's my full .emacs:
(add-to-list 'load-path "/usr/local/lib/erlang/lib/tools-2.5.3/emacs")
(setq erlang-root-dir "/usr/local/lib/erlang")
(setq exec-path (cons "/usr/local/lib/erlang/bin" exec-path))
(require 'erlang-start)
(add-to-list 'load-path "/Users/bob/src/distel/elisp")
(require 'distel)
(distel-setup)
;; prevent annoying hang-on-compile
(defvar inferior-erlang-prompt-timeout t)
;; default node name to emacs@localhost
(setq inferior-erlang-machine-options '("-sname" "emacs"))
;; tell distel to default to that node
(setq erl-nodename-cache
(make-symbol
(concat
"emacs@"
;; Mac OS X uses "name.local" instead of "name", this should work
;; pretty much anywhere without having to muck with NetInfo
;; ... but I only tested it on Mac OS X.
(car (split-string (shell-command-to-string "hostname"))))))
Add Distel to your ~/.erlang so that it's on your Erlang code path:
$ echo 'code:add_pathsz(["/Users/bob/src/distel/ebin"]).' >> ~/.erlang
If the Distel installation was done properly your Emacs mode line will be displayed as (Erlang EXT) next time you're editing an Erlang module. If you get a "nodedown: ..." message when executing a Distel command that means you haven't started a shell yet (C-c C-z). A good test is to stick your insertion point at a function name and hit M-. to get to its definition. M-TAB is auto-completion. I haven't used too much else from it yet.
(Now here's to hoping I don't have to learn any more elisp, ever).
Erlang ships with a quite nice Erlang mode for Emacs. Editing Erlang code is actually the only thing I ever use Emacs for.
Setting it up is only slightly painful. For a default R11B-3 installation your .emacs will look like this:
(setq load-path (cons "/usr/local/lib/erlang/lib/tools-2.5.3/emacs"
load-path))
(setq erlang-root-dir "/usr/local/lib/erlang")
(setq exec-path (cons "/usr/local/lib/erlang/bin" exec-path))
(require 'erlang-start)
(defvar inferior-erlang-prompt-timeout t)
The first set of expressions sets up Emacs to find erlang.el and the path to your Erlang installation.
The second expression tells the emacs mode not to wait for an Erlang prompt. This is my only annoyance with the mode. Without this defvar, when you send a command from Emacs to Erlang it'll hang for 60 seconds (or until you hit Ctrl-G) if there was any IO since the last prompt (e.g. an error_logger report or an io:format call). The caveat with this setting is that the first command you issue (the one that causes the inferior shell to get started) will get sent before Erlang is started and get lost. Issuing the first command twice is a small price to pay in this case, because the lock-up is annoying as all hell when you're in the middle of the compile/play cycle.
Using the Erlang mode is pretty straightforward. Tab does the right thing for indentation and is a good way to check to see if your code makes sense syntactically. If it doesn't indent to the right place, you probably screwed up. The electric stuff like comma and semicolon are great and save you a good deal of typing. The only command I really use is C-c C-k which compiles and reloads the current module into the running Erlang inferior shell. It will start one if one isn't already running (C-c C-z just starts the shell).
The other gripe I have is that when you get compiler errors sometimes clicking the line numbers takes you to the wrong line in the source file, but that's a relatively minor annoyance for me. Restarting seems to fix that (until it breaks again) and normally I'm not fighting too many compiler errors :)
Erlang finally has a book out in print again (almost): Programming Erlang, written by Joe Armstrong. The best part of the story is that the publisher is allowing a combo purchase of a beta PDF plus the print book when it's available. How cool is that? I think this model makes a lot of sense with the speed that technologies move these days. Imagine how much they could have made riding the Ruby on Rails hype train a few months earlier than any other publisher with a 70% finished beta PDF plus a print book when available?
I've purchased the book and read through what's available in the beta PDF so far. It definitely does not disappoint: this is the Erlang book and it will be for some time to come.
If you're particularly interested I also highly recommend reading Joe Armstrong's doctoral thesis paper (Making Reliable Systems in the Presence of Software Errors), which has a lot of overlap with what the beta PDF covers and what the book will cover when it's finished. There's also a lot of interesting information in the thesis that may or may not end up in the book such as the history and evolution of Erlang and some interesting case studies.
simplejson is a simple, fast, complete, correct and extensible JSON encoder/decoder for Python 2.3+. It is pure Python code with no dependencies.
simplejson 1.6 is a minor update that improves str support for encoding. Previous versions of simplejson integrated strings directly into the output stream, this version ensures they're of a particular encoding (default is UTF-8) so that the output stream is valid. See the documentation for more information.
Powered by WordPress
© Bob Ippolito < bob at redivi.com >