-
-
Notifications
You must be signed in to change notification settings - Fork 84
add relative-distance
#887
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
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think some cleanup would be good. I have left comments about them.
|
||
(in-package :relative-distance) | ||
|
||
(defun degree-of-separation (family-tree person-a person-b) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think factoring this out into a few functions might be good. for example the tree parsing could be its own function
(dolist (child children) | ||
(unless (gethash child neighbors) | ||
(setf (gethash child neighbors) (make-hash-table :test 'equal))) | ||
(setf (gethash child (gethash parent neighbors)) t) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
setf
can take pairs of symbols and values so instead of (setf a b) (setf c d)
you can do (setf a b c d)
. I personally think it looks nicer instead of two expressions.
|
||
(setf (gethash person-a visited) t) | ||
|
||
(loop while queue do |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Starting to review the function I was thinking: "oh dolist
not loop
nice..." but now that I see loop
I wonder why you didn't use loop
above as well. You could do something like: (loop for (parent . child) in tree ...)
I don't care do
vs. loop
but think it would good to be consistent.
(let ((current-neighbors (gethash current-person neighbors))) | ||
(when current-neighbors | ||
(maphash (lambda (neighbor _) | ||
(unless (gethash neighbor visited) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't you get a STYLE-WARNING
here about the unused symbol _
? Use (declare (ignore _))
Maybe give it a reasonable name even though it is ignored...
(current-degree (cdr current))) | ||
|
||
(when (equal current-person person-b) | ||
(return-from degree-of-separation current-degree)) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How about you factor this loop
so it evaluates to current-degree
and then this whole function can evaluate to what this loop
evaluates to?
Just a general comment - the use of several |
No description provided.