Skip to content

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

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

Conversation

BNAndras
Copy link
Member

No description provided.

Copy link
Member

@verdammelt verdammelt left a 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)
Copy link
Member

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)
Copy link
Member

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
Copy link
Member

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)
Copy link
Member

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))
Copy link
Member

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?

@verdammelt
Copy link
Member

Just a general comment - the use of several return-from expressions feels a little odd to me - I called out one in loop but the one in the middle of the function also could be replace by using when rather than unless 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.

2 participants