4 ms·
I agree that Lisp is not always terse, which surprised me at first too. You can abstract many constructs and eradicate redundancy, but at some point, your only
by junke 11y ago
I agree that Lisp is not always terse, which surprised me at first too. You can abstract many constructs and eradicate redundancy, but at some point, your only chance of being terser is to use reader macros. However, doing so might not be a good idea either.
There are libraries out there that provide syntactic sugar for Common Lisp, which is often discarded because (i) they define their own "ghetto" dialect of Lisp (ii) it is in fact not very important to waste a character or two. Aesthetics alone is not a goal.
For multiple values, you might still use a list instead, in which case you are back to the usual way of accessing data:
(let ((list (multiple-value-list (get-decoded-time))))
(format t "Year: ~A~%Seconds: ~A" (sixth list) (first list)))
If you only want to access a particular value, use "nth-value" (not possible in your example, of course).
- adwf 11y agoYeah, that's how I do it sometimes with other peoples code. But with my own code I much prefer using structs. Makes it much clearer to read and there is little implicit structure like with an ordered list. So my preferred way would look more like: (let ((struct (my-get-decoded-time))) (format t "Year: ~A~%Seconds: ~A" (time-year struct) (time-seconds struct))) With the original multiple value return, if there were a bug and I were reviewing the code, I'd need to also review get-decoded-time and see what order the values are in. If instead it returned structured data, I could skip that step as the values are clear. Lisp is still my favourite language. I generally rank languages by how much time/code I'm spending managing the language versus managing the problem I want to solve. Lisp is very good for that, very little cruft so it lets you focus directly on the problem at hand.
- junke 11y agoAgreed, structs and classes make often more sense to aggregate data, especially when they are all equally important.