为什么不以def的形式破坏? [英] Why no destructing in def form?

查看:180
本文介绍了为什么不以def的形式破坏?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

让窗体(这里是Clojure),我可以做一些类似于

 (do-something-with uv))

其中 svd 返回一个长度为三的列表。这是一个非常自然的事情,为什么不是我们没有我们没有

 (def [ usv](svd A))

及其各种一般化作为<$ c $的默认行为c> def form?我不明白这会干扰 def 已经在做的任何事情。能理解Lisp或Clojure的Zen的人可以解释为什么 def 不支持与 一样强大的绑定>

解决方案 c是编译器级别的特殊形式:它使一个Var。在解构可用之前, def 必须可用且可用。你看到类似于 let * 的东西,这是一个不支持解构的编译器原语:然后在 clojure / core.clj 该语言终于足够强大,足以提供具有解构的版本 let ,作为 let *

如果你愿意的话,你可以编写一个可以为你做这个的宏(比如 def + )。就我个人而言,我认为它有点粗俗,不会使用它,但使用Lisp意味着要使用适合您的语言。


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?

解决方案

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.

这篇关于为什么不以def的形式破坏?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆