Тёмный

LEARN EMACS LISP - Mostly The Strange Parts 

Gavin Freeborn
Подписаться 12 тыс.
Просмотров 18 тыс.
50% 1

Опубликовано:

 

7 сен 2024

Поделиться:

Ссылка:

Скачать:

Готовим ссылку...

Добавить в:

Мой плейлист
Посмотреть позже
Комментарии : 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 11 месяцев назад
it'd be better if you could also link a source or 2.
@luserdroog
@luserdroog 10 месяцев назад
@@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 года назад
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
@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 года назад
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 :)
@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.
@andriitarykin9567
@andriitarykin9567 2 года назад
Thank you! Happy to see more and content about Lisp on RU-vid.
@GavinFreeborn
@GavinFreeborn 2 года назад
My pleasure! Happy to make it.
@hendrikboom
@hendrikboom 6 месяцев назад
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!
@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 🤣
@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.
@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.
@jwiskikruger8921
@jwiskikruger8921 2 года назад
i love you, thank youfor doing this video !
@GavinFreeborn
@GavinFreeborn 2 года назад
You're so welcome! Great to see you liked it!
@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 :)
@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.
@venum17
@venum17 2 года назад
6:13 funciton 😄
@user-xu9zx9fd7n
@user-xu9zx9fd7n 2 года назад
Awesome could we see more like this
@sethbrown1763
@sethbrown1763 10 месяцев назад
I _will_ understand Lisp ... someday :)
@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.
@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!
@JeffParker45
@JeffParker45 2 года назад
Very Good Video, Thank You!
@johnc3403
@johnc3403 8 месяцев назад
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
@lukass3409
@lukass3409 Год назад
go push that emacs dream
@acebulf
@acebulf 2 года назад
Great video!
@kuijaye
@kuijaye 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
@ScottxHaley
@ScottxHaley 2 года назад
My favorite drink is Jaeger
@kapilrakh
@kapilrakh 2 года назад
Which mic do you use for sound input?
@GavinFreeborn
@GavinFreeborn 2 года назад
Just a blue Yeti
@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
@illegalsmirf
@illegalsmirf 2 года назад
Richard Stallman would marry you
@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 🙂
@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
Просмотров 49 тыс.
Learn Emacs Lisp in 30 Minutes
30:22
Просмотров 9 тыс.
ВОТ ЧТО МЫ КУПИЛИ НА ALIEXPRESS
11:28
Compilers, How They Work, And Writing Them From Scratch
23:53
Why Are Lisp Macros So Great!?
16:28
Просмотров 15 тыс.
Org Roam: The Best Way to Keep a Journal in Emacs
16:50
Every LLM in Emacs, with gptel
17:56
Просмотров 11 тыс.
5 Reasons I Love Emacs Orgmode
15:43
Просмотров 11 тыс.
How to be a git expert
46:26
Просмотров 158 тыс.