分享 Ruby + Clojure = Rouge

jiyinyiyong · October 15, 2012 · Last by unionx replied at April 08, 2014 · 4517 hits

没有 Clojure 社区可发,那就这儿吧.. 话说我一直 Ruby 就 Ruby 吧... 看样子是用 Clojure 的语法跑 Ruby,, https://github.com/unnali/rouge

; define a macro
(defmacro defn [name args & body]
  `(def ~name (fn ~name ~args ~@body)))

; call a Ruby method on Kernel (if the ruby namespace is referred)
(defn require [lib]
  (.require Kernel lib))

; call a Ruby method on an Array with a block argument
(defn reduce [f coll]
  (.inject coll | f))

; using Ruby's AMQP gem with an inline block
(.subscribe queue {:ack true} | [metadata payload]
  (puts (str "got a message: " payload))
  (.ack metadata))

; copied from core.clj and modified to work with our currently smaller core
(defmacro binding [bindings & body]
  (let [var-ize (fn [var-vals]
                  (.flatten
                    (map
                      (fn [pair]
                        (let [key (first pair)
                              val (second pair)]
                          [`(.name (var ~key)) val]))
                      (.each_slice var-vals 2))
                    1))]
  `(try
     (push-thread-bindings (hash-map ~@(var-ize bindings)))
     ~@body
     (finally
       (pop-thread-bindings)))))

用 Clojure 的语法跑 Ruby

你是说用 clojure 实现了个 ruby ?

#1 楼 @lidashuang Ruby 实现了 Clojure 的语法.. 的样子...

这个完全没道理啊,ruby 最强的就是它的语法这层皮

话说是有 Clojure 社区的,cnclojure,不过是 Google Group。

#3 楼 @fsword Lisp 天生就擅长写新语言。

#4 楼 @unionx 帝老师,我那还问你为什么对 Lisp 那么呢..

#3 楼 @fsword 换语法这招在 JS 已经被外国人玩烂了,, 期待 Ruby 加入 关于实用性的话等待高人评价...

#8 楼 @unionx .. 居然当时想着想着漏打了.. 算不算是执着?

#9 楼 @jiyinyiyong 不执著啊,我都去写 Java 了

#10 楼 @unionx 淹没在 Java 里了么... 我已经从 coffee 沦落回到 JS 很久了..

#11 楼 @jiyinyiyong 试试其他的 JS 语言吧,TypeScript 之类的~

#12 楼 @unionx 我公司目前前后端 CoffeeScript... 括号太多的语言就算了

#13 楼 @jiyinyiyong 哈哈哈哈,我也是这么觉得的

You need to Sign in before reply, if you don't have an account, please Sign up first.