LEARN EMACS LISP - Mostly The Strange Parts

แชร์
ฝัง
  • เผยแพร่เมื่อ 27 พ.ย. 2024

ความคิดเห็น • 78

  • @reesecurrie
    @reesecurrie 2 ปีที่แล้ว +8

    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 ปีที่แล้ว +5

      Comments like this warm my heart. Thank you

  • @luserdroog
    @luserdroog 2 ปีที่แล้ว +27

    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 ปีที่แล้ว +1

      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.

  • @hendrikboom
    @hendrikboom 9 หลายเดือนก่อน

    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.

  • @arialdomartini
    @arialdomartini 3 วันที่ผ่านมา

    Thank you thank you! Such great quality and fresh videos are what Emacs deserves. Kudos, really well done! If I can suggest: the amount of keybindings in Emacs might look intimidating to newcomers. I've always thought that mentioning the commands to be run with M-x, together with the keybinding, might help seeing Emacs as more approachable.

  • @Bhanukamax
    @Bhanukamax 2 ปีที่แล้ว +4

    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.

  • @lens3973
    @lens3973 2 ปีที่แล้ว +3

    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!

  • @AndersJackson
    @AndersJackson 2 ปีที่แล้ว +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)

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 2 ปีที่แล้ว +7

    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.

  • @nyd3386
    @nyd3386 2 ปีที่แล้ว +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 ปีที่แล้ว +8

    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 ปีที่แล้ว +2

      Or Clojure, Hy, or any other LISP-1 :P

  • @andriitarykin9567
    @andriitarykin9567 2 ปีที่แล้ว +3

    Thank you! Happy to see more and content about Lisp on TH-cam.

    • @GavinFreeborn
      @GavinFreeborn  2 ปีที่แล้ว +1

      My pleasure! Happy to make it.

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 2 ปีที่แล้ว +8

    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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +1

      @@AndersJackson Thank you for this :)

  • @jacquesdurand4416
    @jacquesdurand4416 2 ปีที่แล้ว +1

    Teaching lisp with a Hawaiian shirt somehow made it even better :) Good video !

    • @GavinFreeborn
      @GavinFreeborn  2 ปีที่แล้ว +2

      Glad you liked it! The shirt I mean 🤣

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 2 ปีที่แล้ว +3

    10:44 Python allows the form “(10).‗‗add‗‗(1)”. That is, an explicit method call on the object “10”.

  • @gamerboy4566
    @gamerboy4566 2 ปีที่แล้ว +1

    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 ปีที่แล้ว +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 ปีที่แล้ว +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 ปีที่แล้ว +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 ปีที่แล้ว +1

    i love you, thank youfor doing this video !

    • @GavinFreeborn
      @GavinFreeborn  2 ปีที่แล้ว +1

      You're so welcome! Great to see you liked it!

  • @pierreabounaoum3713
    @pierreabounaoum3713 22 วันที่ผ่านมา

    have you ever worked on Gtk+? I get an error on finding library? any Idea?

  • @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 ปีที่แล้ว +2

      ​@@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 :)

  • @محمدفرج-ث7ذ3د
    @محمدفرج-ث7ذ3د 2 ปีที่แล้ว

    Awesome could we see more like this

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 2 ปีที่แล้ว +1

    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 ปีที่แล้ว +1

      @@lens3973 Those are *always* the same thing. It’s a core LISP concept.

    • @acebulf
      @acebulf 2 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +1

    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!

  • @lukass3409
    @lukass3409 ปีที่แล้ว

    go push that emacs dream

  • @sethbrown1763
    @sethbrown1763 ปีที่แล้ว

    I _will_ understand Lisp ... someday :)

  • @JeffParker45
    @JeffParker45 2 ปีที่แล้ว

    Very Good Video, Thank You!

  • @lawrencedoliveiro9104
    @lawrencedoliveiro9104 2 ปีที่แล้ว +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 ปีที่แล้ว +1

      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 ปีที่แล้ว +1

      @@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 ปีที่แล้ว +1

      @@GavinFreeborn That’s why I have those comments. You couldn’t have them if they were all on the same line.

    • @GavinFreeborn
      @GavinFreeborn  2 ปีที่แล้ว +1

      @@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

  • @johnc3403
    @johnc3403 11 หลายเดือนก่อน

    Well, we got roads, medicine, electricity, sanitation, communications, flight and the printing press, ..but I guess Emacs is up there too somewhere... 0:04

  • @venum17
    @venum17 2 ปีที่แล้ว +1

    6:13 funciton 😄

  • @kapilrakh
    @kapilrakh 2 ปีที่แล้ว

    Which mic do you use for sound input?

  • @acebulf
    @acebulf 2 ปีที่แล้ว

    Great video!

  • @moumnalmunawy1806
    @moumnalmunawy1806 2 ปีที่แล้ว +1

    Please make a common Lisp tutorial

    • @GavinFreeborn
      @GavinFreeborn  2 ปีที่แล้ว +2

      Funny enough all of this also applies to common lisp 😉. I have plenty planned though don't worry

  • @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

  • @ScottxHaley
    @ScottxHaley 2 ปีที่แล้ว +1

    My favorite drink is Jaeger

  • @illegalsmirf
    @illegalsmirf 2 ปีที่แล้ว +1

    Richard Stallman would marry you

  • @ericpmoss
    @ericpmoss 2 ปีที่แล้ว +1

    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 ปีที่แล้ว +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