5 ms·
Way too imperative. Tons of undeclared variables. why is 'modo' a macro? Local 'defvar'. Try to write the code shorter. You should be able to write it in about
by lispm 12y ago
Way too imperative. Tons of undeclared variables. why is 'modo' a macro? Local 'defvar'.
Try to write the code shorter. You should be able to write it in about 50%.
Example, from 6 to 3 lines:
; generate a random list of *max-int* integers
(defun randlist (size)
(let ((lst ()))
(dotimes (i size)
(setf lst (cons (random *max-int*) lst)))
lst))
vs.
(defun random-vector (size)
"generate a random vector of *max-int* integers"
(map-into (make-array size) (lambda () (random *max-int*))))
and
; generate random data
(defun gen (size-string)
(when (null size-string)
(setf size-string "4096"))
(setf size (parse-integer size-string :junk-allowed t))
(unless (numberp size)
(error "size must be a number"))
(defvar buffer (randlist size))
(princ (%octets-to-string (coerce buffer 'vector) *encoding*)))
vs.
(defun generate-random-data (&optional (size 4096))
(when (stringp size)
(setf size (parse-integer size :junk-allowed t))
(check-type size integer))
(%octets-to-string (random-vector size) *encoding*))