Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

My Lisp education was mostly from Elisp, but this I understood early when I was reading some random code and came across:

    (setf (buffer-string) "hello")
I thought this was just bananas, turns out that Elisp setf simply has a bunch of hardcoded rules for matching getters/setters for even a lot of non-standard data structures like Buffer that are Emacs specific. So the above gets rewritten to:

    (insert (prog1 "hello" (erase-buffer)))
It's not exactly AGI but still very cool.


This is not "hard-coded" as I would describe it. It is defined in `gv.el`:

    (gv-define-setter buffer-string (store)
  `(insert (prog1 ,store (erase-buffer))))
Unfortunately, it is marked obsolete since 29.1. The NEWS says:

* Many seldom-used generalized variables have been made obsolete. Emacs has a number of rather obscure generalized variables defined, that, for instance, allowed you to say things like:

    (setf (point-min) 4)
These never caught on and have been made obsolete. The form above, for instance, is the same as saying

    (narrow-to-region 4 (point-max))




Consider applying for YC's Fall 2026 batch! Applications are open till July 27.

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: