Last active
August 29, 2015 14:20
-
-
Save jordonbiondo/4918ac0043af4b3889fd to your computer and use it in GitHub Desktop.
cycle lisp forms
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
| ;; 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