top | item 33938688

(no title)

JonathanMerklin | 3 years ago

Yeah, I've used it in Haskell for ignored variables, holes, type wildcards, etc.

Another interesting little rabbit hole that this little conversation led me to: In the Chrome (and Firefox) developer tools, the variable for the previous output is "$_", which I imagine that is the case because of how common it was to assign the main export of the Underscore.js library to "_" (and in the days before a lot of websites would mostly e.g. have their site's code in a webpack-induced closure, they would e.g. grab underscore (or lodash, in those times?) from a CDN and pollute the global scope).

Since _ is a valid identifier, it also turns out that in Node.js's REPL, it warns you when you clobber _, but (weirdly) not if the clobbering is with a block-scoped declaration.

  $ node
  Welcome to Node.js v18.12.1.
    Type ".help" for more information.
  > "asdf"
  'asdf'
  > _
  'asdf'
  > var _ = 1
  Expression assignment to _ now disabled.
  undefined
  > "asdf"
  'asdf'
  > _
  1

  $ node
  Welcome to Node.js v18.12.1.
  Type ".help" for more information.
  > const _  = 1
  undefined
  > _
  1
  > "asdf"
  'asdf'
  > _
  1
And obviously, there's no warning for assigning to it outside of the REPL (`node -e "var _ = 2;"`), which makes obvious sense to me.

discuss

order

No comments yet.