Hacker Newsnew | past | comments | ask | show | jobs | submitlogin
Emacs Lisp shorthands as namespacing system (andreyorst.gitlab.io)
102 points by gjvc on Nov 27, 2022 | hide | past | favorite | 21 comments


I don't like the conflation of "-" as both "word separator in the name" and "namespace". I prefer keeping the "/", so you would get "snu/lines" instead of "some-nice-string-utils/lines". Otherwise I think this article is great, and I don't see why more languages don't use this kind of system, instead of dumping all symbols in the imported namespace into the current namespace.


I went back and forth on this.

Using / has one major disadvantage. You can’t name macros w/stdin, w/stdout, w/file, etc.

It’s short for “with-“. It’s only a few characters, but it adds up.

Admittedly it’s more important in arc, where brevity is a feature, not a bug.

On the other hand, having a full separator for the namespace is worthwhile. One idea I toyed with is:

my-func@pkg

So the namespace is on the right, not the left.

But I decided this is even worse, even if it does match e.g. how we ssh into things.

Ultimately it’s hard to beat a global namespace with prefixing conventions.


I'm surprised Unison's approach hasn't caught on more widely. ISTR Joe Armstrong of Erlang was experimenting with something similar in a related domain,

https://joearms.github.io/published/2015-03-12-The_web_of_na...

https://news.ycombinator.com/item?id=2580383

(The OP is a very well written article btw, nice work!)


For me, Python's "from library import module as myname" is unbeatable. I like to choose my own namespaces and assign whatever bits of a lib to it as I feel like. It seems robust and flexible.


This usage is so idiomatic and ubiquitous that you can see "np." or "pd." or "plt." in just about any code and assume that the user is using Numpy or Pandas or Matplotlib.

Now that I think about it, I really should set up a "snippet" to type this for me:

  import matplotlib.pyplot as plt
  import numpy as np
  import pandas as pd


Importing a namespace under an alias exists in a few languages


Python really got that right. In Haskell, it’s similar:

  import qualified Foo.Bar as Baz


I prefer JavaScript's idiomatic approach:

  import anyNamespace from 'module.js'
  import { subModule } from 'module.js'
  import { subModule as anyName } from 'module.js'


the biggest problem with JS's is extremely incidental, but a total mess in practice. If you type from left to right it's impossible for auto-complete to help you with member names (since it can't know what module you're looking for!)


I work around this in two ways:

A) I type "import {} from 'module" first and then go back and add modules

or more often these days,

B) I let Copilot guess for me, which combined with my predictable file organization usually results in the right autocomplete.

Option A can be improved upon by writing a macro/template with slots in the correct order.


Does Python allow import symbol renaming? In R6RS Scheme I can do the following:

  (import (prefix (rename #;from (rnrs r5rs)
                                 (delay #;as eval-later)
                                 (force #;as eval-now))
                   r5rs:))
And from (rnrs r5rs) it will import delay as r5rs:eval-later and force as r5rs:eval-now.


By now they (some maintainers and some users) have a lot from a typical Common Lisp into Emacs Lisp re-engineered (incl. the Common Lisp Object System), but it is not 'officially allowed' to actually upgrade the language/runtime to it. Just libraries or forks...


I've been using https://github.com/Malabarba/Nameless for awhile now - it's functionally very similar to the new Emacs shorthands feature.


If you want to learn about CL packages and namespaces (namespaces are not packages). Take a look at https://gigamonkeys.com/book/programming-in-the-large-packag...


Somewhat unrelated but does anyone know how this website was made? I like the layout and have been wanting to start a blog for some time, this looks perfect.


This tool https://www.wappalyzer.com/ will tell you.


Won't tell you anything about the static site generator they use, or much else about the HTMl that's returned was made, even what program spit it out-- the information usually just isn't there :p

They've got a post on their workflow here: https://andreyorst.gitlab.io/posts/2022-10-16-my-blogging-se...


Yes, I expected to be corrected on this. Thank you.



Thank you a lot, exactly what I wanted to know :)


Right-click -> Show source




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

Search: