class QQuote
class for quark quotes
Attributes
body[RW]
pattern[RW]
Public Class Methods
new(p, b)
click to toggle source
# File lib/qtypes.rb, line 64 def initialize(p, b) @pattern = p @body = b end
Public Instance Methods
==(x)
click to toggle source
# File lib/qtypes.rb, line 84 def ==(x) if x.is_a? QQuote (@pattern == x.pattern) && (@body == x.body) else false end end
bind(bindings)
click to toggle source
takes a hash of var strings to quark items and recursively subs its body
# File lib/qtypes.rb, line 103 def bind bindings @body.map! do |x| if x.is_a? QQuote then x.bind bindings elsif x.is_a? QAtom then bindings[x.val] || x else x end end return self end
dup()
click to toggle source
# File lib/qtypes.rb, line 80 def dup Marshal.load(Marshal.dump(self)) end
pop()
click to toggle source
pops from quark body
# File lib/qtypes.rb, line 98 def pop @body.pop end
push(x)
click to toggle source
pushes to quote body
# File lib/qtypes.rb, line 93 def push x @body.push x end
qtype()
click to toggle source
# File lib/qtypes.rb, line 90 def qtype; :Quote end
to_s(n=nil)
click to toggle source
# File lib/qtypes.rb, line 69 def to_s(n=nil) return "[]" if @body.empty? and @pattern.empty? serialize = lambda do |arr| xs = n ? arr.first(n) : arr xs.map { |x| x.is_a?(QQuote) ? x.to_s(n) : x.to_s }.join(' ') + (n && arr.length > n ? ' ...' : '') end pattern_str = " #{serialize.call(@pattern)} |" if !@pattern.empty? body_str = " #{serialize.call(@body)} " if !@body.empty? "[#{pattern_str}#{body_str}]" end