[ Content | Sidebar ]

Archives for Lisp

Static vs Dynamic Scope

// start pseudo-code var y = “global”; function print-y() { print(y); } function test-scope() { var y = “local”; print-y(); } test-scope(); // statically scoped languages print “global” // dynamically languages print “local” print-y(); // all languages should print “global” // end pseudo-code This is the standard type of example used to explain what static [...]

“wc”-like Unix Command in Emacs Lisp

Inspired by reading a Steve Yegge blog post. (require ‘cl) (defsubst wc-whitespace-char? () “is current character whitespace?” (not (looking-at “[A-Za-z0-9]“))) (defun wc-buffer (b) “count words in a buffer” (interactive “bBuffer to Analyze “) (let ((word-count 0) (in-word nil) (char-count 0) (line-count 1)) (save-excursion (set-buffer b) (beginning-of-buffer) (while (not (eobp)) (if in-word (if (wc-whitespace-char?) (setq in-word [...]

Understanding Lisp Better

This is the result of a light-bulb going on when reading an info file that introduces emacs lisp. I’m not sure this is legal in other lisps, and it goes against el camino of lisp. But it demonstrates what became clear to me… (defun inc (x) (set x (+ 1 (eval x)))) ;note the intentional [...]