Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Initial commit

  • Loading branch information...
commit d9e43cede7b851fd81b439dce8549028c0d748ea 0 parents
@daveray authored
4 .gitignore
@@ -0,0 +1,4 @@
+*.gem
+*.swp
+*.swo
+.DS_Store
16 familiar.gemspec
@@ -0,0 +1,16 @@
+Gem::Specification.new do |s|
+ s.name = 'familiar'
+ s.version = '0.0.0'
+ s.date = '2011-10-07'
+ s.summary = "Hey, this is familiar!"
+ s.description = "Clojure RT for Ruby"
+ s.authors = ["Dave Ray"]
+ s.email = 'daveray@gmail.com'
+ s.files = ["lib/familiar.rb",
+ "lib/familiar/fn.rb",
+ "lib/familiar/atom.rb",
+ "lib/familiar/ref.rb",
+ "lib/familiar/seq.rb",
+ "lib/clojure-1.3.0.jar"]
+ s.homepage = 'http://rubygems.org/gems/familiar'
+end
BIN  lib/clojure-1.3.0.jar
Binary file not shown
34 lib/familiar.rb
@@ -0,0 +1,34 @@
+require "java"
+require "clojure-1.3.0.jar"
+
+require 'familiar/fn'
+require 'familiar/atom'
+require 'familiar/ref'
+require 'familiar/seq'
+
+module Familiar
+
+ def self.future(&code)
+ Java::clojure.lang.Agent.soloExecutor.submit(Callable.new(code))
+ end
+
+ def self.print(v)
+ puts(Java::clojure.lang.RT.print_string(v))
+ end
+
+
+ def self.hash_map(*args)
+ Java::clojure.lang.RT.map(*args)
+ end
+
+ def self.hash_set(*args)
+ Java::clojure.lang.RT.set(*args)
+ end
+
+ def self.vector(*args)
+ Java::clojure.lang.RT.vector(*args)
+ end
+
+end
+
+
16 lib/familiar/atom.rb
@@ -0,0 +1,16 @@
+module Familiar
+
+ def self.atom(v)
+ Java::clojure.lang.Atom.new v
+ end
+
+ class Java::ClojureLang::Atom
+ def swap!(&code)
+ swap(Familiar.fn(code))
+ end
+ def reset!(v)
+ reset(v)
+ end
+ end
+
+end
28 lib/familiar/fn.rb
@@ -0,0 +1,28 @@
+module Familiar
+
+ class Callable
+ include Java::java.util.concurrent.Callable
+ def initialize(callable)
+ @callable = callable
+ end
+
+ def call
+ @callable.call
+ end
+ end
+
+ class Fn < Java::clojure.lang.AFn
+ def initialize &block
+ @block = block
+ end
+
+ def invoke(*args)
+ @block.call *args
+ end
+ end
+
+ def self.fn(p)
+ Fn.new &p
+ end
+
+end
12 lib/familiar/ref.rb
@@ -0,0 +1,12 @@
+module Familiar
+
+ def self.ref(v)
+ Java::clojure.lang.Ref.new v
+ end
+
+ def self.dosync(&code)
+ Java::clojure.lang.LockingTransaction.runInTransaction(Callable.new(code))
+ end
+
+
+end
16 lib/familiar/seq.rb
@@ -0,0 +1,16 @@
+module Familiar
+
+ def self.seq(coll)
+ Java::clojure.lang.RT.seq(coll)
+ end
+ def self.first(coll)
+ Java::clojure.lang.RT.first(coll)
+ end
+ def self.rest(coll)
+ Java::clojure.lang.RT.more(coll)
+ end
+ def self.next(coll)
+ Java::clojure.lang.RT.next(coll)
+ end
+
+end
Please sign in to comment.
Something went wrong with that request. Please try again.