Created
April 4, 2014 20:12
-
-
Save jordonbiondo/9982289 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (defmacro value-bound-lambda (symbols &rest body) | |
| (declare (indent defun)) | |
| (let ((vars (remove-if-not 'boundp symbols)) | |
| (funcs (remove-if-not 'functionp symbols))) | |
| `(lambda () | |
| (let ,(mapcar (lambda (sym) (list sym (symbol-value sym))) vars) | |
| ,@(mapcar (lambda (sym) `(fset ',sym ,(symbol-function sym))) funcs) | |
| ,@body)))) | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| ;; Example | |
| ;; ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;; | |
| (defvar foobar "foobar") | |
| (defvar fizzbuzz "fizzbuzz") | |
| (defun slow-vowel-remover (str) | |
| "Returns STR with no vowels after a while." | |
| (require 'cl) | |
| (let ((vowel-list (string-to-list "aeiou"))) | |
| (apply 'string (remove-if | |
| (lambda (c) (sit-for .15) (member c vowel-list)) | |
| (string-to-list str))))) | |
| (progn (async-start | |
| (value-bound-lambda (foobar fizzbuzz slow-vowel-remover) | |
| (sit-for 1) | |
| (concat (slow-vowel-remover foobar) (slow-vowel-remover fizzbuzz))) | |
| (lambda (result) | |
| (message "result: %s" (propertize result 'face | |
| '(:foreground "green")))))) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment