;;lecture 2 (defun da(name)(disassemble name)) ;save typing (da 'foo) (defmacro da(name)`(disassemble ',name)) ;save typing (da foo) note backquote (defun foo(x y) (+ x y)) ;; (defun foo2(x y) (declare (optimize (speed 3)(safety 0)))(+ x y)) (defun foo3(x y) (declare (optimize (speed 3)(safety 0)) (fixnum x y)) (+ x y)) (defun tester3(n) (dotimes (i n)(foo3 3 4))) (defun tester(n)(dotimes (i n)(foo 3 4))) (defun tester3f (n)(declare (optimize (speed 3)(safety 0)) (fixnum n)) (dotimes (i n)(foo3 3 4))) ;; (use-package :prof) ;; (start-profiler) ;; .... ;; (show-flat-profile) ;; be sure to compile if you want stuff to run faster ;; UNICODE... ;; (code-char #x0141) ;;#\latin_capital_letter_l_with_stroke (format t "~x" (code-char #x0141)) ;; character in CL may be unicode. ;; this returns to a simpler world.. ;; (aref letter-lookup 97) --> #\a ;; (char-code #\a) --> 97 ;; (format t "~a" #x321) (defparameter letter-lookup (make-array 127 :element-type 'character :initial-element #\space)) (loop for i in (coerce "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-+,.:[]{}:;\"\\|!@#$%^" 'list) do (setf (aref letter-lookup (char-code i))i)) (defparameter letter-symbols (make-array 127 :initial-element nil)) (loop for i in (coerce "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789-+,.:[]{}:;\"\\|!@#$%^" 'list) do (setf (aref letter-symbols (char-code i))(intern (format nil "~a" i)))) ;; letters are locations 65 to 122, first the capitals. (defun randomx(n)(aref letter-symbols (+ 65 (random n)))) (defun randomlist(len vars) (let ((ans nil)) (dotimes (i len ans) (push (randomx vars) ans)))) (defun randomprod0 (len vars) (let ((ht(make-hash-table :test #'eq)) (ans nil)) (dotimes (i len ans) (incf (gethash (randomx vars) ht 0))) (maphash #'(lambda(key val)(push (cons key val)ans)) ht) ans)) (defun randomprod (len vars) (let ((ht(make-hash-table :test #'eq)) (ans nil)) (dotimes (i len ans) (incf (gethash (randomx vars) ht 0))) (maphash #'(lambda(key val)(push (cons key val)ans)) ht) (sort ans #'(lambda(r s)(string< (symbol-name r)(symbol-name s))) :key #'car )))