Why no destructing in def form?

后端 未结 4 2105
北恋
北恋 2021-02-18 20:10

In a let form (Clojure here) I can doing something like

(let [[u s v] (svd A)] 
   (do-something-with u v))

where svd

4条回答
  •  北恋
    北恋 (楼主)
    2021-02-18 21:04

    def is a special form at the compiler level: it makes a Var. def has to be available and usable before destructuring is available. You see something similar with let*, a compiler primitive that supports no destructuring: then after several thousand lines in clojure/core.clj the language is finally powerful enough to provide a version of let with destructuring, as a macro on top of let*.

    If you want, you can write a macro (say, def+) that does this for you. Personally I think it's kinda gross and wouldn't use it, but using a Lisp means getting to use a language that suits you personally.

提交回复
热议问题