libera/commonlisp - IRC Chatlog
Search
6:36:08
mfiano
The problem might be the original question made a literal list as its example to be mutated.
6:36:13
moon-child
this will behave slilghtly differently to beach's suggestion, if pizza happens to already be contained within the property list
6:41:22
beach
asarch: Also, I would start using more interesting food examples, like :SUSHI, :MAGRET-DE-CANARD,
8:32:00
beach
DEFCONSTANT means the compiler can substitute the value for the name when references are compiled.
8:32:01
phoe
with constants, the compiler doesn't need to do variable access, it is allowed to splice literal constant values wherever the constant is used
8:32:33
phoe
and that means no global value lookup and no dynamic binding lookup, which speeds things down, and that the compiler can always figure out the type of the value ahead of time
8:58:19
lisp123
I was thinking of this idea, let me know if there are any flaws in it: I USE a package, say CLIM, and then I don't use any package qualifiers.
8:58:56
lisp123
Later on, I run a function that reads a file, and adds package qualifiers for all symbols not in the current-package or in CL
9:00:40
phoe
adds package qualifiers? as in, it reads a Lisp file and prints back out package-qualified symbols wherever applicable?
9:01:34
beach
lisp123: Certain re-evaluations of the DEFPACKAGE form with different options exposes undefined behavior.
9:02:05
beach
lisp123: And why would you intentionally make life harder for the person reading your code by omitting package prefixes the first time around?
9:02:15
lisp123
It would be outside of the Lisp Image / System. As in destructively modify the file to add in package prefixes
9:03:06
lisp123
Not having to write package qualifiers while I'm developing. And once I'm "done" M-x insert-package-qualifiers
9:03:57
beach
lisp123: So you mean, you magically add package prefixes to all your imported symbols later on?
9:04:29
phoe
mostly because wouldn't trust myself that I'd tell it to get all package qualifiers right
9:05:36
phoe
this, plus I generally dislike the :USE option because is dangerous even if you get all package qualifiers right
9:06:51
lisp123
beach: Yes. So I would manually remove the :USE option before reloading the files (including packages.lisp), although I'm sure there would be a way of finding the defpackage form then destructively modifying the file
9:07:49
lisp123
This is basically like a clean up exercise, not meant to be part of the image. Just to save having to type package prefixes during development
9:08:22
beach
lisp123: So if you accidentally use an imported symbol as a lexical variable, this symbol is going to have a package prefix later?
9:09:08
lisp123
So if you accidentally use an imported symbol as a lexical variable, this symbol is going to have a package prefix later? -> Thanks
10:00:41
chrnybo
I'm golfing on parsing four letters in a-z into a single number; is there a "shift left and add" operation in CL?
10:03:46
moon-child
beach: shift and add can be conceived of as a unitary 'append digits' operation. Most things can be decomposed; that does not mean it is not worthwhile to think of them as atomic in some context
10:05:13
beach
moon-child: Do you have a Common Lisp operation that will do both? I can't think of any.
10:07:41
moon-child
that was not how I interpreted it. chrnybo asked 'is there a "shift left and add" operation in CL?' Your response I interpreted as 'that is not an operation, but two', not 'CL has no such operation'
10:13:35
beach
chrnybo: There is not a single Common Lisp operator that will do both those operations. So in Common Lisp you need to use two operators to achieve the effect you want.
10:43:19
beach
chrnybo: You did not include digits in your possible characters, so it was not clear that your letters meant the same as they do in Common Lisp.
12:22:12
semz
I don't think optimizing this for runtime is worth it unless your list is huge (in that case a hash table would be a good idea)
12:27:25
lisp123
semz: Because its a low-level function I need (a varaint on ALPHANUMERICP), optimisation is important
12:29:58
lisp123
I'll use a Hash Table for now, unless someone has a better idea. I assume the char-codes were ordered in a way that allowed SBCL and other implementations to use an array
12:30:07
pjb
lisp123: in general the fastest would be to index a vector giving the answer: (aref answer (char-code ch))
12:31:01
pjb
lisp123: since character sets are usually small (less than 256), a bit-vector would be quite small (only 32 bytes, less than a hash-table memory overhead!)
12:31:38
pjb
lisp123: but if you consider unicode, then the bit-vector will have to be bigger: 139264 bytes.
12:31:41
lisp123
pjb: Thanks. Looking again at the SBCL code, now I suspect they may be doing the same thing you suggest
12:31:48
semz
That too depends on the exact set though. Honestly I suspect that optimizing this is a waste of time, but I don't know what lisp123 is using it for.
12:33:02
lisp123
semz: I have to search for next word in an editor command I am writing, without using the underlying version of Emacs / whatever
12:34:38
lisp123
Or go to the next paragraph (which has much more characters to search through). And I don't want to keep a history of start/end points since they can change if the buffer changes
13:10:21
lisp123
Do all implementations return the same value for CHAR-CODE for a given character or does it depend on some file or system level encodings?
13:12:40
lisp123
So would I be safe to define it in code, like (defconstant +space-char-code+ (char-code #\Space)) and then use that constant elsewhere to check if a particular character is a space?
13:13:20
lisp123
Or is there some weird way the char code may change in between retrieving it, storing it in a constant and then using it in code
13:14:11
beach
I think you can safely define it as a constant. I can't see how it could possibly change over time.
13:14:28
phoe
AFAIK an implementation should always return a constant char-code for a given character
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}>