Skip to content

Conversation

Trashtalk217
Copy link
Contributor

It works, but that is mostly all that can be said about it. I am nowhere near happy with it, but I want people to review it and give some tips. That's also the reason I haven't editted the .md files for Jarvis March. I'll be working on it way more, but for now you can enjoy the spaghetti.

@Gathros Gathros added Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.) Hacktoberfest The label for all Hacktoberfest related things! labels Oct 4, 2018
@Trashtalk217 Trashtalk217 changed the title WIP Lisp jarvis march Lisp jarvis march Oct 6, 2018
@Trashtalk217
Copy link
Contributor Author

Trashtalk217 commented Oct 6, 2018

List of things I'm still not happy with:

  • The way I currently calculate angle is nice and compleet, but I'd like to cut (some) corners.

  • The return-from in line 106 works, but I should just write the loop properly (loop until and then return) instead of jumping out of it like this.

  • Could maybe make the pointstruct more convenient (read-only, shorter way to read values, etc). Both leftmost-point and next-point-on-hull are doing something really similar, so that could be abstracted, I'm also getting tired of tail-recursion, but this might have to do. => abstracted the two into extreme-of

  • The p-eql is poorly named and maybe I could somehow integrate it into the point struct, or another comparison function can be used (there are 4 in common lisp!) => Replaced with equalp

The reason why I removed the WIP label, is because I want additional input, besides my own. I expect that there'll be more people looking to review, when it doesn't have this label.

Copy link
Member

@c252 c252 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just some small things I noticed

@Trashtalk217
Copy link
Contributor Author

I've tried, but I don't know how to shorten the functions involved in calculating the angle. My linear algebra is a bit rusty and the way others do it looks (and maybe is) quite different. If anyone can elaborate that would be very much appreciated.

@Trashtalk217
Copy link
Contributor Author

I've fixed all the things I was unhappy with. All I need now is a review!

Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It looks good, I can understand everything fairly well. I am not a fan of loops and I'm sure there are things that could be refined but it would probably be matter of taste at that point.

Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let me know if I missed something.

(if (< (point-x p1) (point-x p2)) p1 p2))
gift))

(defun second-point-on-hull (start gift)
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 I realized you don't need second-point-on-hull. Alls it does is call next-point-on-hull you might as well do that in your loop.
You can start your hull with the (- (point-y start) 1) and start points. And then remove the fake point later.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Are you sure this is a good idea, because the the first element of the hull, as defined in the hull list, will then become the starting point, so the check after that until (equalp (first hull) start) will pass and the loop will end, I cannot find an elegant way around that, do you have an idea?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I could place an extra check like if length hull is greater then 2, that might work.

@Trashtalk217
Copy link
Contributor Author

Honestly don't know if this is an improvement, but it's a couple lines less once more.

@jiegillet jiegillet self-assigned this Oct 15, 2018
@jiegillet
Copy link
Member

jiegillet commented Oct 15, 2018

I think it's an improvement, removing one function help reading the code.
One last thing, I stumbled onto this could you use it to get rid of [and] (> (length hull) 2))?

I apologize if my ideal piece of code is the shortest that can be. Feel free to fight back especially since I don't actually know lisp.

@Trashtalk217
Copy link
Contributor Author

I wouldn't have expected anything else from a haskell programmer, @jiegillet. But, jokes aside, I mostly agree with you. There's something very satisfying about getting your code under 100 lines and if you're not cramping everything together it more often then not makes it more readable.

I, however, do not understand what you mean in you're request. Could you please be a little more clear?

@jiegillet
Copy link
Member

Something like:

 (loop with start = (leftmost-point gift) with hull = (list start (make-point (point-x start) (- (point-y start) 1))) do (setq hull (cons (next-point-on-hull (first hull) (second hull) gift) hull)) while (/= (first hull) start) 

(although I'm pretty sure my syntax is wrong at more than one place)

@Trashtalk217
Copy link
Contributor Author

I actually can't believe it worked, but it did.

Copy link
Member

@jiegillet jiegillet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I must be a Lisp genius! Imagine if I actually learned it ;)
One last copy/paste incident to fix and we're good to go

[import, lang:"c_cpp"](code/c++/jarvis_march.cpp)
{% sample lang="lisp" %}
[import, lang:"lisp"](code/lisp/jarvis-march.lisp)
{% sample lang="lisp" %}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You imported it twice!

@Trashtalk217
Copy link
Contributor Author

Trashtalk217 commented Oct 17, 2018

It's finally done I think, thanks for reviewing @jiegillet and @c252

@jiegillet jiegillet merged commit fa1a094 into algorithm-archivists:master Oct 17, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Hacktoberfest The label for all Hacktoberfest related things! Implementation This provides an implementation for an algorithm. (Code and maybe md files are edited.)

4 participants