1
1
mirror of https://github.com/kanaka/mal.git synced 2024-11-10 12:47:45 +03:00
mal/ruby/types.rb

76 lines
1.2 KiB
Ruby
Raw Normal View History

2015-02-28 02:36:27 +03:00
require_relative "env"
class MalException < StandardError
attr_reader :data
def initialize(data)
@data = data
end
end
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
attr_accessor :meta
def conj(xs)
xs.each{|x| self.unshift(x)}
return self
end
def seq()
return self
end
2014-04-11 05:34:29 +04:00
end
class Vector < Array
attr_accessor :meta
def conj(xs)
self.push(*xs)
return self
end
def seq()
return List.new self
end
end
class Hash # re-open and add meta
attr_accessor :meta
2014-04-11 05:34:29 +04:00
end
2014-04-11 08:20:11 +04:00
def sequential?(obj)
return obj.is_a?(List) || obj.is_a?(Vector)
end
class Proc # re-open and add meta
attr_accessor :meta
end
class Function < Proc
attr_accessor :ast
attr_accessor :env
attr_accessor :params
2014-04-11 08:27:50 +04:00
attr_accessor :is_macro
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
end
def gen_env(args)
return Env.new(@env, @params, args)
end
end
class Atom
attr_accessor :meta
attr_accessor :val
def initialize(val)
@val = val
end
end