gpt4 book ai didi

clojure - Clojure 中 let 和 let* 的区别

转载 作者:行者123 更新时间:2023-12-03 23:33:42 27 4
gpt4 key购买 nike

考虑以下宏:

(defmacro somemacro []
(list 'let ['somevar "Value"] 'somevar))

展开它会产生以下结果:
(macroexpand '(somemacro))

结果:
(let* [somevar "Value"] somevar)

我有两个关于 let* 的问题(带星号):
  • 这是什么意思? (特别是:它在某处有记录吗?)
  • 为什么宏没有用“正常”让展开? (即,不带星号。)两者都产生相同的结果(在我的实验中)。有反例吗?

  • 不幸的是,我找不到任何关于 let* 的“官方”文档,这就是我在这里问的原因。

    我已经考虑过的来源:
    (doc let*)  ; --> nil
    (source let*) ; --> source not found
  • https://clojuredocs.org/clojure.core --> 我看这里不让*
    (虽然有例如列表*)
  • https://clojuredocs.org/clojure.core/let --> 只提到过一次
    评论,这对我来说并不完全清楚:

    Nota Bene: let in Clojure is like let* in Scheme -- each init-expr has access to the preceding binding forms. (There is also a let*, but it is more or less let without destructuring, and in fact is the underlying implementation.)

  • LET versus LET* in Common Lisp
    --> 这个问题是关于普通的 lisp,但也许在 Clojure 中是一样的?
  • 本回答:https://stackoverflow.com/a/5084339/3398271

    In Clojure it basically means "foo* is like foo, but somehow different, and you probably want foo". In other words, it means that the author of that code couldn't come up with a better name for the second function, so they just slapped a star on it.


  • --> let 和 let* 也是这样吗?但如果是这样,问题仍然存在,究竟有什么区别?
  • What is the difference between let and let* in Scheme? --> 这在Clojure中是一样的吗?
  • 最佳答案

    let*是内部实现细节。 let是根据 let* 实现的宏. https://github.com/clojure/clojure/blob/clojure-1.7.0/src/clj/clojure/core.clj#L4301

    let添加参数 destructuringlet* .这是 xyz 的标准模式和 xyz*在 Clojure 中,使用 *版本未记录。一个异常(exception)是 list list* .

    关于clojure - Clojure 中 let 和 let* 的区别,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31661187/

    27 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com