5 ms·
I am currently learning common lisp. The only thing I've really found lacking is support for basic string operations. I'm sure there is a solid library out ther
by such_a_casual 11y ago
I am currently learning common lisp. The only thing I've really found lacking is support for basic string operations. I'm sure there is a solid library out there for things like replace(), but it seems silly for everyone to possibly be using separate libraries, or in-house implementations for standard string operations. It creates an unnecessary barrier to code readability. From what I've heard around the grape vine, this is a result of the ANSI standard being released prior to the popularization of these functions in other languages. If the CL specification is ever updated, I am sure that this problem will be solved. I am surprised this github project didn't acknowledge this.
P.S. Changing the name of 'Remove-if-not' makes absolutely no sense to me. Remove-if and Remove-if-not make perfect sense together. Adding a whole new word to memorize "Keep" just makes code less readable. Especially since Keep isn't seen anywhere else in the language. Further-more the redundancy in the names 'remove-if' and 'remove-if-not' make you think about how these functions are actually the same, with only a small caveat. 'remove-if' and 'keep-if' make you think of these functions as different things, as different ideas, very unlispy.
edit: just checked cl-ppcre's documentation and learned that split and replace are covered by that lib. Seeing as cl-ppcre seems to be used so widely, I take back what I said. Lisp is perfect once again.
- martinflack 11y agoIt's all there with libraries, if you hunker down. I came from Perl so yes it's harder. Library-wise, CL-PPCRE and SPLIT-SEQUENCE are your friends, along with a bunch of the sequence operations in the ANSI spec, and finally, you should get comfortable doing some string stuff in LOOP going char by char or word by word.
- such_a_casual 11y agoThank you.
- ralt 11y agoI like UIOP:SPLIT-STRING instead of SPLIT-SEQUENCE.
- klibertp 11y ago> The only thing I've really found lacking is support for basic string operations. I'm sure there is a solid library out there for things like replace(), but it seems silly for everyone to possibly be using separate libraries It's not that bad, there are other languages which have this problem - you can see exactly the same situation in JS-land, for example. It would be much worse if not for quicklisp. I think quicklisp and asdf are among the best package distribution tools: I feel it's better than pip and gem and similar to npm. Installing a library is literally a single line in your code. There's the problem with finding the package you need and it's harder than with JS and npm, but doable. BTW: what do you do to learn CL? I'm using StumpWM as my window manager and I think it's one of the best ways of learning CL. With SLIME, then, you get almost Lisp-only environment, especially if you use Emacs for your other editing too. I wrote a couple of blog posts[1] about StumpWM and posted my config on GitHub[2]. [1] https://klibert.pl/posts/stumpwm.html https://klibert.pl/posts/stumpwm.html https://klibert.pl/output/stumpwm-better-modeline.html https://klibert.pl/output/stumpwm-better-modeline.html [2] https://github.com/piotrklibert/stumpwm-config/ https://github.com/piotrklibert/stumpwm-config/
- such_a_casual 11y ago> what do you do to learn CL? The best thing I've done is watch a video on making a reddit clone in Lisp. I couldn't get the libraries to work, but I plan on using other libraries to do the same thing either tomorrow or the next day. It's made me realize that I really need to start walking through other people's code. https://vimeo.com/138249727 https://vimeo.com/138249727 Google's LISP koans which is ~30 exercises where you complete the code and make the tests pass. Covers everything from mapcar to multi-threading. https://github.com/google/lisp-koans https://github.com/google/lisp-koans I'm currently on Ch. 9/32 of Peter Seigel's "Practical Common Lisp". I find the book to be a much better resource after already being familiar with the topics covered. It does a great job of going into the nuances and gotchas of the language, but because is so much more text than code, it's hard for me to appreciate all of those little details if I'm still trying to grasp the fundamentals of the topic. http://www.gigamonkeys.com/book/ http://www.gigamonkeys.com/book/ I write all the code I see with a pencil and paper (including all of those koans). I read a block of code and then try to rewrite it from memory. Currently using vim. Haven't gotten around yet to using a live environment. Future resources: Paul Graham's "Roots of Lisp" Paul Graham's "On Lisp" Build a Lisp compiler SICP Paradigms of Artificial Intelligence Programming Upgrade my editor Yeah, there's a lot I want to go through. It's gonna take me a few months just to go through all of the resources I have bookmarked so far. And I haven't even started looking for code that I want to read. End goal is to master Lisp.
- ScottBurson 11y agoThe problem with the name 'remove-if-not' is that it's both more fundamental and much more common in actual use than 'remove-if', yet its name is both longer to type and conceptually more complex. Selecting a subcollection of elements that satisfy a predicate is a natural primitive. My favorite name for it is 'filter'; that's what I've called it in FSet [0]. I haven't defined 'filter-not'; usually the predicate is an explicit lambda expression, in which case adding the negation is straightforward, and even when a lambda is not needed, it's easy enough to write something like '(filter (complement #'integerp) ...)'. Anyway, even though I prefer 'filter', I could live with 'keep-if'. And by the argument I just gave, we wouldn't really need 'remove-if' anymore. The problem is 'delete-if'/'delete-if-not'; what do we do with them? I guess I would rename 'delete-if-not' to 'nkeep-if' (by analogy with 'nreverse' and 'nsubstitute') and discard 'delete-if'. [0] http://ergy.com/FSet.html http://ergy.com/FSet.html
- such_a_casual 11y agoI completely disagree. Remove-if-not is explicit. You know exactly what it does just by reading it. Your suggestion of filter could either mean use this filter to only grab the the things I want or use this filter to filter out the things I don't want. Complaining about the complexity of a name like "remove-if-not" makes absolutely no sense to me. Anyone can read that name and know exactly what it does. You only know what filter means because of your familiarity with it and not because of any inherit simplicity in its name.
- waterhouse 11y agoFYI, in Arc, the corresponding functions to "remove-if-not" and "remove-if" are called "keep" and "rem".
- chaitanya 11y agoAnd don't forget to check out cl-interpol. Besides being a perfect companion to cl-ppcre, its great in itself if you like things like string interpolation.
- lispm 11y agoIt was later thought that one better writes (remove-if (complement #'prime-p) ...) and not (remove-if-not #'prime-p ...) and thus REMOVE-IF-NOT was deprecated in the ANSI CL standard.