-
Notifications
You must be signed in to change notification settings - Fork 27
Some CLOS Notes
You have joined the channel lisp123 has joined (~lisp123@5.30.23.247) Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books") phoe set the topic at: 21 May 2021 at 6:00 pm Mode: +nt Created at: 19 May 2021 at 8:00 pm Oladon has left IRC (Quit: Leaving.) lisp123 I am finding as I use CLOS more, I am gravitating towards creating more and more (sub)classes. Is that normal? lisp123 It basically has the effect of delaying certain decisions to lower levels of the algorithm. For example, I may previously have used an MVB to return two values, which can then be utilised by the calling function beach Hard to say in general. It depends a lot on the exact problem. lisp123 But now I am gravitating towards housing those values within a class, which I will subclass to allow the result to be passed into a generic function & hence specialised lisp123 So instead of, for example, a COND statement in the calling function, I would turn that calling function into a generic function, and the class object returned by the inner function will force a particular method to be dispatched beach That sounds "normal". lisp123 beach: Thanks, yes there does not seem to be a clear appropriate way (i.e. thus it depends on the problem). I am spending more and more of time on thinking about how to structure the code vs. actually writing it lisp123 By "normal", do you mean returning a class object vs. multiple return values? beach Oh, THAT is normal. :) I.e., thinking about how to structure the code. beach Every good programmer does that, but unfortunately, most programmers are not very good. beach lisp123: Yes, that's usually a better idea, but again, it depends. Multiple values are cheaper than allocating a standard object. beach ... so in a tight loop where performance is critical, the decision may be different. lisp123 :) Working through CLIM was a revelation, I got to thank you for keep reminding people that it is an excellent example of a large code base. It was very hard at first, but once I figured out how it was working, I realised how much easier it was to read (given that CLIM implements a complex GUI system which would be very difficult to read in any other style) lisp123 beach: Great, thanks. I will start with the expensive approach and can fine tune later if ever needed (premature optimisation and all that) beach Yes, reading the CLIM specification is how I understood CLOS. edgar-rft has left IRC (Quit: Leaving) empwilli has left IRC (Ping timeout: 240 seconds) treflip has joined (~user@user/treflip) empwilli has joined (~empwilli@faui48e.informatik.uni-erlangen.de) pjb lisp123: basically, in an OO application, when you have to add a feature or a kind of object to be processed, you should not have to hack right and left, but instead just write one or two sub-classes with a few very specific methods. If you can do that, then it means your OO app is correctly structured, with the right abstract classes and general methods. lisp123 pjb: Thanks, that's a good principle to keep in mind. Right now I'm doing a lot of code revisions so I don't think I'm there yet :( lisp123 But hopefully I get there soon! aeth has left IRC (Ping timeout: 256 seconds) aeth has joined (~aeth@user/aeth) Disconnected You have joined the channel lisp123 has joined (~lisp123@5.30.23.247) Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books") phoe set the topic at: 21 May 2021 at 6:00 pm Mode: +nt Created at: 19 May 2021 at 8:00 pm rotateq hm i had this with qwnavery recently, he produced first (mapcar 1+ (1 2 3)) then i told him we're not scheme and then (mapcar '1+ '(1 2 3)). i suggested (mapcar #'1+ '(1 2 3)), so when to better use what? lottaquestions has joined (~nick@2607:fa49:5041:a200:71e0:c4bf:d866:f951) rotateq so when i think about also when one has a lexical symbol, then its symbol-function is also bindable rotateq again, the deep details of specification :) rotateq where I'm not sure I mean lisp123 The Clim docs state: A protocol class is an “abstract” class with no slots and no methods (except perhaps for some default methods), and exists only to indicate that some subclass obeys the protocol. lisp123 But also: Whenever a class inherits from a protocol class or returns true from the protocol predicate, the class must implement methods for all of the generic functions that make up the protocol. lisp123 Actually ignore me :) I got confused between generic function and method rotateq no lisp123 rotateq but can't help you out lisp123 rotateq: Hey rotateq, how's it going rotateq oh the quotated things rotate, you know rotateq I'm still teaching qwnavery in parallel (over xmpp and sometimes jitsi) lisp123 Nice rotateq yes it's fun rotateq but often i have him to remember, the basics, also because they don't seem to have learned much in highschool, which is now over rotateq he's a good padawan :) rotateq are you still located from work in dubai? lisp123 Oh he is young, the future generation of lispers lisp123 Yes, but I'm moving home to Sydney in a couple of months for good rotateq yes 18 now, but I'm not much older lisp123 Future world domination from both of you ;) rotateq some good people not much older than me are way longer in business, so I shouldn't give up on me rotateq lisp123: yes but i don't think to build replicators (like in Stargate) which then eat up galaxies beach rotateq: 'name and #'name may designate different functions, but for standard functions like 1+, they designate the same one. rotateq or Skynet :) rotateq hello beach rotateq yes okay i see beach There is also a performance difference sometimes. In case of 'name, there may be a call to FDEFINITION at run time. random-nick has left IRC (Ping timeout: 256 seconds) rotateq and that is "worse"? beach Only if you care about a small performance penalty. Usually it doesn't matter. rotateq Ah no, not in the first place, more about intention. beach It is almost always better in that respect to use #'name. rotateq :) lisp123 rotateq: What have you covered with qwanvery so far? rotateq as I also like more to write (funcall #'(lambda (x) ...) ...) instead of what would work just ((lambda (x) ...) ...). but okay LAMBDA is a macro that produces the function object anyway rotateq lisp123: few this and that, now a few months and with weeks of pauses lisp123 ^ I used to do that too, but now I do (lambda ) without the #' rotateq first to learn important symbols to build up from, like PUSH, POP, CONS rotateq ah okay lisp123 Nice rotateq yes and some mathematical things rotateq he now started also project euler lisp123 Good stuff rotateq yes but also stuff that he can understand for now, not too much (just sometimes to shock) rotateq it wasn't so good, he solved problems 1 and 2, then instantly wanted to solve the most recent, and called it "trivial". lisp123 I made that mistake before rotateq I meant I want to save him from making a fool of himself. This has happened to me often enough, but I can live with it. rotateq yes lisp123 and even now just 58 solved it, that's a sign how hard it can be lisp123 Yep rotateq he even doesn't know yet what coprime means and that is in the first line ^^ rotateq but don't get me wrong, i learned also much from him rotateq beach: We had that, CHAR-DIGIT-P returns the value when it's a digit and NIL if not. I didn't know that. beach Why are you telling me this? beach Speaking of which, I have been told quite frequently lately in #commonlisp and #sicl that I am saying wrong things in my utterances, so I think I'll restrict my remarks and answers to #clschool for the time being. rotateq öhm rotateq we just wondered that it is this way and then thought "when we now could ask beach or someone of the other ..." beach I think I understand. lisp123 beach: That would be a shame, you are usually nearly always right but it must be tiring to always have to encourage to be more precise beach That's not the problem. It seems to have become a sport by experienced lispers do disagree with me. Just for the hell of it, it appears. And I don't appreciate that. beach s/do/to/ lisp123 Sorry to hear that beach Yeah, me too. But it's fine. I'll take appropriate action. makomo has joined (~makomo@user/makomo) x88x88x has left IRC (Ping timeout: 240 seconds) x88x88x has joined (~x88x88x@149.28.53.172) beach lisp123: We can do better than the Lisp machine, on stock hardware even. But it will take some time. And I am sure I have said this before. lisp123 beach: Yes :) lisp123 I was thinking more from the perspective of an alternate reality where Lisp took over during the 90s vs. other languages. I was reading a post yesterday by Kent Pitman (timely to rotateq's comment about time machines) on some of the mindset at the time, relevant quote being: lisp123 "...Many people spent a big chunk of their lives investing in this dream and it didn't pan out quite as we wish...We owe it to the losers in these little skirmishes to make sure that, if nothing else, the good ideas are not lost along with the framework. And we do not accomplish that by defining that there was nothing lost. That's both callous to those who worked hard on these other things and short-sighted to the future, which might one day c lisp123 are about the things that got lost." lisp123 It's a bit tangential to all of the discussions, but I always wondered why so many people who pioneered Lisp in the 80s/90s sort of disappeared from it afterwards lisp123 But that quote stuck out to me as a possible reason White_Flame it's all about funding White_Flame when there was funding, people did great things. when funding dried up, they worked elsewhere beach Yeah, people had to make a living. lisp123 I guess White_Flame these sorts of projects take multiple great people with time dedicated to it White_Flame now, if it weren't tied to the hardware, I think things might have been a lot different lisp123 I was hoping they would do something as a hobby at least White_Flame and even the alpha vlm etc stuff still is emulating the lisp hardware platform White_Flame (at least from teh symbolics end of things, which is my biggest retrospective familiarity) lisp123 It wasn't Common Lisp right (it was a predecessor?) White_Flame right, though I believe most or even all the lisp machines did get CL support lisp123 Ah I see White_Flame the hardware was pre-CL rotateq lisp123: it took over since long ago, but just in the back like a puppet player who plays the strings :D the others can believe their myths still and think they're ahead White_Flame what took over? rotateq don't take me too seriously :) White_Flame I'd have to be able to parse it before I could take it seriously or not ;) rotateq ideas are powerful and the things they influence depend on those rotateq and the ideas that are powerful are those who can stand the test of time White_Flame so many ideas were lost from the general mainframe world as well White_Flame and we only have clunky, half-baked versions of them remaining in things like virtual machines rotateq yes and also with the internet ideas and knowledge still gets lost, but the pseudo-knowledge and things no one really needs, grow White_Flame and heck, look at engelbart's ideas etc. people use pale imitations to get the buzzword clout and market from there rotateq do you have a link to read up what it is? White_Flame you can start here: https://www.youtube.com/watch?v=yJDv-zdhzMY
White_Flame
there's plenty of others distingushing what he was talking about compared to what we end up getting
rotateq
hmm
treflip has left IRC (Quit: I'll be back soon)
edgar-rft has joined (~edgar-rft@HSI-KBW-109-193-249-223.hsi7.kabel-badenwuerttemberg.de)
tyson2 has left IRC (Remote host closed the connection)
treflip has joined (~user@user/treflip)
x88x88x has left IRC (Ping timeout: 240 seconds)
x88x88x has joined (~x88x88x@2001:19f0:5:39a8:5400:3ff:feb6:73cb)
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
x88x88x has left IRC (Ping timeout: 260 seconds)
aeth_ has joined (~aeth@user/aeth)
aeth has left IRC (Killed (NickServ (GHOST command used by aeth_)))
aeth_ is now known as aeth
Oladon has joined (~olad@98.43.81.226)
x88x88x has joined (~x88x88x@149.28.53.172)
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
treflip has left IRC (Quit: good night!)
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
x88x88x has joined (~x88x88x@2001:19f0:5:39a8:5400:3ff:feb6:73cb)
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
x88x88x has left IRC (Ping timeout: 240 seconds)
x88x88x has joined (~x88x88x@149.28.53.172)
aeth has left IRC (Ping timeout: 256 seconds)
aeth has joined (~aeth@user/aeth)
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
treflip has joined (~user@user/treflip)
Oladon has left IRC (Quit: Leaving.)
sjl has left IRC (Quit: WeeChat 2.2-dev)
treflip has left IRC (Quit: bye!)
CodeBitCookie[m]
"You would do that because it may..." <- Ah, makes sense.
waleee has left IRC (Ping timeout: 260 seconds)
lisp123
So I have a bit of a naming conuldrum. Consider LIST -> (list 1 2 3 4) returns a list, so in a similar vein, generally I like to use class-names for functions that create instances of those classes
waleee has joined (~waleee@2001:9b0:21d:fc00:398f:b003:b90d:acf4)
lisp123
E.g. for class RESULT, (result ...) -> (make-instance 'result ...)
lisp123
But when it comes to single slot classes, again say result, I have a conuldrum: (defclass result () ((result :initarg :result :accessor result))), would mean the generic function for result is now associated with the accessor of that slot
lisp123
So there's two solutions - change the class creator function to something like 'make-result' which is consistent with how structures are made but not consistent with LIST or other built-in objects
lisp123
Or change the slot name to something else. E.g. (defclass result () ((value :initarg :value :reader get-value)))
lisp123
It's hard to have the name of a slot in a single-slot class to be anything different than the class name IMO, so I am tempted to go down this generic "VALUE" name
lisp123
The issue doesn't arise for multi-slot classes, because they will naturally have their own names
shka has joined (~herr@109.231.0.226)
lisp123
I figured it out, I'll name the slot based on the type of objects they contain
lisp123
So if result is meant to contain a list
lisp123
Then it will be (defclass result () ((lists :initarg :lists :accessor lists)))
beach
If it contains a single list, you should not use the plural form for the slot.
beach
I have occasionally used the naming convention you are aiming for.
beach
I think in Cleavir, we use CONTEXT as the constructor for compilation contexts.
beach
But most of the time, we use the MAKE- prefix.
beach
I wonder whether the LIST function was meant to be named after a verb, "to list" something, rather than the noun.
beach
I am asking because many functions have verbs in their names.
lisp123
Yes, I was typing list then realised my example wouldn't work (but agree with you of course).
beach
Why would your example not work?
lisp123
The accessor function as 'list' would cause a conflict I think
beach
Not if you shadow it.
lisp123
I always thought CL went down the noun route due to Lisp 2
lisp123
So I always read (list 1 2 3 4) as "A list of 1 2 3 4" vs. "To List 1 2 3 4" (or easier to read (make-list 1 2 3 4))
beach
Possibly. I haven't counted verbs vs nouns.
lisp123
Yes, both get used. Sometimes I try to name a function with a noun if it is relatively simple (e.g. list) or doesn't have any side effects
lisp123
And for "bigger" objects or where there is side-effects, I may resort to a verb version - "make-something" sounds like more "work" than just "something"
lisp123
So I would read (make-something 1 2 3 4) vs. (something 1 2 3 4) as the "something" object being bigger / more complex. But that's just some personal tendencies of mine, nothing that I have read from elsewhere
beach
Either way, shadowing is a better option than violating the singular/plural rule.
lisp123
Agree
Disconnected
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
You have joined the channel
lisp123 has joined (~lisp123@5.30.23.247)
Topic: Common Lisp questions answered here! (Lisp-Koans #u"https://github.com/google/lisp-koans") (CL-on-Exercism #u"https://exercism.io/tracks/common-lisp") (Online-Tutorial #u"http://cliki.net/Online+Tutorial") (Books #u"http://cliki.net/Lisp+Books")
phoe set the topic at: 21 May 2021 at 6:00 pm
Mode: +nt
Created at: 19 May 2021 at 8:00 pm
lisp123
Is it a hard rule/suggestion for protocol classes to have no slots? Or is it okay to give them a slot that every 'concrete' class that inherits from it will define anyway?
lisp123
I'm just trying to get my head around that
lisp123
The only thing I can think of is that you don't want users to use the protocol class directly, hence no slots
lisp123
Looks like in CLIM they use the concept of "standard-[class-name]" which implements the protocol, that makes sense
beach
lisp123: It is fine to give them slots.
beach
But yeah, it is perhaps more common to put the slots in the STANDARD- class.
tyson2 has joined (~user@bras-base-toroon0624w-grc-19-70-31-33-162.dsl.bell.ca)
aeth has left IRC (Ping timeout: 240 seconds)
pjb
lisp123: you don't really need to define a class to define a protocol. in CLOS, a protocol is just a bunch of generic functions.
pjb
lisp123: but you can define a mixin, or an abstract class, with a bunch of generic functions, and some methods.
pjb
in the later case, you can have slots.
aeth has joined (~aeth@user/aeth)
nexeq has left IRC (Read error: Connection reset by peer)
nexeq has joined (~nexeq@static.99.72.130.94.clients.your-server.de)
nexeq has left IRC (Ping timeout: 245 seconds)
nexeq has joined (~nexeq@94.25.176.105)
random-nick has joined (~random-ni@87.116.167.125)
lisp123
beach & pjb: Thanks!
lisp123
That makes sense