LEARN EMACS LISP - Mostly The Strange Parts

  Рет қаралды 17,830

Gavin Freeborn

Gavin Freeborn

Күн бұрын

Пікірлер: 77
@luserdroog
@luserdroog 2 жыл бұрын
Short explanation of 'car' and 'cdr': The original IBM machines used for Lisp had a long instruction word with an A bitfield and a D bitfield. They called the bitfields "registers", so we have CAR= and CDR=. "Address" and "Decrement" refered to the weird negative indexing that the IBM machines did. But you can think of it as just snagging one of two bitfields called A and D. The values stored in the bitfields were pointers, usually "tagged pointers".
@ctoid
@ctoid Жыл бұрын
Thanks bro.
@miko007
@miko007 Жыл бұрын
that is wrong. the ibm 704 did not have an address register.
@atharvbhagya4317
@atharvbhagya4317 Жыл бұрын
it'd be better if you could also link a source or 2.
@luserdroog
@luserdroog Жыл бұрын
@@miko007 Quite right. It had "a register". But a portion of it was the address part.
@reesecurrie
@reesecurrie 2 жыл бұрын
Gavin as an old greybeard who has been using Emacs for almost 20 years, it's awfully encouraging to see young people using it. It's a productivity superweapon. Thanks for spreading the news.
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
Comments like this warm my heart. Thank you
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
7:47 Another thing that LISP and Python have in common is support for docstrings. If the first item/statement in the function body is a string literal, then it can be displayed as help text for the function.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
23:39 Having separate namespaces for functions and variables is a feature of Common LISP. If you think it makes more sense to have both in the same namespace, try the LISP variant known as Scheme.
@trannusaran6164
@trannusaran6164 2 жыл бұрын
Or Clojure, Hy, or any other LISP-1 :P
@Bhanukamax
@Bhanukamax 2 жыл бұрын
This is a nice one, I had been wondering what the whole hash quote (#') business is all about, but never took the time to figure it out, this video cleared it up for me.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
12:13 The first implementation of LISP was on an early IBM machine. Each cell of the list fitted nicely into a single machine word, and the two halves were called the “address register” and the “displacement register” (I think). The “C” stood for “contents”, and so you can now figure out what “CAR” and “CDR” stand for.
@c1dk1n
@c1dk1n 2 жыл бұрын
More to your point lists are for structuring data in trees known as CONS(tructs) where the CAR is the Content of the "Address Register" and CDR is the Contents of the "Decrement Register." You can also see these sometimes referred to as the "Head" and "Tail" of the data, or the "First" and "Rest" of the data, the latter of the two makes the most sense to me.
@AndersJackson
@AndersJackson 2 жыл бұрын
@@c1dk1n it is lists, not trees. But lists can be arranged as trees. Yes, car can be aliased with first and cdr can be aliased to rest. And are often aliased as them. But you are right about cons, being CONStruct. That is what makes up a list, and the end is marked with an empty list (nil or ()) or a symbol. A proper list should have cons where the last is nil, but there are also constructions where it ends with a symbol.
@c1dk1n
@c1dk1n 2 жыл бұрын
@@AndersJackson Thank you for this :)
@hendrikboom
@hendrikboom 7 ай бұрын
I learned Lisp in about 1964. I liked it so much that I made my own implementation -- there wasn't one available on the only computer I had available. Nowadays I use Racket, a Lisp derivative. It's somewhat more streamlined than that first Lisp. This video really brings me back to those days. Thank you.
@AndersJackson
@AndersJackson 2 жыл бұрын
I like the introduction, and that explanation of the name space for variables and functions. That is that symbols can have two different values. You can also use set and setf for variable and function name space for variables. There are aliases for car and cdr, which is first and rest. But there are some uses with car and cdr is usefull. For instance (car (cdr (cdr '(1 2 3 4 5)))) evaluate to 3, which is the same as (caddr '(1 2 3 4 5)) which also evaluate to 3. So you can easy combine some first (car) and rest (cdr) into one function. Another common examle is to test (cons (car '(1 2 3)) (cdr '(1 2 3))) which is '(1 2 3)
@lens3973
@lens3973 2 жыл бұрын
Great video! I am just now implementing an open source, cross platform text editor based on my love of Emacs and LISP, called LITE. I plan to eventually port LITE to my own OS as the built in text editor, but I have to implement dynamic linking first, which I've been procrastinating about forever :p Also, when mentioning car and cdr, I feel like it is imperative to also mention why they exist: lists are implemented as recursive pairs, meaning each value actually has a left and a right value. The nested pairs are parsed and displayed in a special syntax that is easier to read (the parenthesized list), but under the hood a 123 list should look like "(1 . (2 . (3 . nil)))". At least that's what I needed for it to click in my head. Thanks again for the amazing video!
@andriitarykin9567
@andriitarykin9567 2 жыл бұрын
Thank you! Happy to see more and content about Lisp on KZbin.
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
My pleasure! Happy to make it.
@nyd3386
@nyd3386 2 жыл бұрын
Thank you so much! I've been trying to learn elisp but was confused with different namespaces for functions and variables. Your videos are always awesomely useful and easy to understand!!
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
10:44 Python allows the form “(10).‗‗add‗‗(1)”. That is, an explicit method call on the object “10”.
@jacquesdurand4416
@jacquesdurand4416 2 жыл бұрын
Teaching lisp with a Hawaiian shirt somehow made it even better :) Good video !
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
Glad you liked it! The shirt I mean 🤣
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
6:15 Perhaps a better way to say it is that every (non-simple) LISP construct looks like “(«word» ...)” where that first «word» after the opening parenthesis determines how the rest is interpreted. Usually it’s the name of a function, but it can be a macro or some other things as well.
@AndersJackson
@AndersJackson 2 жыл бұрын
It is all functions, and most functions are evaluated after all the arguments are evaluated (called normal form). But some are handling the argument unevaluated (called special form). Like setq, quote, cond (original LISP only had cond, no if) if etc. That all arguments are evaluated before they are sent to the function works in most cases, but not for instance for if. (if (eq divisor 0) 0 (/ 10 divisor)) That would not worrk, because if divisor are 0, then we will get error division by zero, and not 0. So some functions are evaluating the argument themself, like the ones mentioned above. Macros are just special functions that are evaluated when reading the progams, and the result is the program that is used.
@gamerboy4566
@gamerboy4566 2 жыл бұрын
Thanks for making this video. There seems to be a lack of tutorial videos on emacs lisp compared to things like lua for neovim, etc.
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
You're very welcome! I think it comes down to how few Emacs related content creators out there and even less of those feel comfortable with elisp enough to explain it. Hopefully this video will help fill in the gaps.
@AndersJackson
@AndersJackson 2 жыл бұрын
Yes, Gavins videos are great for introduction and configuring Emacs and in this case Elisp. Another one I recommend is also System Crafters. Botth are great examples of content that is useful to have when one want to learn Emacs and Elisp.
@gamerboy4566
@gamerboy4566 2 жыл бұрын
@@AndersJackson Yeah, System Crafters is also awesome. I am subscribed to both.
@ironmanlifts
@ironmanlifts 2 жыл бұрын
Thanks for the video, I was wondering what mapcar did. I presume one is only limited by the knowledge of lisp, as to what they can do in emacs. Hopefully yasnippet can replace my ultisnips.
@quentinquadrat9389
@quentinquadrat9389 Жыл бұрын
Would be nice if you make more Lisp training videos :) I'm a C++ guy who wants to switch to Lisp and Prolog.
@delibellus
@delibellus Жыл бұрын
that's a peculiar switch, but an interesting one, too. there is something comfy and nice about diving into old languages, i don't know if that's motivating you.
@quentinquadrat9389
@quentinquadrat9389 Жыл бұрын
​@@delibellus In my opinion, the golden age of computer science was Lisp Machine: all integrated and consistent. Unix was less well-made but less expensive so more popular and since this time, computer science did not make progress that Lisp Machine already solved. AFAIK since I'm born in 80's I did not know this age. Our generation cannot understand how our fathers' generation could succeed making expert systems combining Lisp and Prolog accessing databases of mathematical solvers that you could interact with in natural language and the system generated Fortran code and Phd-quality papers in TeX. I'm nostalgic of this epoch I have never met :)
@jwiskikruger8921
@jwiskikruger8921 2 жыл бұрын
i love you, thank youfor doing this video !
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
You're so welcome! Great to see you liked it!
@sethbrown1763
@sethbrown1763 11 ай бұрын
I _will_ understand Lisp ... someday :)
@محمدفرج-ث7ذ3د
@محمدفرج-ث7ذ3د 2 жыл бұрын
Awesome could we see more like this
@kapilrakh
@kapilrakh 2 жыл бұрын
Which mic do you use for sound input?
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
Just a blue Yeti
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
19:10 A pair of empty parentheses is another of those constructs that evaluates to itself, so it doesn’t need to be quoted.
@lens3973
@lens3973 2 жыл бұрын
He probably avoided it as it's different between the LISPs. Sometimes empty parens evaluate to an empty list, sometimes to nil, and sometimes those are the same thing!
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
@@lens3973 Those are *always* the same thing. It’s a core LISP concept.
@acebulf
@acebulf 2 жыл бұрын
@@lawrencedoliveiro9104 Scheme and related dialects have #f, which is distinct from nil. e.g. (not '()) is #f for example.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
@@acebulf OK, so Scheme diverges more from traditional LISP concepts than I thought.
@AndersJackson
@AndersJackson 2 жыл бұрын
@@acebulf that is true and false. Lisp, like C uses 0 or (), nil as false. And anything different are true. And yes, Scheme are simplified Lisp.
@divest6527
@divest6527 2 жыл бұрын
This was super helpful for me. One thing I’d like to understand better is how to apply this knowledge in the maintenance of .dir-locals.el files! With Eglot, you often end up building (relatively) complex data structures, but without access to lisp - look at some of the examples for yaml-language-server and you’ll see what I mean!
@jorgegomezabrante8780
@jorgegomezabrante8780 2 жыл бұрын
hi would you be able to link your org file in the video? it would be much appreciated
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
gist.github.com/Gavinok/e68a21b0e72607b20a1e0255b3aeb9fe Here you are
@lukass3409
@lukass3409 Жыл бұрын
go push that emacs dream
@JeffParker45
@JeffParker45 2 жыл бұрын
Very Good Video, Thank You!
@johnc3403
@johnc3403 9 ай бұрын
Well, we got roads, medicine, electricity, sanitation, communications, flight and the printing press, ..but I guess Emacs is up there too somewhere... 0:04
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
8:02 I figured early on that having all those closing parentheses pile up together is not conducive to readability. So I decided to follow a formatting rule analogous to the one I use for statement brackets in C and other languages, where I put the closing parenthesis on a line by itself, at the same indent as the corresponding opener, e.g. (defun funcname (arg) (print 10) ) ; defun Sure, one line per closing parenthesis may seem excessive, but why not?
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
I just don't find it to be necessary and makes it easier to read larger files with the way shown in the video. I totally get people taking the same approach you do. Just figured since this is focused on teaching explaining how you can read Lisp the proper way would help in the long run. It's something people complain about before realizing it's actually better to just ignore the parens and let the indentation guide your eyes.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
@@GavinFreeborn Try a larger example, and see if you still agree: (defun convert-to-region-codes (beg end) "converts alphabetic characters in the selection to “region indicator symbols”." (interactive "*r") (unless (use-region-p) (ding) (keyboard-quit) ) ; unless (let ( deactivate-mark (intext (delete-and-extract-region beg end)) c ) (dotimes (i (- end beg)) (setq c (elt intext i)) (cond ((and (>= c ?A) (= c ?a) (
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
@@lawrencedoliveiro9104 I personally still feel the same way. If it weren't for the extra comments I'd have a hard time even telling which open paren they relate to. I am sure I would eventually get used to it. I've just gotten used to writing and reading lisp at this point.
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
@@GavinFreeborn That’s why I have those comments. You couldn’t have them if they were all on the same line.
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
@@lawrencedoliveiro9104 my point was more that I wouldn't have any use for them in that case. Since it's all condensed enough I don't have to scan up and down. To be fair I am dyslexic so maybe that's why I prefer everything closer together so I don't get mixed up. Who knows
@venum17
@venum17 2 жыл бұрын
6:13 funciton 😄
@ScottxHaley
@ScottxHaley 2 жыл бұрын
My favorite drink is Jaeger
@acebulf
@acebulf 2 жыл бұрын
Great video!
@reverseila
@reverseila 2 жыл бұрын
Thanks man!
@moumnalmunawy1806
@moumnalmunawy1806 2 жыл бұрын
Please make a common Lisp tutorial
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
Funny enough all of this also applies to common lisp 😉. I have plenty planned though don't worry
@ericpmoss
@ericpmoss 2 жыл бұрын
Can you turn down the treble a bit? This sounds like an ASMR video, and it annoys me so much I can’t listen to it. Thanks.
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
Sure I'll see what I can do 🙂
@illegalsmirf
@illegalsmirf 2 жыл бұрын
Richard Stallman would marry you
@lawrencedoliveiro9104
@lawrencedoliveiro9104 2 жыл бұрын
3:29 Try following the CTRL-H with “?” to get a list of all the categories of help available.
@GavinFreeborn
@GavinFreeborn 2 жыл бұрын
Oh that would have been worth mentioning! Thanks
You Should Really Learn Org Mode - It's Easy
19:32
Gavin Freeborn
Рет қаралды 51 М.
Learn Emacs Lisp in 30 Minutes
30:22
Gavin Freeborn
Рет қаралды 10 М.
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,9 МЛН
НАШЛА ДЕНЬГИ🙀@VERONIKAborsch
00:38
МишАня
Рет қаралды 2,5 МЛН
How to whistle ?? 😱😱
00:31
Tibo InShape
Рет қаралды 14 МЛН
Flipping Robot vs Heavier And Heavier Objects
00:34
Mark Rober
Рет қаралды 59 МЛН
Why You Should Learn Lisp In 2024
21:50
Gavin Freeborn
Рет қаралды 66 М.
The Rise & Fall of LISP - Too Good For The Rest Of the World
17:44
Gavin Freeborn
Рет қаралды 41 М.
Why Lisp Is One Of The Most Productive Programming Languages
12:14
Gavin Freeborn
Рет қаралды 43 М.
I Made a ChatGPT Like Client For Emacs - AND SO CAN YOU!!
16:15
Gavin Freeborn
Рет қаралды 8 М.
The 6 Emacs Settings Every User Should Consider
15:41
System Crafters
Рет қаралды 36 М.
Distro-hopping In Linux May Be Bad For Your Mental Health
12:23
Linux Dev Labs
Рет қаралды 1 М.
Why Are Lisp Macros So Great!?
16:28
Gavin Freeborn
Рет қаралды 15 М.
Rewrite Your Scripts In LISP - with Roswell
21:23
Gavin Freeborn
Рет қаралды 21 М.
РОДИТЕЛИ НА ШКОЛЬНОМ ПРАЗДНИКЕ
01:00
SIDELNIKOVVV
Рет қаралды 3,9 МЛН