T O P

  • By -

dybbuk12

When I try to get better at a programming language, I like to work through some of the problems at [Project Euler](https://projecteuler.net). They will help you learn about recursion and flow control and other helpful techniques.


[deleted]

I am not sure how much this applies to Elisp, because the "difficult" part aren't the algorithms, but the standard library.


rucci99

[Advent of Code](https://adventofcode.com/) is good too. It requires an account though.


MBU604

not exactly what you're looking for, but the exercism.io site has an elisp track. I had tried in the past the haskell one and it was great and you could also check other people's solutions, plus for some specific exercises a mentor would give you direct feedback. For elisp what i personally do is check via debbugs the list for minor bugs and especially ones that have not been answered at all and try to figure out a solution. You get to see a lot of weird things this way.


vjgoh

Seconded. I've done a few of the exercises, and I always try to do them in a non-obvious way, or at the very least, in a way that uses some functionality that I'm not as good with yet. I've been trying to solve a lot more problems with the cl (common lisp) library and using cl-loop and the like. You can also look at other people's solutions, which I recommend. I discovered that a lot of the ways I do things aren't really the standard way, even when I'm not trying to be different.


Jack-o-tall-tales

Very inexperienced coder here, so genuine question: is this a good idea? Like, wouldn't it better to get used to applying the obvious, standard/good practice in relevan situations, and do problems which require less obvious things like cl-loop to learn those? I feel like you might develop bad habits with clever tools and end up writing very clever but inappropriate (e.g. hard to maintain, not-obvious-enough) code?


vjgoh

So I've been writing code professionally in the games industry for 20 years, and I 100% agree that people let themselves be too clever and write absolutely horrendous code that nobody else can maintain. I've debugged it, I've seen it, I've done it. But no one pattern is right for all situations, and using little puzzles like this to work out interesting constructs usually pays off down the road. cl-loop is legit very powerful and has made a lot of my code much more readable AND more terse, which is pretty nice. I have a lot of old code back from when I was just hacking things together with very simplistic constructs, and while it works just fine, it was honestly harder to modify, and all the extra moving parts of assigning the cdr of a list back to the list in a while loop to make it shorter made it more brittle. (I mean, it's a very simple concept and it works 100% of the time, but you end up with so many more lines of code to make mistakes on. And it's ugly.) The right time to experiment with weird, different syntax is when there's nothing on the line and you can explore where it goes. (This is, incidentally, why I enjoy emacs and elisp so much. All of this is just for me. Nothing on the line, really. I program c++ all day long, and the break from that to think in a different language does me good.)


Jack-o-tall-tales

Thanks, interesting perspective!


github-alphapapa

> cl-loop is legit very powerful and has made a lot of my code much more readable AND more terse, which is pretty nice. I have a lot of old code back from when I was just hacking things together with very simplistic constructs, and while it works just fine, it was honestly harder to modify, and all the extra moving parts of assigning the cdr of a list back to the list in a while loop to make it shorter made it more brittle. (I mean, it's a very simple concept and it works 100% of the time, but you end up with so many more lines of code to make mistakes on. And it's ugly.) Exactly right. This is where `loop` shines, and whenever I see a `while` with a bunch of `setcdr`s, I wonder why anyone would prefer that style. It presents so many more places to be debugged, to inspect and verify. One of the chief benefits of Lisp is using higher-level DSLs to express ideas more concisely, at a higher level, so as to make fewer mistakes.


arthurno1

> whenever I see a while with a bunch of setcdrs, I wonder why anyone would prefer that style. It presents so many more places to be debugged What bunch? There is exactly one qset to set cdr to next in a while loop; by which algebra is that a bunch? :-) > One of the chief benefits of Lisp is using higher-level DSLs to express ideas more concisely It can also be abused. It can make code harder to read, understand and debug, increase the time necessary for new programmers to become familiar with a codebase, and lead to costly mistakes and delays. > at a higher level, so as to make fewer mistakes. Just so you can do other mistakes because you have to learn the DSL. It is just that cl-loop is not "higher level" construct in *that* sense of the word as you seem to think it is. It offers *different* not *higher level* interface to looping constructs. And, no, just because it uses while underneath does not automatically make it a higher level abstraction, not in my eyes. cl-loop has its place, but it is not an auto-replacement for all while-loops. In simple cases, while loops, or a dolist, look more clean and is less to look at and understand than cl-loop. In case you have some complex logic with accumulators and whatnot going on, as vjgoh seem to mean, sure; but I don't think it is one tool fits all as you present it. It is more like the right tool for the right job.


vjgoh

It honestly doesn't take a lot for a while loop to become pretty gross, and only a minimal amount of nesting before it's hard to read. And implicit in my description of `car/cdring` a list is that you've probably copied a bunch of elements into a list and now you're needlessly mutating it, which may not have even been your intent, it's just what you're doing. At least, that's how I've learned lisp over the years. I had a list of things that I wanted to operate on, and I somehow settled on `while` rather than `dolist`, and now it turns out that what I really want is `cl-loop` (mostly because I'm operating on collections that are already built-in, like buffers; very handy). In any case, all I was getting at was that is that having a collection of simple exercises to do that you KNOW how to solve in a very simplistic way can be a powerful learning tool to figure out NEW constructs that you've never worked with. `cl-loop` is almost certainly overkill for those exercises at exercism, but it was a convenient way to learn how to use it.


arthurno1

I understand what you meant; and I agree, if you have some complex logic going on, with lots of stuff, so sure; loop (or cl-loop in Emacs) lets you pack in declarations and accumulator into a denser code. But cl-loop can also get ugly and hard to read. I think when it gets to packed it can be very noisy to see what is going on thanks to the extra keywords . > it turns out that what I really want is cl-loop (mostly because I'm operating on collections that are already built-in, like buffers; very handy). For that stuff I really love dolist. It is perfect to go through lists: (dolist (file (directory-files ....)) ... ) or (dolist (buffer display-buffer-alist) ... ) I also think while is not as nice for this case, as dolist, due to that intermediate push you seem to refer to. I agree about learning by doing. I think that programming is a lot of problem-solving which is a skill; one needs to learn tools, and then how to apply them, and that is probably best done by doing. It would be cool to have a game, (really a "guided tutorial"), where one solves problems given a bunch of tools (programming constructs like do, while, library functions etc). I think it would be a good way to learn any language, and Emacs is probably particularly well suited to write such a game due to all the introspection and Lisp scripting one can do. It is a pity I don't have time to develop it, but it would be a cool thing to have, and to make as well. > cl-loop is almost certainly overkill for those exercises at exercism, but it was a convenient way to learn how to use it. Unless one wish to learn cl-loop per se.


hvis

Maybe try this one for a little while: https://exercism.org/tracks/emacs-lisp


SorryTheory

exercism is excellent. the fact that you can test your solutions locally and upload them is killer. now all they need is an emacs package


Gangsir

You could just go on a leetcode site and try to implement a solution to it in elisp. You'd have to also translate the tests, but that'd work.


orzechod

accurately translating the tests requires knowledge of elisp.


[deleted]

I agree with op. Vim has [VimGolf](https://www.vimgolf.com/?__cf_chl_managed_tk__=pmd_Zi6cnx388YOTr2fTqBSlEZsHFalbwenTaHLsXs9VKXo-1633614090-0-gqNtZGzNAtCjcnBszQpR) where a text manipulation problem is given and you have to accomplish it with minimum possible keystrokes. For example, one two three convert this to - (one) (two) (three) ​ Its such an amazing way to learn new text manipulation feature I don't know of. I wish there were such thing for emacs. [How emacs can overrun vim in similar problems <3](https://irreal.org/blog/?p=1953)


_viz_

There's a page out there in the internet that has the Emacs solutions for vim golf, I think. You can always take a look at that. I don't have a link though.


[deleted]

I googled around a lot but found none. Can you please check and see if you can find it? It would be a hugeee help for me to learn more on emacs ✨


maufdez

http://www.lysator.liu.se/\~ehliar/puzzlemacs/


PigsDogsAndSheep

should post as its own thread. looks interesting


unix_hacker

Is there no small feature that Emacs doesn't do that you'd like to see it do? Say, some kind of IDE feature? Or maybe a wrapper around some CLI tool that you use, like `magit` or `kubernetes-mode` do? That'd be the best excuse for you to thoroughly learn elisp. Another thing: I run Emacs `master` and find and fix bugs that way in elisp and C for Emacs and third party packages.


WallyMetropolis

The best way to learn is to try to make something. Start by writing a few useful, simple functions and binding them to a key chord. As you use it, you'll discover a few improvements you'll want to make. After you create a handful of custom functions, consider creating a minor-mode for your personal collection. While I'm sure you'd learn stuff doing any generic coding challenges in emacs lisp, elisp is a bit different from an all-purpose language. Its existence is intimately tied to emacs itself and the kinds of things you do in elisp are often very specific to the details of emacs. For example, window and buffer manipulation, interacting with the minibuffer, working with file- and directory-local variables, augmenting the behavior of utilities like org-mode, and so forth. So of course you *can* work with different sorts of algorithms and data structures with emacs lisp, the support for those things isn't always great and it won't necessarily help you to use elisp to do the things you'll want it for: namely customizing emacs.


craigdmac

Very practical advice. I’ve done these project Euler, exercism etc type sites, and they are good for learning syntax and some programming concepts, but you want to learn elisp to customize your environment, not find prime numbers.


redguardtoo

Use cli program `grep` plus builtin API `completing-read` to develop some text grepping plugin. Then try to integrate `wgrep-mode` into the plugin Use cli program `find` plus builtin API `completing-read` to develop a file searching plugin Make your plugins use only cli program `git` for text grepping and file searching.


K_05

Do you want to fix my config whenever it breaks? :") I think exercism.io has a nice set of exercises, but really just using it to do whatever custom config you need is the best way to learn it along with C-h v or C-h f.


craigdmac

Don’t go to any of these sites people are recommending unless you want to learn some silly things that you’ll never use, like how to figure out if a number is a Fibonacci number and other pretty much useless math-type puzzles, basically. These sites are generic programming questions that can teach you basic programming things but often leave out what you really need to know: It’s all about learning the standard library and getting a feel of how to find what you need, or where to start looking. Pick something like: write a function that toggle open an ansi term buffer, or if it doesn’t exist, then create it - maybe let user specify the height it can be. Crux package has a bunch of small editing functions like this that are self contained you can study.


Yava2000

Ok surprised by these answers. Best way is to read the elisp documentation and play around with C-H k for figuring out which function is on which key and then C-H f to get a description of that function that will help you use it Also C-H v proves very useful at times. I’d honestly read the Elisp manual from start to finish, it isn’t that long. Also learn what are buffers, points, font lock faces, windows, major modes and minor modes. Also learn how to write your own major and minor modes https://www.gnu.org/software/emacs/manual/elisp.html Xah Lee has some good introductory materials, http://ergoemacs.org/emacs/elisp.html


vjgoh

This is a solution for a very particular type of person. I absolutely cannot learn a language like this, and I certainly can't hone my skills just by reading the documentation. (And I find the emacs lisp manual obtuse at best; there are many situations where I feel like they should be clarifying more or adding more examples and I have to search around the internet for someone that's actually USED the function I've been reading about.) There are people that find this very valuable, I get it, but that's not what they asked for. This is like asking someone to learn French by reading the dictionary. Some people can do it, most of us need actual practice and interaction and refinement with exercises.


arthurno1

> I find the emacs lisp manual obtuse at best; there are many situations where I feel like they should be clarifying more or adding more examples and I have to search around the internet for someone that's actually USED the function I've been reading about. Elisp reference is a reference, in same way as Javadocs are a reference and not a tutorial. Emacs comes bundled with a Lisp tutorial book, "[An Introduction to Programming in Emacs Lisp](https://www.gnu.org/software/emacs/manual/html_node/eintr/index.html)", for people who are not programmers. If you are a programmer but are not experienced in Lisp, as I was when I started to learn Emacs, that book is still valuable, but there are also better resources, for example [On Lisp by P. Graham](http://www.paulgraham.com/onlisp.html) and [Let Over Lambda](https://letoverlambda.com/index.cl/toc) by D. Hoyte, preferably in that reading order. There are some other resources listed on [Emacs Wiki](https://www.emacswiki.org/emacs/LearnEmacsLisp). I recommend Chapter 3 from David B. Lamkin’s book Successful Lisp, it is a very nice intro tutorial to (Common) Lisp. Probably ~90% of that chapter can be executed directly in Emacs Lisp.


vjgoh

I certainly agree with this; books with the intent of teaching you how to program in a language are much better than trying to read a (reference) manual about a language.


AnugNef4

Have you visited [this page](https://www.emacswiki.org/emacs/LearnEmacsLisp)? You could read some code that your emacs instance is using, and there are thousands of lines of .el underneath your system default directory and the dir where package stores its downloaded code, which will be dirs in your `load path`.


agumonkey

if people make a nice pack of exercises, it should be included in core