Class: Clojure::Runtime

Inherits:
Object
  • Object
show all
Defined in:
lib/clojure/runtime.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeRuntime

Returns a new instance of Runtime.



3
4
5
# File 'lib/clojure/runtime.rb', line 3

def initialize
  @namespaces = {}
end

Instance Attribute Details

#namespacesObject (readonly)

Returns the value of attribute namespaces.



7
8
9
# File 'lib/clojure/runtime.rb', line 7

def namespaces
  @namespaces
end

Instance Method Details

#include(lib) ⇒ Object



13
14
15
# File 'lib/clojure/runtime.rb', line 13

def include(lib)
  @namespaces[lib.name.downcase.gsub("::", ".").to_sym] = lib
end

#load(filename) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/clojure/runtime.rb', line 17

def load(filename)
  ns = Clojure::Namespace.new(self)
  source = open(filename).read
  ast = Clojure::Reader.new(source).ast
  ast.each { |form| ns.evaluate form }
  ns_name = ns["*ns*"]
  @namespaces[ns_name.to_sym] = namespace(ns_name).merge(ns)
end

#namespace(name) ⇒ Object



9
10
11
# File 'lib/clojure/runtime.rb', line 9

def namespace(name)
  @namespaces[name.to_sym] ||= Clojure::Namespace.new(self)
end

#read(ns_name, source) ⇒ Object



26
27
28
29
30
# File 'lib/clojure/runtime.rb', line 26

def read(ns_name, source)
  ast = Clojure::Reader.new(source).ast
  ns = namespace ns_name.to_sym
  ast.map { |form| ns.evaluate form }.last
end