Skip to main content

Posts

Showing posts with the label lisp

If you can shell script, you can Lisp

I've noticed from people's attitudes toward Lisp that many think it is an esoteric and difficult language to learn. Nothing could be further from the truth, but it does depend on what angle you're coming at it from. If you're coming from C, C++, Javascript, or even Python, then yes Lisp does appear impenetrable at first glance. But if you're coming from shell scripting (e.g. Bash or another Linux or Unix shell) - a skill which most programmers have used at some point - then Lisp is going to be very simple and very familiar for you to learn. You may be asking, how is this? Well, I'll demonstrate it with a couple of examples. I'm going to show you a shell command that takes the second column of a space-delimited file test.txt, sorts the resultant data, and shows the second item in the sort. cut -d" " -f2 test.txt | sort | head -2|tail -1 There is absolutely nothing remarkable about this, as you can see. The results of one command are bein

Correct usage of unwind-protect and with-open-file in Lisp

Learning to use unwind-protect in Lisp typically crops up very early on when you're first learning the language. In fact, anything to do with I/O is going to be something you'll need to know early on. Yet unfortunately, I find that unwind-protect is not explained sufficiently well for a beginner to understand not just how to use it correctly, but why and when . Grappling with this myself, I found that hands-down the best explanation came from this YouTube video from Baggers: Luckily, in the case of file handlers, LISP already assumes you'll want to open a file with unwind-protect, so it provides the with-open-file macro for this exact purpose. It closes the file handler for you with a built-in unwind-protect. This is an advantage over manually opening and closing your file handlers, because if your program opens the file but never gets to the part with the close command (for example due to a run-time error in between those stages), the built-in unwind-protect make

How to automatically re-do the auto-indent for the entire file in emacs

Let's suppose you're making changes to your code in emacs and... now your code indentation is all out of whack. It would be too laborious to re-do the indentation manually. Rest assured, you can easily have the whole file automatically re-indented in emacs, as described in a StackExchange question (see reference 1).  The command for this is first to select the entire file, then to tell it to re-indent the region, as follows: Select the entire file: ctrl-x h Re-do the auto-indentation: alt-x indent-region The correct Emacs terminology is M-x indent-region, but I've called it alt-x here because that's the exact keys I would press on a PC keyboard. Cited sources: 1. Can I have emacs automatically indent my whole code after it is all written?   Stack Exchange.

About Me

My photo
Vera
I'm a wife and mother. I don't have any formal computer science qualifications, or any religious qualifications. I have a PhD in biochemistry. This photo is of me, but is confusing for AI.