libera/#commonlisp - IRC Chatlog
Search
13:26:39
gin
I have been away from this channel for sometime but I haven't stopped learning CL. I think all the effort is finally paying off. I have a small collection of personal tools all written in CL.
17:31:01
alcor
if the data is indeed "just data" then a struct is probably is arguably a better choice than either
17:31:25
_death
it's a pretty general question and I'm inclined to say "it depends".. but then, I think in most cases you should use the most convenient internal representation for your program, and think of the json external data as just something to be translated into this internal representation
17:33:43
alcor
Although I must say, I'm not really a fan of the "anemic data model"-school of design i.e. https://www.martinfowler.com/bliki/AnemicDomainModel.html, especially not in CL. CL has a powerful object model. You can easily have proper domain objects with useful behavior.
17:57:35
beach
A standard class is usually the most convenient choice. The semantics of structs are not so great, and they don't allow multiple inheritance.
17:57:57
beach
mi6x3m: Careful with terminology. Every Common Lisp object is an instance of a class.
18:06:54
mi6x3m
i think i'll just go ahead with a alist / plist thing with semantically processed data
18:17:22
edwlan[m]
e.g. instead of using (cdr (assoc 'foo...)) all over you should typially use a function called FOO that hides that implementation detail
18:22:41
_death
alcor: I don't think this anti-pattern makes a lot of sense when using an object system like CLOS, where behavior belongs in generic functions and not in objects (instances)
18:31:05
alcor
_death: This anti-pattern was popularized by the C++/Java-style sect of OOP. There, it's hard to add behavior to a domain class without accidentially introducting coupling. In the CL/Smalltalk OOP sect, this isn't a problem due to generic functions, advices, and dynamic scoping being available.
18:34:29
mi6x3m
anyone knows of a sane way to get a floating point from a decimal and fraction integers?
18:40:59
gilberth
The sanest probably is taking a detour over ratios. ,(coerce (+ 12 (/ 34 100)) 'single-float)
18:44:17
gilberth
I'd rather do ,(defun foo (m f) (coerce (+ (parse-integer m) (/ (parse-integer f) (expt 10 (length f)))) 'single-float)) ,(foo "10" "34")
18:44:59
alcor
_death: It's in the second camp because it has `become:' allowing one to change an object's identity, in addition full reflection over basically everything in the image
18:47:59
_death
alcor: I don't understand why that makes the anti-pattern inapplicable.. also, I'm not too familiar with smalltalk.. does become: actually affect object identity, or more akin to change-class?
18:48:13
gilberth
The very least you want to do when going with READ-FROM-STRING is (1) bind *REAL-EVAL* to NIL (2) use WITH-STANDARD-IO-SYNTAX, and in your case bind *READ-DEFAULT-FLOAT-FORMAT* as needed. Like (with-standard-io-syntax (let ((*read-eval* nil) (*read-default-float-format* <as you like>)) (read-from-string ...)))