【问题标题】:Weird HyLang dot notation behavior奇怪的 HyLang 点符号行为
【发布时间】:2017-06-30 16:10:16
【问题描述】:

为什么以下工作:

(def session (sessionmaker))
(.configure session :bind engine)

...但是 (def session (.configure (sessionmaker) :bind engine)) 导致我的 Hy 应用程序抛出 NoneType TypeError?

【问题讨论】:

    标签: hy


    【解决方案1】:

    所以(sessionmaker) 制作了一个“会话”对象? (.configure (sessionmaker) :bind engine) 方法调用是否返回该会话对象?还是只是为了副作用?我怀疑是后者,只是返回None。您可能正在寻找doto 表单,它允许您配置一个对象,然后在最后返回它。所以代码是

    (def session (doto (sessionmaker) (.configure :bind engine)))
    

    如果您熟悉 Python,REPL 中的 $ hy --spy 选项对于了解 Hy 的编译方式非常有用。

    【讨论】:

    • 工作就像一个魅力,谢谢你的解释!
    猜你喜欢
    • 1970-01-01
    • 2015-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-03-05
    • 2013-08-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多