libera/#commonlisp - IRC Chatlog
Search
5:09:18
etimmons
I think an ELS paper would be great. I certainly wish I knew about it before I did.
6:19:12
phantomics
For question 1 you just need to loop over the vector of depths subtracting the previous from each depth starting at index 1, then count the positive differences
6:38:53
phantomics
This loop gives you the differences in depth, with *depths* being the vector of measurements: (loop :for x :across *depths* :for ix :from 0 :when (and (< 0 ix) t) :collect (- x (aref *depths* (1- ix))))
7:08:41
dre
phantomics, thanks. is there any other way to do it? I spent a long time trying to get some recursive function to do it
7:17:02
beach
dre: Your use of LINE as a Boolean variable is a violation of the rules stated on page 13 of the LUV slides by Norvig and Pitman.
7:25:32
beach
It is not about semantics. It's about the message you send to the person reading your code.
7:28:30
beach
dre: Clearly the use of > or < has the same semantics as the use of PLUSP and MINUSP, but again, it is about the person reading your code.
7:29:02
beach
The "rule" here is that you should use the most specific construct that will do the trick, so as to make the understanding of your code faster.
7:31:11
dre
well when I think plus I think of the action, compared to 'positive' which would be an adjective
7:32:11
beach
Anyway, that would be a problem only for the first few days of learning a language. It would not be worthwhile designing a language with those few days in mind.
7:35:15
dre
https://www.reddit.com/r/adventofcode/comments/r66vow/2021_day_1_solutions/hmrl3xc/?utm_source=reddit&utm_medium=web2x&context=3
7:35:50
dre
countif / mapcar was what I was originally trying before getting stuck in that loop business.
7:37:33
phantomics
dre: for a recursive function, you just need to go over the list keep track of three values: the last value, the current value, and the number of matches. If the last value is less than the current value, increment the match count. If there is no current value (you're at the end of the list), return the match count.
7:38:57
stylewarning
In case you're interested in the Coalton solution for AoC 1: https://github.com/stylewarning/aoc/blob/main/2021/1/1.lisp
7:40:07
stylewarning
With currying you can write slick code like (countBy (== LT) foo) to count the number of items in foo that are equal to the symbolic constant LT
7:44:47
_death
stylewarning: why not have a coalton-load that evaluates forms in coalton-toplevel context? (can also have a coalton-compile-file)
7:45:32
stylewarning
_death: I've been thinking about that, and also making an ASDF component type. But then it wouldn't work well with SLIME without slime hacking :[
8:02:04
kennyd
I wonder if it would it be possible to get similar currying working in plain CL, with a custom progn-like macro
8:08:18
stylewarning
And using lots of combinators in plain Common Lisp is so clumsy anyway, there wouldn't be much payoff. The most you might be able to do is define new reader syntax like [mapcar f], but you'd need to be able to query the arity of the function being called
8:09:32
stylewarning
And even then, it would be restricted to named, known functions only. Coalton gets away with it because all functions have their types statically known at compile time, so we can resolve "the meaning" of a curried expression with full generality, regardless of how many combinators are being composed and used
9:20:12
kakuhen
I just learned that, like all textbooks, the Art of the MOP is not free of errors; obvious in hindsight, but interesting to see anyway
10:13:18
beach
kakuhen: I think it depends on the implementation whether a method on validate-superclass is needed.
10:52:32
cuz
Hey all, quick question. I have a list of a list of numbers and I want to create a new list that is the sum of each of those e.g. ((1 2 3) (4 5 6)) turns into (6 15). Is there a simple function for this?
10:54:42
hayley
(flet ((sum (xs) (reduce #'+ xs))) (mapcar #'sum '((1 2 3) (4 5 6)))) is the best I can think of.
11:00:05
cuz
yeah i've got some ugly mapcar apply combo... I guess it's not too bad but i'm suprised there isn't something standard
11:08:20
Krystof
how often do you think generating a list of list sums happens, that there should be a standard function for this?
11:09:01
Krystof
supplementary question: if there were a standard function for this, what would its name be?
11:21:10
semz
but for string concatenation, it's mildly annoying that there is no variant that takes a sequence
11:27:34
cuz
This is a pretty common pattern for me, where I have a function and then I want to apply it to multiple inputs. EG lets say I want to send an email to multiple people but can only send it to one at a time, then I would make a list of each persons email and then apply the email function to each email in that list
11:31:40
kennyd
it doesn't buy you much over reduce. but summing a flat list is probably a lot more common than summing a 2d one. and once you have a flat sum, summing a 2d list is short enough that we don't really need a new function, (mapcar #'sum ...), or (sum (mapcar #'sum ...)), depending on the desired result
11:38:32
scymtym_
etimmons: i'm not aware of anyone hooking Eclector into CL:LOAD. what's the use case?
11:38:33
minion
scymtym_, memo from etimmons: Do you know of any success stories using Eclector as the reader for CL:LOAD (without completely replacing the implementation's reader)? I tried using Fare's reader-interception, but it has issues. Trying to decide if I should fix them or hop to something else that already works.
11:44:28
akater[m]
Krystof: Such operations are certainly very useful in multilinear algebra. But they should probably be in a multilinear algebra system. Wolfram named this one ArrayReduce: https://reference.wolfram.com/language/ref/ArrayReduce.html
12:16:48
akater[m]
kennyd: You're right: if you only have #'+ and not #'sum, it's not the same thing. Wolfram's apply takes a similar spec (“levelspec”) and so a hypothetical (wolfram:apply #'+ matrix '(1)) would effectively reduce the rows of matrix with #'+. It's a common enough operation to have infix for it. I used it quite often; Wolfram is very strongly oriented towards operating on “multidimensional” lists. levelspecs and dimension specs
12:16:49
akater[m]
are offered consistently in the language, where Lisp would offer &rest, essentially. &rest approach is ultimately more limited and less useful when dealing with arrays with higher ranks.
12:21:34
akater[m]
&rest is more handy in very simple cases and conses less, unless the multidimensional-oriented approach implements fusion.
12:22:35
hayley
ACTION thinks petalisp:lazy-reduce or petalisp:lazy-reduce* takes a dimension (RIP petalisp:β)
13:47:36
etimmons
scymtym_: More details after I left the memo. But short story is I've got some package hacks I'd like LOAD and COMPILE-FILE to use.
13:53:47
scymtym_
etimmons: i see. i only have worked towards side stepping the implementation completely (for something like static analysis) which is pretty difficult in general since loading or compiling a file is not just a READ loop. instead READ must be interleaved with certain side effects. "just" replacing the implementation's READ could be easier. an implementation specific solution could be advising CL:READ such that it calls Eclector's READ
13:56:55
etimmons
It was working for a while. But then I had the gall to include a comment at the end of the file and it blew up.
15:07:26
Guest74
midnight is too late to do AoC. I kept reading part two wrong and kept reading the figure horizontally instead of vertically.
15:26:54
pve
etimmons: Hi, I don't know if it helps you at all, but here are my eclector experiments: https://github.com/pve1/eclector-access
15:27:46
pve
etimmons: you can check examples/package-nicknames-test.lisp (or some other file) to see how it works.
15:32:34
attila_lendvai
Xach, oh, i didn't know that's also part of ql... :/ not sure how to handle this, but the dialog started with the author (https://github.com/hu-dwim/hu.dwim.defclass-star/issues/12 and https://github.com/hu-dwim/hu.dwim.defclass-star/pull/7)
15:59:48
etimmons
pve: Thanks! Looks like you pull tricks similar to reader-interception. And even avoid the bug reader-interception fell in to!
16:03:40
etimmons
pve: You wight want to also consider a WITH-ECLECTOR macro, so that any LOADs within its body automatically get the Eclector reader. So that a file can use it without needing to call ENABLE
16:14:00
pve
etimmons: I wonder what would break if I enabled a client globally at startup (e.g. in .sbclrc) that translates all occurrences of cl:load to "my-load"..
16:16:32
jcowan
Probably a good thing to do after writing a long and difficult (to write, not to read!) programming book.
16:17:43
etimmons
pve: Hmmm. Only one way to find out! But You might have trouble making it happen. I think SBCL LOADs .sbclrc, so *READTABLE* is bound. You'd probably have to actually mutate the standard read table, which sounds scary
16:19:38
jcowan
Unicode already defines what "alphanumeric" means, though it does not include APL symbols.
16:19:45
jackdaniel
unicode is a terrible mess, second only to previous situation with gazzilions of incompatible encodings
16:21:02
pve
etimmons: oh, I was under the impression that sbcl does read-eval or something on .sbclrc, and not load
16:21:09
jcowan
Some of the complexity is accidental or historical-only, but most of it is essential complexity: writing systems are complex, end of.