Clojure 语法问题回复:#^ [英] Clojure syntax question re: #^

查看:19
本文介绍了Clojure 语法问题回复:#^的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在 Rich Hickeys 蚂蚁游戏中,他有以下代码:

in Rich Hickeys ant game, he has the following code:

(import 
 '(java.awt Color Graphics Dimension)
 '(java.awt.image BufferedImage)
 '(javax.swing JPanel JFrame))

(defn fill-cell [#^Graphics g x y c]
  (doto g
    (.setColor c)
    (.fillRect (* x scale) (* y scale) scale scale)))

我无法在任何地方找到有关 #^ 在这种情况下的含义的文档,感谢任何帮助.

I can't find documentation anywhere for what #^ means in this context, any help appreciated.

推荐答案

#^ 是元数据阅读器宏的旧语法.clojure 1.2 中的语法已更改为 ^.请参阅 http://clojure.org/reader.在您的示例中, #^Graphics 表示 类型提示 出于性能原因使用.

The #^ is the old syntax for metadata reader macro. The syntax has changed to ^ in clojure 1.2. See http://clojure.org/reader. In your example, #^Graphics represents a type hint which is used for performance reasons.

这篇关于Clojure 语法问题回复:#^的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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