Skip to content

Instantly share code, notes, and snippets.

@jordonbiondo
Created April 4, 2014 20:12
Show Gist options
  • Select an option

  • Save jordonbiondo/9982289 to your computer and use it in GitHub Desktop.

Select an option

Save jordonbiondo/9982289 to your computer and use it in GitHub Desktop.
(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