Search
Monday, 16th of May 2022, 3:23:20 UTC
10:56:31
Lord_of_Life_
** NICK Lord_of_Life
11:17:28
mfiano
What is a good way to transform a string repeatedly given a list of cons of translation characters. For example given the list ((#\, . #\-) (#\; . #\:)) and the string "foo,bar;baz", it should produce "foo-bar:baz"
11:19:05
semz
mfiano: Is reduce + substitute too expensive due to intermediates?
11:20:58
semz
Although this may run into issues if one character is replaced with another character that is to be replaced later
11:21:41
lisp123
i'd probably separate the list to (, ;) and (- :) if the string is large enough
11:23:29
mfiano
So it seems I have to do single-pass
11:24:25
mfiano
with #'(setf char) or whatnot
11:33:14
lisp123
this week going to have about 5000 people using my CL app (for a few minutes each at a conf)
11:35:30
mfiano
Something like this maybe is sufficient: https://gist.github.com/mfiano/5616e646ad101334ff4c4938872caaa7
11:37:50
rotateq
Or if you would use REPLACE?
11:38:09
mfiano
I don't see how REPLACE would work here.
11:38:15
jackdaniel
substitute if anything, and that would require n passes
11:38:50
mfiano
jackdaniel: n passes would be problematic as mentioned above
11:39:14
mfiano
I do not want subsequent passes to mutate previous passes. I want to do it all in one pass to avoid that
11:39:16
jackdaniel
that's why I'm not suggesting it, I've mentioned it to correct rotateq
11:39:42
rotateq
jackdaniel: very good of you, thx :)
11:40:02
jackdaniel
sure, I've mixed these two functions too
11:40:32
jackdaniel
what is a testimony that replace is perhaps not the best name for that particular function
11:40:44
mfiano
There's also substr and sublis for trees
11:40:50
mfiano
I mix those two up all the time
11:41:39
lisp123
loop macro has a = clause/phrase?
11:41:42
rotateq
I always see what I didn't use yet so often. Or today, that NTH-VALUE is actually a macro.
11:42:11
lisp123
:for (old . new) := (assoc char transforms)
11:42:13
jackdaniel
there are two camps loop-wise - people who use keywords and people who don't
11:44:37
mfiano
Maybe I should be looping over STRING instead of NEW-STRING. I have to read to iteration restrictions in the CLHS again
11:44:48
mfiano
I think it is legal to mutate the current iteration though
11:46:01
lisp123
how does lisp calculate array length btw?
11:46:23
mfiano
Well that's implementation dependent
11:48:20
mfiano
and not all arrays have a length, anyway
11:48:36
rotateq
lisp123: I think you mean vector length or array dimensions. ;)
11:48:57
mfiano
Only a vector is a sequence
11:50:04
jackdaniel
(map 'string (lambda (ch) (or (cdr (assoc ch *vroom*)) ch)) *string*)
11:52:25
mfiano
Much more concise and more readable. I think I'll go with that.
11:53:34
jackdaniel
there is always map-into
11:53:43
jackdaniel
if you are not interested in retaining the old string
11:59:21
lisp123
how to reload a file in sbcl repl
11:59:41
jackdaniel
(load <file>) would be one way
12:00:10
lisp123
So CLISP has a better repl than SBCL?
12:00:29
jackdaniel
try linedit for similar capabilities
12:01:00
jackdaniel
clisp payed a dear price for rlwrap integration - it had to change its own license
12:01:52
lisp123
oh it was rlwrap that caused CLISP to be GPL?
12:02:18
jackdaniel
yes, I think that an email conversation is linked from clisp website
12:02:27
jackdaniel
they've reached a mutal understanding after some back and fro
12:02:58
lisp123
yeah I read that but not the details
12:03:01
jackdaniel
(Bruno Haible and Richard Stallman - afair)
12:03:14
lisp123
i was reading recently on how ECL's roots are quite good
12:03:26
lisp123
first CL implementation built ground up from the specificaiton
12:03:47
jackdaniel
technically it was KCL ,)
12:04:23
jackdaniel
and KCL has more descendants than ECL
12:05:44
Mrtn[m]
jackdaniel: Cool. I like the GPL.
12:06:21
mfiano
and CLASP is derived from ECL afaik :)
12:07:20
jackdaniel
only core runtime, not the compiler
12:07:42
jackdaniel
(and parts of the core runtime written in C were rewritten in C++)
12:17:40
Mrtn[m]
<lisp123> "one day I will learn C" <- What will you do in the afternoon of that day?
12:19:23
Mrtn[m]
Hey Bike, good afternoon.
12:20:54
lisp123
Mrtn[m]: Learn RUST #FAST #SAFE
12:43:24
trev
i had just watched a talk by the creator of clasp
12:43:56
trev
amazing how much work he has done, plus the chemistry stuff
12:45:03
jackdaniel
drmeister: your are being praised ^
12:45:58
rotateq
trev: It's really one of the most impressive talks I know, due to the idea of translating the metaprogramming for chemistry.
12:56:09
mfiano
jackdaniel: How would you modify your example such that if the cdr is nil, it means trim the original character without replacing (shorter string)?
13:07:12
jackdaniel
I wouldn't, (map 'string) doesn't work like this.
13:07:38
jackdaniel
I'd probably have a string with a fill pointer along with the index closed over (map nil …)
13:07:47
jackdaniel
or use loop/other iterative construct
13:08:08
jackdaniel
or, instead of an index variable - push-extend
13:10:37
jackdaniel
(let ((string (make-it size :fill-pointer 0))) (map nil (lambda (c) (when-let ((val (assoc-value …))) (vector-push-extend val string))) *the-other-string*)
13:10:56
jackdaniel
but that's not much different than using loop
14:31:45
trev
lagash: https://www.youtube.com/watch?v=mbdXeRBbgDM
14:46:26
trev
i should also say that it made me feel like a total loser after watching, and now i am contemplating my entire purpose in life!
14:51:41
trev
beach, cause it was awesome stuff and when you are just working a mildly interesting day job just for money, it is easy to envy academia
14:54:18
jackdaniel
you should start putting easter eggs in the day job, then it will be for money *and* for easter eggs :)
14:56:15
trev
i should embed a lisp compiler into the product
14:56:24
trev
i think that is what you are getting at jackdaniel
14:56:39
jackdaniel
press tilde for instance repl
15:04:15
dlowe
see how well that worked for web browsers
15:05:14
Bike
do i understand correctly that conspack can't do multidimensional arrays?
15:14:03
Bike
relatedly, what de/serialization libraries are good. i tried marshal first, and that works okay, but i'd have to devise my own efficient output format and the code is a bit ugly in parts
15:14:26
Bike
conspack seems pretty good, but i do actually want to handle complicated arrays
Monday, 16th of May 2022, 15:23:20 UTC