libera/#commonlisp - IRC Chatlog
Search
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.
17:14:09
jcowan
Back to Unicode for a second: https://docs.google.com/document/d/1d4xnVAGod2NxjGypwyS9bYlx5kE2VBJu5p4xl5zXEy8 is my original proposal for doing Unicode in the R7RS-small variant of Scheme, and I think it would make sense for CL as well if mechanically translated to use CL function names.
18:17:48
phantomics
jcowan: took a look at the document, the criteria there look good in terms of categorization, the alphabetical and numeric Unicode categories are a bit more expansive that what SBCL has
18:24:09
phantomics
Mainly I see that they include the "number letter" categories that SBCL doesn't, APL characters definitely shouldn't be included, there's something weird with Allegro's system
18:37:53
contrapunctus
attila_lendvai: is this your site? http://dwim.hu/ You may want to serve JS over HTTPS, and update that Freenode link to libera.chat...
18:39:20
attila_lendvai
contrapunctus, thanks for the headsup. that site is somewhat... well, abandoned. there's plenty of potentially useful features that should be fixed/finished, but we're not working much in CL anymore.
18:41:49
attila_lendvai
:) heh, right, when Xach notifies me of the breakage, then i fix our libs up to the point where they compile and run the dwim.hu code
18:42:19
Xach
attila_lendvai: i appreciate it - but if it becomes too much of a bother, please let me know.
18:42:56
attila_lendvai
Xach, no, not at all! i always have the option to not react, so please keep me posted! and thanks for all the work on ql!
18:53:17
attila_lendvai
Xach, i'll communicate that, don't worry. it already feels it was a waste what went into writing all the hu.dwim libs. i don't want to let them bitrot, maybe there are some users out there.
19:15:37
pve
attila_lendvai: Any highlights in those libs you feel we should know about? (I'm not familiar with them)
19:17:49
attila_lendvai
pve, hu.dwim.perec is a rather nice ORM. it has a query compiler that compiles queries given in sexp form to SQL, and when it cannot do that, then it transparently runs it in the lisp VM. it can even compile parts of the query to SQL, and run a hybrid lisp+SQL query
19:19:09
attila_lendvai
hu.dwim.stefil is i think by far the best unit test lib (simply wraps defun to ensure a dynamic environment, but tests are otherwise defun's. very nice experience in slime.)
19:19:38
attila_lendvai
there are all kinds of little utils, like hu.dwim.defclass-star to make defclass less verbose
19:20:26
attila_lendvai
hu.dwim.computed-class is a functional reactive programming lib that makes class slots reactive (they get automatically recalculated as needed)
19:21:06
jcowan
attila_lendvai: Do you have a writeup (other than the source) of the sexp-to-SQL mapping? It's a hard problem.
19:21:25
attila_lendvai
hu.dwim.reiterate is an 80% iterate replacement, but it's much better. it uses a proper walker, hu.dwim.walker.