src/utils.lisp @ 69f98eb3a1df

Mini 5: Pythagorean Theorem and Distance
author Steve Losh <steve@stevelosh.com>
date Fri, 22 Apr 2016 23:13:31 +0000
parents 2278039315fa
children 67072984548b
(in-package #:coding-math.utils)

(defun dividesp (n divisor)
  "Return whether `n` is evenly divisible by `divisor`."
  (zerop (mod n divisor)))

(defun square (n)
  "Return the square of `n`."
  (* n n))


(defmacro mulf (place n &environment env)
  "Multiply `place` by `n` in-place."
  (multiple-value-bind (temps exprs stores store-expr access-expr)
      (get-setf-expansion place env)
    `(let* (,@(mapcar #'list temps exprs)
            (,(car stores) (* ,n ,access-expr)))
       ,store-expr)))


(defun a (alist key) ; lol
  (cdr (assoc key alist)))

(defmacro in-context (&body body)
  `(prog1
    (push-matrix)
    (progn ,@body)
    (pop-matrix)))