<beach>
coat: Common Lisp is wonderful in that, instead of containing a function for every possible special case, it contains all the building blocks to make such functions yourself.
hendursa1 has joined #commonlisp
<aeth>
coat: For built-ins? Shouldn't matter. For user-defined functions? There can be a distinction if it gets redefined. (CLs can prevent things in the COMMON-LISP package from being redefined)
<moon-child>
beach: eh...I know of few languages for which that's not the case
<moon-child>
discounting, say, brainfuck
<beach>
coat: #'digit-char-p is preferable. You then clearly tell the person reading your code that it is the function you are passing, rather than the symbol.
<coat>
beach: thanks
<moon-child>
and I do wish cl had better tools (built-in) for tacit programming. It is cumbersome to write the above lambda, rather than (e.g.) (partial #'every #'digit-char-p)
<beach>
moon-child: Oh? From the videos of C++ "standardization" that I have watched. The process is mainly about introducing more special cases every iteration.
<aeth>
moon-child: beach is right, some languages love special cases, e.g. sum() is very common
hendursaga has quit [Ping timeout: 244 seconds]
<aeth>
at least, when we're talking about how to do simple tasks on sequences, which is the topic
<moon-child>
sure, but in few languages can you not write (reduce #'+)
<pjb>
that said, it may be less efficient, and on long strings, in both cases.
<aeth>
moon-child: but it winds up with what's idiomatic in the language... and in particular, what's optimal (since if a sum() or .sum() is built in, that's probably faster than their equivalent of (reduce #'+ ...) while if it's not built in, then the implementation will try to optimize (reduce #'+ ...) more)
<moon-child>
aeth: the particular case of 'sum' is a bad one, as it's likely to have different semantics: reducing floating-point error. More generally, compilers recognizing specific idiomatic forms (such as (reduce #'+)) doesn't scale outside of apl. More interesting things like loop unrolling and autovectorization any compiler worth its salt will do anyway, given the opportunity
<coat>
aeth: what is a non-simple string?
<aeth>
coat: most commonly, an adjustable string buffer
CrashTestDummy2 has joined #commonlisp
<aeth>
(make-array 8 :element-type 'character :adjustable t :fill-pointer 0)
<aeth>
then (vector-push-extend char that-non-simple-string)
<beach>
coat: The standard is very clear with its definition of SIMPLE for arrays, but it leaves a lot of decisions to the implementation when it comes to non-SIMPLE.
<aeth>
but, yes, there are other ways to get non-simple-strings, e.g. displaced arrays
<beach>
aeth: The standard allows for all strings to be simple.
CrashTestDummy3 has quit [Ping timeout: 258 seconds]
<pjb>
beach: literal strings?
<beach>
coat: See the definition of simple-array.
<pjb>
beach: I don't see how the standard can forbid: (make-array 8 :element-type 'character :adjustable t :fill-pointer 0)
<pjb>
or can let implementations to forbid it.
<beach>
pjb: It can't. What makes you think I implied that?
<coat>
aeth: beach: thanks!
trocado has quit [Ping timeout: 265 seconds]
<beach>
The standard says: "The type of an array that is not displaced to another array, has no fill pointer, and is not expressly adjustable is a subtype of type simple-array."
<beach>
But it doesn't say that the other types of arrays are non-simple.
<pjb>
Oh, ok. But then it doesn't say that simple-array have to be simple, ie. have to not be displaced, have no fill pointer or cannot be expressly adjustable.
<pjb>
If there are only simple-arrays…
IAmRasputin has joined #commonlisp
<beach>
Right, it has no opinion about that direction of the implication arrow.
<coat>
can this code be made simpler? https://plaster.tymoon.eu/view/2514 - I have repeated (char s n) calls. is there a way to put all the indices in the list, iterate over those indicies and collect (char s i) instead?
<beach>
pjb: Though the standard does not define "simple" that way.
<beach>
coat: (loop for i in '(0 1 2 ....) collect (char s i))
<coat>
pjb: thanks! that would be useful if I wanted all characters. but I want to choose which indices I want so the LOOP solution is more useful for my specific problem.
CrashTestDummy2 has quit [Ping timeout: 265 seconds]
wheelsucker has quit [Remote host closed the connection]
wheelsucker has joined #commonlisp
_death has quit [*.net *.split]
adeht has joined #commonlisp
CrashTestDummy2 has joined #commonlisp
lisp123 has joined #commonlisp
CrashTestDummy3 has quit [Ping timeout: 268 seconds]
wilfred has quit [Quit: Connection closed for inactivity]
lisp123 has quit [Ping timeout: 252 seconds]
jemoka has quit [*.net *.split]
hirez has quit [*.net *.split]
spacebat1 has quit [*.net *.split]
sukaeto has quit [*.net *.split]
markasoftware has quit [*.net *.split]
sukaeto has joined #commonlisp
markasoftware_ has joined #commonlisp
jemoka_ has joined #commonlisp
hirez- has joined #commonlisp
spacebat1 has joined #commonlisp
amb007 has quit [Ping timeout: 268 seconds]
amb007 has joined #commonlisp
trocado has joined #commonlisp
lotuseater has joined #commonlisp
Inline has quit [Quit: Leaving]
trocado has quit [Ping timeout: 252 seconds]
Inline has joined #commonlisp
silasfox has joined #commonlisp
Inline has quit [Remote host closed the connection]
Inline has joined #commonlisp
frgo has quit [Remote host closed the connection]
frgo has joined #commonlisp
Inline has quit [Remote host closed the connection]
Inline has joined #commonlisp
trocado has joined #commonlisp
<coat>
is there a function that take can take all elements of list *b* and append it to list *a*. For example, (defparameter *a* (list 10 20 30)) (defparameter *b* (list 40 50)). I need (some-func *a* *b*) such that the result would be *a* = (10 20 30 40 50)?
IAmRasputin has joined #commonlisp
<shka>
coat: yes
<shka>
append :D
waleee has joined #commonlisp
<coat>
shka: append does not seem to modify *a*. It returns a new list for the result.
<shka>
also, note that destructive modification of lists is perhaps not the best idea if said list (or part of it) has any chance of being shared
<shka>
because bugs will be hilarious
IAmRasputin has quit [Ping timeout: 272 seconds]
<kakuhen>
(format nil "good night")
kakuhen has quit [Quit: Leaving...]
amb007 has quit [Ping timeout: 268 seconds]
hendursa1 has quit [Ping timeout: 244 seconds]
tyson2 has joined #commonlisp
amb007 has joined #commonlisp
hendursa1 has joined #commonlisp
kevingal has joined #commonlisp
<coat>
what does 'n' mean in 'nconc'? concatenation of n items?
<edgar-rft>
non-destructive
<edgar-rft>
nonsense, non-consing by using destructive pointer manipulatiopn
<edgar-rft>
append creates a new list, nconc modifies the pointers in the cdr cells
<edgar-rft>
therefore nconc does not allocate new cons cells
amb007 has quit [Ping timeout: 272 seconds]
amb007 has joined #commonlisp
random-nick has joined #commonlisp
<edgar-rft>
same is true for other 'n' functions, e.g. reverse vs. nreverse
kevingal has quit [Remote host closed the connection]
lisp123 has joined #commonlisp
<coat>
edgar-rft: thanks
<beach>
coat: You may have some interesting surprises with NCONC.
<beach>
coat: I recommend using append instead, and assign to the variable.
<coat>
beach: Is performance hit not a concern in append?
lisp123 has quit [Ping timeout: 272 seconds]
<coat>
beach: Is the surprise about (nconc a b) regarding the fact that some other variable may be referring to 'a' and might be expecting it to not change?
<beach>
coat: Both are O(n) in terms of the length of the first list.
<beach>
What do you think *l1* contains after doing (nconc *l1* *l2*)?
<coat>
(list l1 l2)?
<beach>
That would be the numbers eleven and twelve in *l2*.
<coat>
oops, those were eleven and twelve
<coat>
(list 11 12)?
<beach>
So you expect *l1* to have the value (11 12). And you would be wrong.
<beach>
Hence my warning.
<coat>
thanks
<beach>
Sure.
<beach>
So do (setf *l1* (append *l1* *l2*)) instead.
<beach>
And forget about NCONC until you understand what it does.
<beach>
... and until you understand how lists work in Common Lisp.
<beach>
coat: Also, a piece of general advice: Do not worry about performance unless your application needs to be faster than it is. And then, only consider parts of the application that are bottlenecks in terms of performance.
<beach>
coat: Worry about your algorithms and data structures in terms of asymptotic complexity as usual.
derelict has joined #commonlisp
amb007 has quit [Ping timeout: 272 seconds]
<coat>
beach: thanks for the advice
<beach>
Sure.
<coat>
which is better to use in code? equalp or string=
<coat>
assuming comparing strings only
<beach>
coat: There is a very general rule in programming, and that is, use the most specific construct that will get the job done.
CrashTestDummy3 has joined #commonlisp
<coat>
so string=
<beach>
If that gets the job done, then yes.
<coat>
why are there so many equal functions in CLHS? it is quite confusing while programming and need to check the CLHS again and again
<beach>
coat: Have you programmed in other languages before?
<coat>
is there a shortcut to look up function documentation in SLIME? say I want to see what equal does in SLIME itself without opening the browser
<coat>
beach: learnt C and Python. but done some real projects in Python only
<beach>
You can open the Common Lisp HyperSpec page in Emacs.
amb007 has joined #commonlisp
CrashTestDummy2 has quit [Ping timeout: 268 seconds]
<susam>
coat: There are two things I use. C-c C-d d to describe symbol. C-c C-d h to open CLHS in a web browser.
Inline has quit [Remote host closed the connection]
Inline has joined #commonlisp
<coat>
susam: thanks
<beach>
coat: What material did you use to learn to program?
<coat>
beach: k&r for C. python.org tutorial for python
<beach>
I see. So you are self-taught?
<coat>
beach: yes
<coat>
beach: but I understand your point about asymptotic complexity. you mean terms of big oh notation, right?
<beach>
I mean, those are both language specific resources, and they probably wouldn't cover rules like the one I just cited.
<beach>
coat: Yes, and that's yet another domain, also independent of any language.
Inline has quit [Remote host closed the connection]
Inline has joined #commonlisp
<beach>
coat: Part of the reason Common Lisp has so many operators is historical. But then, most people complain that it doesn't have enough.
<coat>
beach: do you recommend any good source to learn programming from?
Inline has quit [Remote host closed the connection]
<beach>
coat: But here is another general rule of programming: The smaller the language, the more code you have to write yourself, and you often need to do it differently for each project, and certainly in a way incompatible with what other people do.
<beach>
... like object-oriented programming in early Scheme for instance.
Inline has joined #commonlisp
<beach>
coat: I would have to think about that and look around. I haven't had to do that for a very long time.
<coat>
beach: how did you do learn to program when you did?
<beach>
coat: I had some very good teachers at the university, and then I studied a lot myself.
taiju has quit [Ping timeout: 265 seconds]
<beach>
Teachers like Erik Sandewall and Anders Haraldson.
<beach>
coat: You can learn a lot from people like Robert C Martin (a.k.a. Uncle Bob). He comes across as a bit weird if you watch his "clean code" videos, but he actually knows what he is talking about.
amb007 has quit [Ping timeout: 268 seconds]
<beach>
He has also written several books, of course, in case you prefer to read.
amb007 has joined #commonlisp
amb007 has quit [Ping timeout: 265 seconds]
cross has quit [Quit: leaving]
waleee has quit [Ping timeout: 250 seconds]
cross has joined #commonlisp
amb007 has joined #commonlisp
cross has quit [Quit: leaving]
cross has joined #commonlisp
cross has quit [Client Quit]
cross has joined #commonlisp
amb007 has quit [Ping timeout: 268 seconds]
amb007 has joined #commonlisp
amb007 has quit [Ping timeout: 268 seconds]
<shka>
coat: simply put, don't mix destructive and non-destructive data structures
<shka>
and lists should be most of the time considered to be non-destructive
taiju has joined #commonlisp
amb007 has joined #commonlisp
char has joined #commonlisp
Equill has joined #commonlisp
amb007 has quit [Ping timeout: 268 seconds]
amb007 has joined #commonlisp
<Josh_2>
'ello 'ello
<Josh_2>
You are correct this fella is an odd ball beach but I am a big fan of the eccentric
silasfox has quit [Ping timeout: 250 seconds]
amb007 has quit [Ping timeout: 272 seconds]
<beach>
Uncle Bob?
<beach>
Yes, I didn't take him seriously at first, but I have changed my mind since.
silasfox has joined #commonlisp
<Josh_2>
Yes Uncle Bob
cage has joined #commonlisp
adeht is now known as _death
Nilby has joined #commonlisp
silasfox has quit [Ping timeout: 250 seconds]
silasfox has joined #commonlisp
IAmRasputin has joined #commonlisp
IAmRasputin has quit [Ping timeout: 272 seconds]
amb007 has joined #commonlisp
selwyn has joined #commonlisp
lisp123 has joined #commonlisp
<shka>
the most tragic history about the uncle bob
<beach>
What?
<shka>
is when he mentioned that nobody will be serious about the programming until software bug will cause a major aviation accident
<shka>
but then Boeing Max happens
<beach>
I think he is totally right.
<beach>
Yes, that wasn't enough apparently.
<shka>
and corporate don't care anyway :P
<beach>
They will have to care if there is new legislation as he predicts.
<shka>
yeah, it sounded ludicrous at first, but i actually think that this may be not be worst idea ever
VFR has quit [Ping timeout: 252 seconds]
lisp123 has quit [Ping timeout: 265 seconds]
<beach>
I agree, but it would be a terrible idea presently. What will happen will depend a lot on the "experts" that are chosen to draft legislation. I won't be surprised if (say) free software is outlawed, and VSCode becomes mandatory, and stuff like that.
<beach>
I mean, imagine they pick "experts" from (say) Oracle.
<shka>
Boeing also decided to move all of the software development to India
<beach>
Wow.
<beach>
Amazing.
<jcowan>
Obviously Boeing has very good (and very expensive) e&o insurance, some of it paid for by taxpayers. I read once that aviation didn't become profitable (as opposed to pervasive) iuntil the 1960s or so
<beach>
I am not worried about Boeing. I am worried about the future of software development.
<shka>
jcowan: Boeing is not allowed to go out of business anyway
<shka>
way to many military assets are connected to Boeing
<jcowan>
Bear, Stearns wasn't either, and yet.
amb007 has quit [Read error: Connection reset by peer]
amb007 has joined #commonlisp
<jcowan>
Software has been in crisis my whole life, almost.
bhaible has quit [Remote host closed the connection]
bhaible has joined #commonlisp
jans has quit [Remote host closed the connection]
silasfox has quit [Ping timeout: 250 seconds]
silasfox has joined #commonlisp
bhaible has quit [Remote host closed the connection]
bhaible has joined #commonlisp
yitzi has quit [Quit: Leaving]
lad has joined #commonlisp
cage has quit [Quit: rcirc on GNU Emacs 27.1]
waleee has joined #commonlisp
tyson2 has joined #commonlisp
tyson2 has quit [Remote host closed the connection]
tyson2 has joined #commonlisp
selwyn has quit [Read error: Connection reset by peer]
tfeb has joined #commonlisp
tfeb has quit [Client Quit]
tyson2 has quit [Remote host closed the connection]
IAmRasputin has joined #commonlisp
lisp123 has quit [Remote host closed the connection]
IAmRasputin has quit [Ping timeout: 268 seconds]
domovod has quit [Quit: WeeChat 3.2]
lisp123 has joined #commonlisp
tyson2 has joined #commonlisp
silasfox has quit [Ping timeout: 268 seconds]
lisp123 has quit [Ping timeout: 265 seconds]
silasfox has joined #commonlisp
unyu has joined #commonlisp
shka has quit [Quit: Konversation terminated!]
shka has joined #commonlisp
sp41 has quit [Remote host closed the connection]
lisp123 has joined #commonlisp
aleamb has quit [Quit: bye]
treflip has quit [Remote host closed the connection]
silasfox has quit [Ping timeout: 250 seconds]
silasfox has joined #commonlisp
tyson2 has quit [Remote host closed the connection]
silasfox has quit [Ping timeout: 252 seconds]
lisp123 has quit [Ping timeout: 268 seconds]
shka has quit [Ping timeout: 265 seconds]
jeosol has quit [Quit: Ping timeout (120 seconds)]
<coat>
I am trying to make a small wrapper that can push a cons to alist. (defun add-key-value (key value alist) (push (cons key value) alist)) (defparameter *a* nil) (add-key-value "foo" "bar" *a*). But *a* remains as NIL after I execute this.
<coat>
How can I make the add-key-value function actually modify the alist?
<pjb>
coat: if you really want to do that, you just use defsetf
<pjb>
not defun
<pjb>
coat: I guess you could also use define-modify-macro and acons.
<pjb>
coat: unfortunately, a lot of CL functions don't have their parameters in the right order for define-modify-macro… So you need to swap them, eg. with that lambda.
<coat>
pjb: Okay. Curious about another thing. Is creating a list and pushing cons to it not a popular way? Do people usually use acons instead?
<pjb>
coat: note: it's bad to mutate state! Instead, use a local variable and acons!
<jcowan>
The whole point of alists is that they are persistent
selwyn has joined #commonlisp
elf_fortrez has quit [Quit: Client closed]
kevingal has joined #commonlisp
dsk has quit [Ping timeout: 244 seconds]
trocado has quit [Ping timeout: 272 seconds]
livoreno has quit [Read error: Connection reset by peer]
livoreno has joined #commonlisp
livoreno has quit [Read error: Connection reset by peer]
livoreno has joined #commonlisp
pve has quit [Quit: leaving]
lisp123 has joined #commonlisp
klltkr_ has joined #commonlisp
lisp123 has quit [Ping timeout: 272 seconds]
varjag has quit [Quit: ERC (IRC client for Emacs 28.0.50)]
frgo has quit [Remote host closed the connection]
frgo has joined #commonlisp
jeosol has joined #commonlisp
klltkr has joined #commonlisp
klltkr_ has quit [Ping timeout: 268 seconds]
Nilby has quit [Ping timeout: 265 seconds]
IAmRasputin has joined #commonlisp
IAmRasputin has quit [Ping timeout: 258 seconds]
andreyorst has quit [Ping timeout: 258 seconds]
andreyorst has joined #commonlisp
tfb has quit [Quit: died]
kevingal has quit [Remote host closed the connection]
[deleted] has joined #commonlisp
livoreno has quit [Ping timeout: 272 seconds]
klltkr has quit [Ping timeout: 272 seconds]
cjb has joined #commonlisp
tfb has joined #commonlisp
tfb has quit [Client Quit]
<jasom>
doesn't cl:push leave the original list unchanged?
<jasom>
I thought it only changed the slot that the list was stored in
<jasom>
i.e. isn't this true? (let ((y x)) (push 'foo x) (eq (cdr x) y))
lotuseater has quit [Quit: ERC (IRC client for Emacs 27.2)]
[deleted] has quit [Read error: Connection reset by peer]
<aeth>
the way lists go, a push is a cons, so how can it not do that? there is no list, only cons pairs
<moon-child>
jasom: yes, otherwise it would be O(n) in the length of the referenced list
livoreno has joined #commonlisp
<aeth>
pushes could only directly modify if the list data structure was actually one more pointer, a pointer to the first cons pair (or if it added to the end and was O(n))
<moon-child>
it could also add to the beginning destructively, moving down the elements of each successive cons cell. Still O(n) though