Skip to content

Instantly share code, notes, and snippets.

@rebcabin
Created December 4, 2015 15:49
Show Gist options
  • Select an option

  • Save rebcabin/5b3208cc3d431d04651a to your computer and use it in GitHub Desktop.

Select an option

Save rebcabin/5b3208cc3d431d04651a to your computer and use it in GitHub Desktop.
A MVE for StackOverflow question 34079242

Macrology

1 Version information

Emacs version: GNU Emacs 24.5.1 (x86_64-apple-darwin13.4.0, NS apple-appkit-1265.21)
 of 2015-04-10 on builder10-9.porkrind.org
org version: 8.3.1

2 Units

2.1 Unit of Time

(defmacro unit-of-time  (value unit)
  `(* ,value
      ,(case unit
        ((s) 1)
        ((m) 60)
        ((h) 3600)
        ((d) 86400)
        ((ms) 1/1000)
        ((us) 1/1000000))))
UNIT-OF-TIME

3 Named Let

(defmacro nlet (n letargs &rest body)
  `(labels ((,n ,(mapcar #'car letargs)
              ,@body))
     (,n ,@(mapcar #'cadr letargs))))

3.1 Test

(defun nlet-fact (n)
  (nlet fact ((n n))
        (if (zerop n)
            1
            (* n (fact (- n 1))))))

(nlet-fact 60)
8.32098711274139e+81
(setf *pretty-print* nil)
(defun fact (n)
  (if (= 0 n)
      1
      (* n (fact (- n 1)))))

(fact 60)
8.32098711274139e+81
(defun range (max &key (min 0) (step 1))
  (loop for n from min below max by step
        collect n))

(range 60)
01234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment