Skip to content

Instantly share code, notes, and snippets.

@zkat
Last active August 29, 2015 21:45
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zkat/49352 to your computer and use it in GitHub Desktop.
Save zkat/49352 to your computer and use it in GitHub Desktop.
;dispatch(selector, args, n)
; for each index below n
; position := 0
; push args[index] on ordering stack
; while ordering stack is not empty
; arg := pop ordering stack
; for each role on arg with selector and index
; rank[role's method][index] := position
; if rank[role's method] is fully specified
; if no most specific method
; or rank[role's method] < rank[most specific method]
; most specific method := role's method
; for each delegation on arg
; push delegation on ordering stack
; position := position + 1
; return most specific method
;;COMPARE AND CONTRAST
(defun generate-applicable-talent-list (selector &rest args)
(let ((n (length args))
(most-specific-method nil)
(ordering-stack nil))
(loop
for index upto n
fof position upto n
do (let ((position 0))
(push (elt args index) ordering-stack)
(loop while ordering-stack
do (let ((arg (pop ordering-stack)))
(loop for role in (sheep-direct-roles arg)
when (and (eql selector (name role))
(eql index (role role)))
do (setf (elt (rank (method role)) index)
position)
if (or (fully-specified-p (rank (method role)))
(< (calculate-rank (rank (method role)))
(calculate-rank (rank most-specific-method))))
do (setf most-specific-method (talent-pointer role)))
(loop for delegation in (sheep-direct-parents arg)
do (push delegation ordering-stack))))))
most-specific-method))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment