Create a gist now

Instantly share code, notes, and snippets.

# igrigorik { ~ } > rvm use jruby
# Using /Users/igrigorik/.rvm/gems/jruby-1.6.2
# igrigorik { ~ } > gem install mvn:org.clojure:clojure
# Successfully installed mvn:org.clojure:clojure-1.3.0.b.1-java
# 1 gem installed
require 'rubygems'
require 'java'
require 'maven/org.clojure/clojure'
# Clojure Atoms in Jruby!
java_import 'clojure.lang.Atom'
p Atom.new nil # => #<Java::ClojureLang::Atom:0x536b98c3>
# Execute some arbitrary Clojure code
%w[
clojure.lang.Compiler
java.io.ByteArrayInputStream
java.io.BufferedReader
java.io.InputStreamReader
].each {|c| java_import c }
def clojure_execute(code)
java_string = java.lang.String.new(code + "\n")
stream = ByteArrayInputStream.new(java_string.getBytes)
rdr = BufferedReader.new(InputStreamReader.new(stream))
Compiler.load(rdr)
end
p clojure_execute('(first [1 2 3 4])') # => 1
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment