Search
3:51:00
Lord_of_Life_
** NICK Lord_of_Life
6:17:26
beach
Good morning everyone!
10:20:43
tempate
Can I get tips to improve this piece of code? https://gist.github.com/Tempate/2a05c584e1b29c9c609c90856c566128
10:26:30
beach
tempate: Your indentation seems off.
10:27:21
beach
tempate: Your PROGN should be indented 2 spaces, but then, since LET has an implicit PROGN, you don't need it.
10:28:30
beach
You can use with-slots to avoid repeating (slot-value deck 'cards).
10:28:57
beach
But then I advise against using slot-value in favor of using a slot accessor.
10:30:35
tempate
What's wrong with slot-value?
10:31:32
beach
It is very low level. Usually, you design a data structure around classes and generic functions. That's known as a "protocol".
10:31:55
beach
A protocol is a generalization of an interface in other languages.
10:32:36
beach
Just as you don't want to access fields in a structure or class directly, you typically don't want to access Common Lisp slots directly.
10:32:53
beach
That's just basic software engineering.
10:33:02
beach
But for this small a problem, it won't matter.
10:33:18
beach
But you should definitely use WITH-SLOTS.
10:33:22
specbot
Couldn't find anything for with-slots..
10:33:24
specbot
http://www.lispworks.com/reference/HyperSpec/Body/m_w_slts.htm
10:38:07
tempate
Changed to: https://gist.github.com/Tempate/2a05c584e1b29c9c609c90856c566128
10:39:39
beach
If you care about performance, using a vector would be better.
10:40:24
White_Flame
it would have to use a different algorith, though
10:40:27
tempate
At the moment performance is not one of my priorities
10:40:47
tempate
It would make more sense to make hit a method, right?
10:40:48
beach
White_Flame: Right, you wouldn't use DELETE.
10:41:53
White_Flame
you could add a count to the class to cache the length, so you don't have to recompute it, which would be a fairly easy optimizatin
10:41:58
beach
tempate: It would be a generic function, but it might be overkill for this problem.
10:43:38
tempate
what are the differences between C++ classes and Lisp's?
10:43:50
tempate
White_Flame: oh, right. Let me try to do that.