Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ensure vector is adjustable & has a fill-pointer on remove-listener #11

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

Zulu-Inuoe
Copy link

Fixes #4.
See spec documentation on delete (http://clhs.lisp.se/Body/f_rm_rm.htm)

I believe this is a better fix than #8 because it doesn't rely on the user issuing a restart, and instead just ensures we always have an adjustable array to work with, instead

@anranyicheng
Copy link
Contributor

anranyicheng commented Mar 6, 2022

Hi, after this fixes fea2603, the result is also not correct. I fix code there:
(defun remove-listener (object event listener &key(start 0))
(let* ((silo (silo object))
(listeners (gethash event silo)))
(unless listeners
(return-from remove-listener))
(setf (gethash event silo)
(delete listener listeners
:test #'eq
:count 1
:start start
:key #'listener-function)))
(values))

(defun emit (event object &rest args)
(let* ((listeners (listeners object event))
(max-size (length listeners)))
(when (zerop max-size)
(return-from emit nil))
(dotimes (indx (length listeners))
(apply (listener-function (elt listeners indx)) args))
(do ((indx 0 (1+ indx)))
((>= indx max-size))
(when (listener-once (elt listeners indx))
(remove-listener object event (listener-function(elt listeners indx))
:start indx)
(decf max-size)
(decf indx)))
t))
then ,the result is right.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Do not run vector-push-extend on the result of delete
2 participants