Alex Rivera | Logout

Why no destructing in def form?

Asked 2011-11-19T21:03:48.400
21

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

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

where svd returns a list of length three. This is a very natural sort of thing to do, so why isn't that we don't we have

(def [u s v] (svd A))

and its various generalizations as the default behavior of the def form? I don't see how this would interfere with anything that def is already doing. Can someone who understands the Zen of Lisp or Clojure explain why def does not support binding (with destructuring) as powerful as let?

Edit
Report

1 Answer

2

def is basically the constructor for Vars. The first argument is the symbol that names the Var. It takes that symbol and returns a Var for that symbol. Destructuring would change these semantics.

You could write a macro that does it, though.

answered 2011-11-19T21:19:05.230

Your Answer