libera/#commonlisp - IRC Chatlog
Search
13:16:12
JeromeLon
I want to find, remove, and return the first element of a vector that matches a predicate. DELETE is *so* close, but it doesn't return it. I could FIND and DELETE, but that's duplicating the work. The only solution I found is POSITION, followed by (DELETE-IF (lambda (x) t) seq :start position :end (1+ position)). This last bit gives me nausea. Can anyone suggest something less ugly?
13:17:02
JeromeLon
(I do know that delete does not garantee that my original vector contains the result)
13:23:44
JeromeLon
Bike: thanks! And thanks for suggesting replace, I'll use it instead of the DELETE, to change the original vector, it brings several improvements
13:46:41
Krystof
(defun find-remove-and-return (vector predicate) (let (result) (delete-if vector (lambda (x) (when (funcall predicate x) (setq result x) t)) :count 1))) ;?
14:05:52
Colleen
Function array-utils:vector-pop-position https://shinmera.github.io/array-utils#FUNCTION%20ARRAY-UTILS%3AVECTOR-POP-POSITION
15:08:23
JeromeLon
Shinmera: Thanks! I feels like a basic need, indeed. I see why you need this lib in several projects
15:10:16
Shinmera
not covered by the docs, but it also has a * variant that is O(1), but changes order of elements.
15:44:03
dieggsy
A while ago I think someone suggested a way to create a graph of class structure/inheritance - does anyone have any ideas? Allegro's composer has a utility for this, but it seems to crash on Emacs for macos (without X11). We have some custom method that user graphviz, but I'm wondering if there's a more straightforward or portable way
15:46:28
beach
As I recall, it's a command that starts with comma, like ,show-class-subclasses and ,show-class-superclasses
16:51:20
beach
That would depend a lot on the implementation of both Common Lisp and that other language.
16:52:14
lucerne
beach: Perl and Python both have one canonical implementation AFAI, and I am open to using any (free) CL, though I prefer SBCL.
17:26:54
Bike
please post descriptions of links you post if their content is not obvious from the url
17:27:06
lucerne
Xach: I currently just want a language (any language) that I can code once in, and use it anywhere. CL is one of the nicest langs I know, so I wanted this main lang to be CL. I guess I’d go with zig now.
17:28:03
Xach
lucerne: the easiest way to do that is to become important enough at a company or other organization that you can dictate technical details.
17:30:25
lucerne
But I do not want to duplicate some basic functionality between CL and Perl and others. I can’t afford that, being just one person 😄
17:30:55
Xach
I've been pretty happy simply ditching perl and using CL for everything, but it is a personal choice.
17:31:16
mfiano
Raku (formerly Perl 6) might be worth looking into, as it has a lot in common with CL, but this is off-topic here.
17:41:22
copec
It feels like there is an exponential explosion of new languages in the last 10 years
17:52:52
pjb
lucerne: you can use libecl.so and dynamically link it into any program, to use Common Lisp.
17:57:37
pjb
lucerne: but if you're afraid of the work, you can still avoid duplication by having two programs, one in perl and one in common lisp, and communicating thru a pipe or sockets.
18:10:55
jcowan
on IRC, it's morning when you join / start talking, and night when you leave / stop talking.
18:46:13
pjb
lisp123: well, I said that :around et al. are better reserved to client code, but actually this has a problem: if the client code adds a :around method on one of your class, this will also be called for other subclasses of yours, in other client libraries.
18:46:36
pjb
lisp123: so even client code may want to refrain adding methods on classes or subclasses that are not its own.
18:47:12
lisp123
pjb: I see. I earlier thought you had meant to use it to avoid changing any interfaces for the client
18:48:01
pjb
What those method do, is to wrap behavior in the right position even for subclasses provided by the client.
18:48:36
pjb
Always keep this picture https://pablofernandez.tech/wp-content/uploads/2011/08/common-lisp-method-composition.png
18:49:04
pjb
or this equivalent one: https://upload.wikimedia.org/wikipedia/commons/4/43/Method-combination.png
18:51:05
lisp123
Fortunately I only code for myself, so I will just stick to standard primary methods :)
19:03:10
pjb
lisp123: notice the cm and mc example (m is a "mixin", and depending on the order it's in the superclasses list, the order of the methods called.
19:04:21
pjb
lisp123: notice also with the cm example, the importance of (when (next-method-p) (call-next-method)) even in the inner primary method (in the superclass).
19:42:07
xaltsc
Hey, is there a "Common Lisp for the Schemer" somewhere ? All the guides/tutorials I've found are either too basic or too advanced...
19:43:56
lisp123
I would think Practical Common Lisp would be perfect for a Schemer because they already understand the basics of Lisp, but not sure if you think its too advanced. If so, ANSI Common Lisp, which is a bit easier to read, might be sutiable
19:45:54
xaltsc
I guess what I want is how to translate scheme idoms to clisp ones, like (define fun (lambda [arg] (...))) is just (defun fun [arg] (...))
19:47:25
lisp123
You can try this cheat sheet if you want something to the point: https://github.com/ashok-khanna/lisp-notes
19:47:43
Alfr
xaltsc, you can't, e.g. tail call optimization isn't mandated and some implementations might exhaust the stack; also no call/cc.
19:48:52
lisp123
xaltsc: Unfortunately (I can get your perspective now), I can't think of anything that would be perfect for you. You might need to just bite the bullet and read through PCL
19:48:54
xaltsc
Alfr: my entry in the clisp world would only be nyxt configuration right now, so I don't have to worry about this kind of stuff
20:22:19
jcowan
I found PCL very readable, but I'm an odd case because I wrote CL (in anger) about the same time I learned Scheme (from reading the Rabbit compiler, which is written in Scheme and Maclisp). I never returned to CL after that except to update myself, but got involved in Scheme much more so.
20:28:11
jcowan
beach: Of course you can define away "unlispy CL features" by saying "Everything in CL is lispy". But if you look at how people actually use the term, they seem to focus on `format` as the most unlispy feature, followed by `loop` and CLOS in that order.
20:28:57
jcowan
I agree about `format`, think `loop` could have been designed better but the idea was a good one.
20:29:51
lisp123
White_Flame: Seems like there is two eras of Lisp - The ones before format / loop / CLOS and the ones after it
20:30:24
White_Flame
well, the old ones really sucked because they used symbol plists as an application database, and did spaghetti mutation everywhere
20:30:30
lisp123
The one before was DIY, you got the primitives, go have fun. The ones after is like, why reinvent the wheel, use these useful tools. That's my two cents
20:32:04
jcowan
There should be a bottom-up MOP+CLOS book that explains how a CLOS is done, analogous to phoe's condition book.
20:33:01
Bike
amop is kind of written like that... though it skips some of the efficiency details and isn't quite in line with the MOP "standard"
20:36:04
lisp123
jcowan: You can also check out Sonja Keene's book and then the standards. Then look at Portable Common Loops
20:38:17
lisp123
https://www.cs.cmu.edu/afs/cs/project/ai-repository/ai/lang/lisp/oop/clos/pcl/0.html