libera/#commonlisp - IRC Chatlog
Search
13:18:13
lisp123
Okay, so here's a bit of a trivia question: Are both of these forms equivalent in speed: (eql char #\Space) and (eq (char-code char) +space-char-code+)
13:20:52
beach
lisp123: They *could* generate the same code, but the compiler would have to be good.
13:32:15
phoe
what is the best way of checking whether a symbol has ever been the name of a DEFTYPE or DEFCLASS or DEFINE-CONDITION or DEFSTRUCT?
14:00:42
mzan
neominimum: you said " In the iterative form, walking a non-linear data structure, requires the use of an explicit stack. Compared to the recursive form utilising the implicit call stack."
14:01:44
skeemer
people i was reading practical common lisp, and i was so excited about the higher order function trick that is being used here https://gigamonkeys.com/book/practical-a-simple-database.html
14:02:27
mzan
as beach already said, in practice a lot of nested data structures are trees or similar. In these cases you have often a not extremely deep hierarchy, so probably in these case you can write some recursive code, and use the iterative form only for the final leaf.
14:02:41
skeemer
i was wondering, are there other of these cool tricks with Higher order functions that can be used in more day-to-day applications?
14:05:11
skeemer
phoe, i understand the coolness, but probably i cannot come up with other examples where i could use such things...
14:05:35
skeemer
or how can i practice this? are there any programming exercises online for me to train this ability to code like that?
14:06:22
mzan
neominimum: for example I wrote a rather classical code-formatting function. It accepts as parameter the indentation level, and for each nested scope, it calls itself increasing its parameter. It i recursive. But how many nested scope are there usually? Less than thousands. Then for the instructions inside the current scope, I use a normal iterative loop.
14:07:07
mzan
So in many cases you can combine recursion with explicit iterative loops. You use recursion for the hierarchy part, and recursion for the leaf/final-data.
14:08:24
mzan
skeemer: because CL does not support in the standard tail-call optimization, so recursion of potentially many data can overflow the stack
14:10:37
Xach
skeemer: i have been very happy with a query system based on simple functions that return object matchers, and then a few logical glue functions that compose simpler functions into arbitrary expressions.
14:11:10
Xach
i'm working with a system that produces thousands of sets of change records for certain objects, and i want to select only certain objects of interest interactively at the REPL
14:12:16
Xach
so i can write something like (=and (=matches-text "Foo") (=score> 100) (=not (=color "purple")))) -- here the "=" prefix indicates a function that returns a function.
14:13:09
skeemer
Xach, ok so instead of writing a single where function, you have that dispatched to different functions right?
14:24:54
_73
In a function docstring is the backquoute/single-quote convention meant to be used to denote any symbol that is not local the function? For example: (defun foo (arg) "This function calls `baz'" ...)
14:41:53
_73
I started using it cause emacs highlights it for me so I figured it was a thing in CL. But then I couldn't find anyone elses code out there using it.
14:42:48
_death
the elisp reader is case preserving, so `bar' is often used, while CL's reader is upcasing by default so we just say BAR.. some elisp code uses the latter and some CL code uses the former as well
14:44:46
chrnybo
_73: care to point to relevant emacs documentation on the backquoute/single-quote convention? I don't see it mentioned in (elisp) Function Documentation, but I notice that it works in practice, i.e. a phrase such as `ssh' get highlighted and is a clickable link to the documentation of the function ssh.
14:45:18
lisp123
But then, you have systems like LW, who like to use natural language commands (strings), which is not a bad idea too for end user functions. Not sure if CLIM / Lisp Machines followed the same convention
14:50:26
lisp123
The best advice Emacs Documentation Guidelines gave was to prempt likely follow-on questions and include them in the docstring. E.g. one could add to the docstring for NTH "To access elements of a Sequence, use ELT."
16:33:20
nij-
Anyone uses parenscript? While it supports some lisp constructs (e.g. let, defun, loop), it misses some too (e.g. mapc, mapcar). Is there a way to extend parenscript to support those without hacking the code base?
16:46:16
phoe
(parenscript:ps (defun mapcar (function list) (loop for element in list collect (funcall function element))) (mapcar (lambda (x) (+ x 10)) '(1 2 3)))
16:52:36
josrr
ACTION nij-: there is the runtime library https://parenscript.common-lisp.dev/reference.html#section-runtime-library
17:10:09
nij-
Well.. the lib only contains 7 functions. I suppose I need to write some of the ones i like.
17:25:51
foxfromabyss
hi! is it possible to get something like `:a :b` as a result of a macro expansion, is opposed to `(:a :b)` ?
17:32:57
beach
Unfortunately I can't stick around. I need to go fix dinner for my (admittedly small) family. Sorry.
17:33:14
foxfromabyss
`(splice-into-outer (x y z)` `=>` `:x x :y y :z z`, where the keys have the same name as the variables, and it supports multiple variables
17:34:21
phoe
in particular, something like (list 1 (foo) 3) then this is always a list of length 3 - (FOO) can only expand to a single Lisp value
17:36:22
phoe
doesn't jsown have some sort of semiautomated facility to turn json objects into CL instances?
17:37:15
Josh_2
foxfromabyss: you do not need to remove the list from (:x x ..) you can simply use (apply #'make-instance <your plist>)
17:38:11
Josh_2
(apply #'make-instance '%api-call-failure '(:object 1 :processor 1 :hash 1 :c 1)) => <%API-CALL-FAILURE {1008694863}>
18:37:17
foxfromabyss
`(apply #'make-instance 'testobj (:x 5))` this fails with `:x` being an undefined function
18:37:18
foxfromabyss
i can quote it it this example, but if i do smth like `(apply #'make-instance 'testobj (get-values-for-x))`, i can't quote the values for `apply` :(
18:40:42
Xach
Someone keeps emailing me questions about Vecto and fonts, but their email box is full and my replies keep getting held up :(
18:40:42
skeemer
what common lisp library do you suggest to plot stuff... i need something similar to matplotlib, or ggplot
19:17:16
edgar-rft
skeemer: I usually write gnuplot data into a file and then use gnuplot from the commandline, but here are some other alternatives -> https://www.cliki.net/plotting
19:32:05
phoe
literate programming time - https://github.com/phoe/articles/blob/main/2022-01-29-static-let/static-let.md
19:37:25
White_Flame
isn't literate programming usually about being documentation with code interspersed?
19:40:08
phoe
White_Flame: I think it is - I kind of abuse this idea to also include stuff that teaches writing Lisp in general
19:51:23
moon-child
phoe: 'we did not supply the second argument to LOAD-TIME-VALUE, which creates constant data' I think this would be clearer as 'we did not supply a second argument to LOAD-TIME-VALUE, which lets us create constant data'
19:52:23
moon-child
I'm also not sure if the use of the uninterned symbol clarifies or obscures intent. Depends on your audience, probably, but
22:39:01
phoe
flip214: https://github.com/armedbear/abcl/issues/433 looks like Alexandria might need to adjust its TYPE= tests for cases where one SUBTYPEP returns T T and the inverse SUBTYPEP returns NIL NIL
0:06:09
etimmons
Shinmera: trivial gray streams has file-position, and I'm pretty sure it works on most implementations