[英]i need the steps to run a code in clojure language contains GUI in java
i have a big problem my doctor want form me to make calculator using new language(clojure)but i don't know anything about it i read some information from www.clojure.org but i still have a problem how to save the code in a file to run it another time and i need the path how to connect java to clojure i found this code : 我有一个大问题,我的医生想让我使用新的语言(clojure)来制作计算器,但我对此一无所知,但我从www.clojure.org上读取了一些信息,但是如何保存代码仍存在问题一个文件再次运行它,我需要如何将java连接到clojure的路径,我发现此代码:
(ns rayne.main
(:gen-class)
(:import (javax.swing JFrame JTextField JButton JOptionPane)
(java.awt.event ActionListener)
(java.awt GridLayout)))
(def numbers (ref []))
(def times-clicked (ref 0))
(defn calc [nseq op]
(let [n1 (first nseq)
n2 (last nseq)]
(cond
(= op "+") (+ n1 n2)
(= op "*") (* n1 n2)
(= op "-") (- n2 n1)
(= op "/") (/ n1 n2))))
(defn add-op-button [op text button]
(.addActionListener button
(proxy [ActionListener] []
(actionPerformed [e]
(dosync
(ref-set times-clicked (inc @times-clicked))
(if (= @times-clicked 2)
(do
(let [result (.toString (calc @numbers op))
result2 (read-string result)]
(.setText text result)
(ref-set numbers [])
(ref-set times-clicked 0)))
(do
(ref-set numbers (conj @numbers (read-string (.getText text))))
(.setText text ""))))))))
(defn -main []
(let [frame (JFrame. "Calculator")
add-button (JButton. "+")
sub-button (JButton. "-")
mul-button (JButton. "*")
div-button (JButton. "/")
clr-button (JButton. "Clear")
text-field (JTextField.)]
(add-op-button "+" text-field add-button)
(add-op-button "-" text-field sub-button)
(add-op-button "*" text-field mul-button)
(add-op-button "/" text-field div-button)
(doto frame
(.setLayout (GridLayout. 1 5))
(.add text-field)
(.add add-button)
(.add sub-button)
(.add mul-button)
(.add div-button)
(.setSize 500 100)
(.setVisible true))))
so when i try to test it i don't know how it work . 因此,当我尝试对其进行测试时,我不知道它是如何工作的。 please i need some one to help me in this problem and send me a link to install a clojure program to execute such a file.
请我需要一些人来帮助我解决这个问题,并向我发送链接以安装clojure程序来执行这样的文件。 thank's for all
谢谢大家
Sounds like a great reason to lean a fun new language. 听起来这是学习有趣的新语言的重要原因。
for getting started with new clojure pojects the leiningen tool can get you to the point of compiling and running code very quickly. 为了开始使用新的Clojure对象, leiningen工具可以使您快速地编译和运行代码。 (i'm assuming mac or linux here)
(我在这里假设是Mac或Linux)
Leiningen can also start a repl for you which will speed up you iterations and integrates well (through slime/swank) with emacs. Leiningen还可以为您启动一个repl,它将加快您的迭代速度,并与emacs很好地集成(通过粘液/ swank)。
Clojure.org has a nice section called Getting Started that is about ... getting started. Clojure.org有一个不错的部分,称为“ 入门” ,它与... 入门有关。 From getting the clojure zip file to debugging and profiling.
从获取clojure zip文件到调试和配置文件。 Very, very basic.
非常非常基本。
Also has links to more advanced resources. 还具有指向更高级资源的链接。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.