;ELC ;;; Compiled by mwolson@grepfind.mwolson.org on Thu Jan 24 00:15:30 2008 ;;; from file /stuff/proj/emacs/dvc/mwolson/lisp/dvc-lisp.el ;;; in Emacs version 23.0.50.2 ;;; with all optimizations. ;;; This file uses dynamic docstrings, first added in Emacs 19.29. (if (and (boundp 'emacs-version) (< (aref emacs-version (1- (length emacs-version))) ?A) (or (and (boundp 'epoch::version) epoch::version) (string-lessp emacs-version "19.29"))) (error "`dvc-lisp.el' was compiled for Emacs 19.29 or later")) ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; (byte-code "\301B\302\301!\204\303\301\304\"\210\301\207" [current-load-list dvc-gensym-counter default-boundp set-default 0] 3) #@220 Generate a new uninterned symbol. If PREFIX is a string, then the name is made by appending a number to PREFIX. The default is to use "dvc". If PREFIX is a number, then use that number at the end of the symbol name. (defalias 'dvc-gensym #[(&optional prefix) ";\203 \202\n\304\211\250\203\202 \211T\305\306\307\n#!\310\311 \312BB!\210 +\207" [prefix dvc-gensym-counter num symbol "dvc-gensym-uniq-" make-symbol format "%s%d" eval defvar (nil "lint trap")] 6 (#$ . 728)]) #@245 Traverse list L, replacing captured symbols with newly generated symbols. A pair is added to `captured-values' for each new symbol, containing the name of the new symbol and the name of the old symbol. This is used by `dvc-capturing-lambda'. (defalias 'dvc-capturing-lambda-helper #[(l) ":\204\207@\305=\2035\211A@)\2119\204\306\307\n\"\210\310\n \"@\211\2042\311 \211\nB B\f*\207\312\313\"\207" [l x sym captured-values g capture error "Expected a symbol in capture statement: %S" rassq dvc-gensym mapcar dvc-capturing-lambda-helper] 4 (#$ . 1223)]) #@1734 Return a `lambda' form with ARGS, containing BODY, after capturing symbol values in BODY from the defining context. Symbols to be captured should be surrounded by (capture ...). The remainder of BODY's forms are left as-is. For development on DVC, using either `dvc-capturing-lambda' or `lexical-let' is acceptable, with the condition that you must use one consistently within a particular source file. A practical example: ;; Using dvc-capturing-lambda (defun sort-by-nearness-1 (values middle) "Sort VALUES in order of how close they are to MIDDLE." (sort values (dvc-capturing-lambda (a b) (< (abs (- a (capture middle))) (abs (- b (capture middle))))))) (sort-by-nearness-1 '(1 2 3 4 8 5 9) 6) => (5 4 8 3 9 2 1) ;; Using backquote (defun sort-by-nearness-2 (values middle) "Sort VALUES in order of how close they are to MIDDLE." (sort values `(lambda (a b) (< (abs (- a ,middle)) (abs (- b ,middle)))))) (sort-by-nearness-2 '(1 2 3 4 8 5 9) 6) => (5 4 8 3 9 2 1) ;; Using lexical-let (defun sort-by-nearness-3 (values middle) "Sort VALUES in order of how close they are to MIDDLE." (lexical-let ((middle middle)) (sort values (lambda (a b) (< (abs (- a middle)) (abs (- b middle))))))) (sort-by-nearness-3 '(1 2 3 4 8 5 9) 6) => (5 4 8 3 9 2 1) An example for the well-read Lisp fan: (let* ((x 'lexical-x) (y 'lexical-y) (l (dvc-capturing-lambda (arg) (list x (capture y) arg)))) (let ((y 'dynamic-y) (x 'dynamic-x)) (funcall l 'dummy-arg))) => (dynamic-x lexical-y dummy-arg) (defalias 'dvc-capturing-lambda '(macro . #[(args &rest body) "\303\304 !\305\306\307\nD\305\310\311\312\n\313\314\"\" BB\312\313\315\n\"\305\316\305\313\317\"BEC\"BBBF*\207" [captured-values body args nil dvc-capturing-lambda-helper list 'lambda quote 'apply lambda append mapcar car #[(arg) "\301D\207" [arg quote] 2] 'quote cdr] 14 (#$ . 1800)])) (byte-code "\300\301\302\303#\210\300\301\304\305#\207" [put dvc-capturing-lambda lisp-indent-function 1 edebug-form-spec (sexp body)] 4) #@84 Replace instances of quoted lambda forms with `lexical-let' in the current buffer. (defalias 'dvc-lexical-let-perform-replacement-in-source #[nil "eb\210\306\307\310\311#\205\226\312\313!\210\212\314\315!\210\316c\210)\317\315!\210\320c\210\312\321!\210`\322\310\314\315!\210\214\n`}\210eb\210\306\323\310\311#\203\202\317\315!\210`\314\315!\210`\324 \f\"\325\326\327 #\330P \235\204s B \211\322\230?\205j\331\313\331 \316\260 \f|\210 b\210c\210,\2025eb\210\306\320!\210\313 \316\261\210\332 \210,\202\207" [namelist letlist beginning beg end name search-forward "`(lambda" nil t search-backward "(" forward-sexp 1 ")" backward-delete-char "(lexical-let " "(lex" "" "," buffer-substring-no-properties replace-regexp-in-string "[^a-zA-Z\\-]" "-" "-lex" " " newline-and-indent var] 7 (#$ . 4032) nil]) #@93 Replace instances of quoted lambda forms with `dvc-capturing-lambda' in the current buffer. (defalias 'dvc-capturing-lambda-perform-replacement-in-source #[nil "eb\210\301\302\303\304#\205C\305\224\305\225|\210\306c\210\307\310!\210`\311\312!\210\214`}\210eb\210\301\313\303\304#\203?\314\312!\210\315c\210\311\312!\210\316c\210\202&*\202\207" [beginning search-forward "`(lambda" nil t 0 "(dvc-capturing-lambda" search-backward "(" forward-sexp 1 "," backward-delete-char "(capture " ")"] 4 (#$ . 4863) nil]) (provide 'dvc-lisp)