Module: Nydp::Helper

Instance Method Summary collapse

Methods included from Converter

#n2r, #r2n, #rubify

Instance Method Details

#cons(a = nil, b = nil) ⇒ Object



79
80
81
# File 'lib/nydp/helper.rb', line 79

def cons a=nil, b=nil
  Nydp::Pair.new a, b
end

#list(*args) ⇒ Object



83
84
85
# File 'lib/nydp/helper.rb', line 83

def list *args
  Nydp::Pair.from_list args
end

#literal?(expr) ⇒ Boolean

Returns:

  • (Boolean)


91
92
93
94
95
96
97
98
99
100
# File 'lib/nydp/helper.rb', line 91

def literal? expr
  case expr
  # when String, Float, Integer, Integer, Symbol, Nydp::Truth, Nydp::Nil
  # when String, Float, Integer, Integer, Symbol, Nydp::Truth, NilClass
  when String, Float, Integer, Integer, Symbol, TrueClass, FalseClass, NilClass
    true
  else
    false
  end
end

#pair?(expr) ⇒ Boolean

Returns:

  • (Boolean)


75
76
77
# File 'lib/nydp/helper.rb', line 75

def pair? expr
  expr.is_a?(Nydp::Pair)
end

#sig(klass) ⇒ Object



55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/nydp/helper.rb', line 55

def sig klass
  case klass
  when Nydp::Symbol              ; "SYM"
  when Nydp::ContextSymbol       ; "LEX"
  when Nydp::Literal             ; "LIT"
  when Nydp::FunctionInvocation  ; "NVK"
  when Nydp::Invocation::Base    ; "NVB"
  when Nydp::InterpretedFunction ; "IFN"
  when Nydp::Cond                ; "CND"
  when Nydp::CondBase            ; "CND"
  when Nydp::Assignment          ; "ASN"
  else ; raise "no sig for #{klass.class.name}"
  end
end

#sym(name, ns) ⇒ Object



87
88
89
# File 'lib/nydp/helper.rb', line 87

def sym name, ns
  name.to_s.to_sym
end

#sym?(expr, name) ⇒ Boolean

Returns:

  • (Boolean)


70
71
72
73
# File 'lib/nydp/helper.rb', line 70

def sym? expr, name
  # expr.is_a?(Nydp::Symbol) && (expr.is? name)
  expr.is_a?(::Symbol) && (expr == name.to_sym)
end