2015-02-28 02:36:27 +03:00
|
|
|
require_relative "env"
|
2014-04-11 07:52:26 +04:00
|
|
|
|
2014-04-13 23:37:56 +04:00
|
|
|
class MalException < StandardError
|
|
|
|
attr_reader :data
|
|
|
|
def initialize(data)
|
|
|
|
@data = data
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2016-02-11 22:57:49 +03:00
|
|
|
class String # re-open and add seq
|
|
|
|
def seq()
|
|
|
|
return List.new self.split("")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
|
2014-04-11 05:34:29 +04:00
|
|
|
class List < Array
|
2014-04-13 23:37:56 +04:00
|
|
|
attr_accessor :meta
|
|
|
|
def conj(xs)
|
|
|
|
xs.each{|x| self.unshift(x)}
|
|
|
|
return self
|
|
|
|
end
|
2016-02-11 22:57:49 +03:00
|
|
|
def seq()
|
|
|
|
return self
|
|
|
|
end
|
2014-04-11 05:34:29 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Vector < Array
|
2014-04-13 23:37:56 +04:00
|
|
|
attr_accessor :meta
|
|
|
|
def conj(xs)
|
|
|
|
self.push(*xs)
|
|
|
|
return self
|
|
|
|
end
|
2016-02-11 22:57:49 +03:00
|
|
|
def seq()
|
|
|
|
return List.new self
|
|
|
|
end
|
2014-04-13 23:37:56 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Hash # re-open and add meta
|
|
|
|
attr_accessor :meta
|
2014-04-11 05:34:29 +04:00
|
|
|
end
|
2014-04-11 07:24:58 +04:00
|
|
|
|
2014-04-11 08:20:11 +04:00
|
|
|
def sequential?(obj)
|
|
|
|
return obj.is_a?(List) || obj.is_a?(Vector)
|
|
|
|
end
|
|
|
|
|
2014-04-14 00:27:34 +04:00
|
|
|
class Proc # re-open and add meta
|
2014-04-13 23:37:56 +04:00
|
|
|
attr_accessor :meta
|
2014-04-14 00:27:34 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
class Function < Proc
|
2014-04-11 07:52:26 +04:00
|
|
|
attr_accessor :ast
|
|
|
|
attr_accessor :env
|
|
|
|
attr_accessor :params
|
2014-04-11 08:27:50 +04:00
|
|
|
attr_accessor :is_macro
|
2014-04-11 07:52:26 +04:00
|
|
|
|
|
|
|
def initialize(ast=nil, env=nil, params=nil, &block)
|
|
|
|
super()
|
|
|
|
@ast = ast
|
|
|
|
@env = env
|
|
|
|
@params = params
|
2014-04-11 08:27:50 +04:00
|
|
|
@is_macro = false
|
2014-04-11 07:52:26 +04:00
|
|
|
end
|
|
|
|
|
|
|
|
def gen_env(args)
|
|
|
|
return Env.new(@env, @params, args)
|
|
|
|
end
|
|
|
|
end
|
2014-04-13 23:37:56 +04:00
|
|
|
|
|
|
|
class Atom
|
|
|
|
attr_accessor :meta
|
|
|
|
attr_accessor :val
|
|
|
|
def initialize(val)
|
|
|
|
@val = val
|
|
|
|
end
|
|
|
|
end
|