5 ms·
A few cool thing happened! I might give the CLOS course a try! I’m a functional guy but I feel CLOS isn’t your typical object system.
by nesarkvechnep 2y ago
A few cool thing happened! I might give the CLOS course a try! I’m a functional guy but I feel CLOS isn’t your typical object system.
- dartos 2y agoAs a functional fan, CLOS is amazing.
- f1shy 2y agoWhen I learned CLOS it was the first time OOP started making sense for me.
- asplake 2y agoI've never used CLOS but I loved the metaobject protocol book. So many learnings outside of OOP – it’s a masterclass in API design.
- jjtheblunt 2y agoWhat’s the metaobject protocol book?
- pjmlp 2y agoA computing literature classic. https://en.m.wikipedia.org/wiki/The_Art_of_the_Metaobject_Protocol https://en.m.wikipedia.org/wiki/The_Art_of_the_Metaobject_Pr...
- jjtheblunt 2y agoNo idea how i missed that; thank you.
- f1shy 2y agohttps://github.com/lisp-books/lisp-books/blob/main/Art%20of%20Metaobject%20Protocol.pdf https://github.com/lisp-books/lisp-books/blob/main/Art%20of%...
- codr7 2y agoMy main takeaway was multi-methods, they didn't really click for me before I started seriously digging into CLOS. I wish more languages supported them/played around with similar ideas.
- pjmlp 2y agoIndeed, most successful FP languages have their OOP like approaches. Another thing all modern Lisps have since the 1980's, is all major data structures, not only lists as many think when discussing Lisp.
- fovc 2y agoHaving the data structures is nice and all, but using them is kind of painful. They are certainly second class. Having to use accessor functions or destructuring macros instead of just a period or -> is often annoying too. The lack of syntax has cons as well as pros.
- cenamus 2y agoI mean you can write a macro that let's you write (object -> slot) and transforms it to (slot object) "->" should be unused
- tmtvl 2y agoWriting a reader macro that allows for something like... [some-numbers 0] ...to get the first (many programming languages make this mistake, using 0 to refer to the first element of a collection, so we can forgive CL for this) element. But I'm curious how you can write... (object -> slot) ...without getting an error about OBJECT not being a valid function or macro.
- fovc 2y agoAnd also make sure that slot is a symbol in the correct package. Or do like Elisp and do without packages but then have a 16 character prefix
- Jach 2y agoA late reply but it's worth addressing one way of doing this. First, your concern about object not being a valid function or macro isn't relevant at read time. Second, note that Lisp already has similar syntax: '(1 . 2) is essentially (cons 1 2). Implementing this type of syntax is not a privilege of the implementation alone. You're allowed to redefine your own reader for left paren. In SBCL: CL-USER> (get-macro-character #\() SB-IMPL::READ-LIST You can write `(set-macro-character #\( 'sb-impl::read-list)` and everything continues to work just fine. You can also jump-to-source and modify it if you want -- though it's cleaner to just copy it out to your own project, that's what I did for a quick hack/proof of concept. Essentially I added before the existing (when...) which handles the special dot syntax: (when (and (eq firstchar #\-) (eq (peek-char t stream t nil t) #\>)) (read-char stream t) ; actually read the nextchar > to discard it (let ((next-obj (read stream))) (sb-impl::flush-whitespace stream rt) (return `(slot-value ,@listtail ',next-obj)))) I won't claim this is good or proper, but it shows that it's quite feasible. We've turned (foo -> bar) into (slot-value foo 'bar). CL-USER> (defclass vec2 () ((x :initarg :x) (y :initarg :y))) #<STANDARD-CLASS COMMON-LISP-USER::VEC2> CL-USER> (defparameter vec (make-instance 'vec2 :x 3 :y 4)) VEC CL-USER> (vec -> y) 4 CL-USER> (read-from-string "(print (vec -> x))") (PRINT (SLOT-VALUE VEC 'X)) 18 Personally I wouldn't use this even if it was more properly/carefully implemented. (There's really no reason to replace the default left-paren reader, and no reason we have to have a space surrounding the "->". One thing I like about the infix reader macro package https://github.com/quil-lang/cmu-infix https://github.com/quil-lang/cmu-infix is that it doesn't care about spaces, I can write #I(1+1 + 4) and get 6.) I'm quite happy putting my class in its own package, and thus getting the primary tab-completion behavior I care about. e.g. "(ma:<tab>" could complete to "(math:" and then "(math:v<tab>" could complete to a list of options like "vector-x" "vector-y" or so on. I also like the somewhat unusual approach of naming my accessors with a dot prefix, e.g. (.x vec) and (.y vec), or even (math:.x vec) if I haven't imported the symbol.
- runevault 2y agoAs someone who's dabbled with Scheme, Clojure, and CL long ago and started wanting to get back into CL, I really enjoyed that course as a combination refresher plus deep dive into some topics I didn't really know before (including CLOS).
- nextos 2y agoCLOS is great, but CL also supports pure typed FP with https://coalton-lang.github.io https://coalton-lang.github.io Coalton progress is discussed briefly in the OP: https://lisp-journey.gitlab.io/blog/these-years-in-common-lisp-2023-2024-in-review/#coalton https://lisp-journey.gitlab.io/blog/these-years-in-common-li...