libera/#commonlisp - IRC Chatlog
Search
14:35:48
Josh_2
with format can I conditionally print elements from a list? basically can I reduce this:
14:36:05
Josh_2
(format nil "~{~A~^,~}" (loop :for ele :in '(1 3 4 5 6) :when (oddp ele) :collect ele)) into a single format call?
14:56:09
Josh_2
I'm trying to represent a tree of products, their subproducts and varying lengths of time and prices for each product
14:57:52
Josh_2
with product A having two sub products A.b and A.c with A.b and A.c having the same number of months but varying prices on each
15:09:11
shka
which will group all time version of the particular product in order, so you can binary search (or something) given the date
15:11:18
shka
next, you gonna want something to map the name of the product to the product, given the time domain
15:12:42
shka
alternative solution is to have another hash-table mapping product-name to subproducts
15:16:07
Josh_2
I think I may not have been clear enough, when I say months I mean say you can get the product for X months, and the X is adjustable with different prices say 1, 2, 3, 6, forever, etc with each seller being able to change the number of months and their prices
15:56:57
Josh_2
shka: got this so far, I think it will work https://plaster.tymoon.eu/view/2513#2513 each user will have their own product tree which they can modify as they wish, taking away and adding
15:57:45
Josh_2
Thank you for helping me, feels like you sprayed a bit of WD40 on my brain, lubricating it a bit
16:03:28
beach
You should avoid structs unless performance measures indicate that they would have a certain advantage to standard classes.
16:10:24
beach
Also, we keep inventing new techniques, like call-site optimization, that make it possible to inline slot accessors of standard objects in many cases. It would be silly to dumb down your programming style for reasons that may go away in the future.
16:13:19
beach
Same thing with generic functions. It would be silly to avoid generic functions in favor of ordinary functions if we can make generic dispatch as fast as ordinary function calls in many cases.
16:15:56
shka
keyword arguments are way to useful to not use even despite theoretical performance hit
16:17:42
shka
i've been programming in golang lately, lack of optional/named arguments lead to some intriguing oddities in the language
16:19:25
beach
Oh, just wait for the new version of the language. I presume it is like every other language in that the specification changes every year or so.
17:10:53
pjb
Josh_2: (format nil "~{~:[odd~;even~] ~A~^, ~}" (mapcan (lambda (n) (list (evenp n) n)) '(1 2 3 4 5))) #| --> "odd 1, even 2, odd 3, even 4, odd 5" |#
17:10:53
pjb
Josh_2: (format nil "~:{~:[~;even ~A; ~]~}" (mapcar (lambda (n) (list (evenp n) n)) '(1 2 3 4 5))) #| --> "even 2; even 4; " |#
17:10:53
pjb
Josh_2: (format nil "~{~[even ~:*~A~;odd~;even ~:*~A~;odd~;even ~:*~A~;odd~;even ~:*~A~;odd~]~^; ~}" '(1 2 3 4 5)) #| --> "odd; even 2; odd; even 4; odd" |#
17:11:45
pjb
Josh_2: but if you want to filter the list while printing, you will have to write a format function and use it with (format nil "~{~/fmt-only-even/~^, ~}" '(1 2 3 4 5))