Skip to content

Commit

Permalink
Move COPY method definitions.
Browse files Browse the repository at this point in the history
There were default `copy` method definitions in the file toolkit.lisp
that was loaded before the (macro-generated) `defgeneric` for `copy`,
in generator.lisp.

This made SBCL grumpy, so I moved the two `copy` method definitions
into generator.lisp.
  • Loading branch information
rpgoldman committed Aug 18, 2023
1 parent c697105 commit caf470a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
14 changes: 13 additions & 1 deletion generator.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@
(if *print-readably*
(call-next-method)
(print-unreadable-object (generator stream :type T)
(format stream "~s" (seed generator))))
(format stream "~s" (seed generator))))
;; P-U-O does not return the object, which PRINT-OBJECT is supposed to do.
generator)

Expand Down Expand Up @@ -77,6 +77,18 @@
(define-generator-fun bits-per-byte (generator))
(define-generator-fun copy (generator))

;;; supporting methods for COPY
(defmethod copy ((thing number))
thing)

(defmethod copy ((thing array))
(make-array (array-dimensions thing)
:element-type (array-element-type thing)
:fill-pointer (array-has-fill-pointer-p thing)
:adjustable (adjustable-array-p thing)
:initial-contents thing))


(defun make-generator (type &optional (seed T) &rest initargs)
(let ((generator (apply #'%make-generator type initargs)))
(when seed (reseed generator seed))
Expand Down
10 changes: 0 additions & 10 deletions toolkit.lisp
Original file line number Diff line number Diff line change
Expand Up @@ -66,16 +66,6 @@
(defmacro update (bits place op &rest args)
`(setf ,place (fit-bits ,bits (,op ,place ,@args))))

(defmethod copy ((thing number))
thing)

(defmethod copy ((thing array))
(make-array (array-dimensions thing)
:element-type (array-element-type thing)
:fill-pointer (array-has-fill-pointer-p thing)
:adjustable (adjustable-array-p thing)
:initial-contents thing))

(defun histogram (rng bins &key (samples (floor 1e8)) (width 80) (stream *standard-output*))
(declare (notinline random))
(check-type samples (unsigned-byte 64))
Expand Down

0 comments on commit caf470a

Please sign in to comment.