class Clojure::Namespace

Constants

SPECIAL

calls woth postponed evaluation of expression

Attributes

runtime[R]

Public Class Methods

new(runtime) click to toggle source

Clojure’s ns | evaluation context | class

# File lib/clojure/namespace.rb, line 5
def initialize(runtime)
  @runtime = runtime
end

Public Instance Methods

evaluate(form) click to toggle source
# File lib/clojure/namespace.rb, line 14
def evaluate(form)
  case form
  when Array
    form_eval form
  when String
    resolve form
  else
    form
  end
end

Private Instance Methods

form_eval(form) click to toggle source
# File lib/clojure/namespace.rb, line 42
def form_eval(form)
  head, *expressions = form
  fn = case head
       when Array
         form_eval head
       when Symbol
         # dirty keyword IFn
         -> (_ctx, args) { args[0][head] }
       else
         resolve head
       end
  raise Exception, "Function #{head} not defined" unless fn
  args = if head.is_a?(String) && SPECIAL.include?(head)
           expressions
         else
           expressions.map { |f| evaluate f }
         end
  fn.call self, args
end
resolve(symbol) click to toggle source
# File lib/clojure/namespace.rb, line 27
def resolve(symbol)
  n, ns = symbol.split('/').reverse
  i = self[ns] || self[n] || Clojure::Core[symbol] || raise("Can't resolve #{symbol}.")
  case i
  when Clojure::Alias
    if ns
      i.lookup()[n]
    else
      i.lookup()
    end
  else
    i
  end
end