Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
ansi-test
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Deploy
Releases
Container Registry
Model registry
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Michał Herda
ansi-test
Commits
fcf82c40
Commit
fcf82c40
authored
19 years ago
by
pfdietz
Browse files
Options
Downloads
Patches
Plain Diff
Added RANDOMIZED method combination, I intend to rewrite MAKE-RANDOM-TYPE-CONTAINING to use this
parent
1df86fcb
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
ansi-tests/random-aux.lsp
+21
-0
21 additions, 0 deletions
ansi-tests/random-aux.lsp
with
21 additions
and
0 deletions
ansi-tests/random-aux.lsp
+
21
−
0
View file @
fcf82c40
...
...
@@ -34,6 +34,7 @@
(total (car (last cumulative-weights)))
(r (gensym)))
(assert (every #'plusp weights))
(when (typep total 'ratio) (setf total (coerce total 'double-float)))
`(let ((,r (random ,total)))
(cond
,@(loop for case in (butlast cases)
...
...
@@ -257,3 +258,23 @@
(make-list p :initial-element 1))
(t (mapcar #'1+ (random-partition* (- n p) p)))))
;;; Random method combination
;;; Methods in this method combination take a single method qualifier,
;;; which is a positive integer. Each method is invoked
;;; with probability proportional to its qualifier.
;;;
;;; Inside a method, a throw to the symbol FAIL causes
;;; the application to repeat. This enables methods to abort
;;; and retry the random selection process.
(defun positive-integer-qualifier-p (qualifiers)
(typep qualifiers '(cons (integer 1) null)))
(define-method-combination randomized nil ((method-list positive-integer-qualifier-p))
(assert method-list)
(let ((clauses (mapcar #'(lambda (method)
(let ((weight (car (method-qualifiers method))))
`(,weight (call-method ,method))))
method-list)))
`(loop (catch 'fail (return (rcase ,@clauses))))))
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment