Skip to content

Instantly share code, notes, and snippets.

@jordonbiondo
Last active August 29, 2015 14:20
Show Gist options
  • Select an option

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

Select an option

Save jordonbiondo/4918ac0043af4b3889fd to your computer and use it in GitHub Desktop.
cycle lisp forms
;; because, why not?
(setq lexical-binding t)
(defmacro cycle-forms (&rest forms)
(let ((sym (make-symbol "sym"))
(n 0)
(l (length forms)))
(set sym 0)
`(case (prog1 ,sym
(incf ,sym)
(when (= ,sym ,l) (setq ,sym 0)))
,@(mapcar (lambda (form) (list (1- (incf n)) form)) forms))))
(defun my-func1 ()
(message "in my func 1"))
(defun my-func2 ()
(message "in my func 2"))
(defun my-func3 ()
(message "in my func 3"))
(defun my-toggling-function ()
(cycle-forms
(my-func1)
(my-func2)
(my-func3)))
(my-toggling-function) ;; => "in my func 1"
(my-toggling-function) ;; => "in my func 2"
(my-toggling-function) ;; => "in my func 3"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment