看过"黑客与画家"之后,你是不是对Lisp心动不已?然后翻了几页ACL(Ansi Common Lisp)又望而却步?叹息:如果有一天可以再.Net CLR 上写Lisp代码那就好了!这一天已经来了,这就是Clojure CLR.看语言转换矩阵, Clojure的寄生能力超强,这方面甚至超过javascript.在CLR上有一席之地不足为怪.
Error
16 The command "" D:\Code\clojure-clr-master\bin\4.0\Debug\Clojure.Compile.exe "
clojure.core clojure.core.protocols clojure.main clojure.set clojure.zip clojure.walk clojure.stacktrace clojure.template clojure.test clojure.test.tap clojure.test.junit clojure.pprint clojure.clr.io clojure.repl clojure.clr.shell clojure.string clojure.data
clojure.reflect" exited
with code 1. Clojure.Compile |
Clojure 1.4.1 user=> (+ 1 2) 3 user=> (println "hello world") hello world nil user=>
public class __Init__ { // Fields protected internal static Var const__0; protected internal static AFn const__1; protected internal static Var const__2; protected internal static object const__3; // Methods static __Init__() { try { Compiler.PushNS(); __static_ctor_helper_constants(); } finally { Var.popThreadBindings(); } } private static void __static_ctor_helper_constants() { const__0 = RT.var("clojure.core", "in-ns"); const__1 = Symbol.intern(null, "hello"); const__2 = RT.var("clojure.core", "println"); const__3 = 0x7ddL; } public static void Initialize() { ((IFn) const__0.getRawRoot()).invoke(const__1); ((IFn) new hello$loading__16463__auto____5()).invoke(); ((IFn) const__2.getRawRoot()).invoke("hello world", const__3); } }
user=> (System.Console/WriteLine "Now we use Console Writeline") Now we use Console Writeline nil ;;读写文件 user=> (def file (System.IO.StreamWriter. "test.txt")) #'user/file user=> (.WriteLine file "===Hello Clojure ===") nil user=> (.Close file) nil user=> (println (slurp "test.txt")) WARNING: (slurp f enc) is deprecated, use (slurp f :encoding enc). ===Hello Clojure === nil user=>
System.Net.WebClient webClient= new System.Net.WebClient(); byte[] bResponse = webClient.DownloadData("http://www.baidu.com"); Console.WriteLine(Encoding.UTF8.GetString(bResponse));
(import (System.Net WebClient)) (import (System.Text Encoding)) (.GetString Encoding/UTF8 (.DownloadData (WebClient.) "http://www.baidu.com"))
(ns hello) (import (System.Net WebClient)) (import (System.Text Encoding)) (defn getbaidu [] (.GetString Encoding/UTF8 (.DownloadData (WebClient.) "http://www.baidu.com")) )
[Serializable] public class hello$getbaidu__11 : AFunction { // Methods public override bool HasArity(int num1) { if (num1 != 0) { return false; } return true; } public override object invoke() { return Encoding.UTF8.GetString(new WebClient().DownloadData("http://www.baidu.com")); } }
user=> (System.Reflection.Assembly/Load "System.Windows.Forms, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089") #4.0.0.0, Culture=neutral, Public KeyToken=b77a5c561934e089> user=> (import (System.Windows.Forms MessageBox)) System.Windows.Forms.MessageBox user=> (MessageBox/Show "Hello world from clojure-clr!" "Clojure-CLR DialogBox") OK user=>