diff --git a/functions.lisp b/functions.lisp index 81a34dc..4c7bb81 100644 --- a/functions.lisp +++ b/functions.lisp @@ -10,6 +10,18 @@ (defparameter *green* (color 1 32)) (defparameter *yellow* (color 0 33)) +;; simple hash function (Fowler Noll Vo) +;; https://en.wikipedia.org/wiki/Fowler%E2%80%93Noll%E2%80%93Vo_hash_function +(defun fnv-hash(string) + "return a hash from a string" + (let ((FNV_prime 2) + (hash 26123230013)) + (loop for octet-of-data across string + do + (setf hash (* FNV_prime + (logxor hash (char-code octet-of-data))))) + hash)) + ;; common-lisp don't have a split string function natively (defun replace-all (string part replacement &key (test #'char=)) (with-output-to-string (out) @@ -72,8 +84,9 @@ (or ,@body))) (defun =>(level fonction &rest params) - (format t "[~a~a ~20A~a] ~35A" *yellow* level fonction *white* (getf params :desc params)) - (let ((result (funcall fonction params))) + (format t "[~a~a ~20A~a] ~45A" *yellow* level fonction *white* (getf params :desc params)) + (let ((hash (fnv-hash (format nil "~{~a~}" (nconc (list level fonction) (remove-if #'symbolp params))))) + (result (funcall fonction params))) (if (not (listp result)) (progn (format t " => ~asuccess~a~%" *green* *white*)