Module: Nydp::Helper

Instance Method Summary collapse

Methods included from Converter

#n2r, #r2n

Instance Method Details

#cons(a, b = Nydp::NIL) ⇒ Object



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

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

#list(*args) ⇒ Object



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

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

#literal?(expr) ⇒ Boolean

Returns:

  • (Boolean)


84
85
86
87
88
89
90
91
# File 'lib/nydp/helper.rb', line 84

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

#pair?(expr) ⇒ Boolean

Returns:

  • (Boolean)


68
69
70
# File 'lib/nydp/helper.rb', line 68

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

#sig(klass) ⇒ Object



49
50
51
52
53
54
55
56
57
58
59
60
61
62
# File 'lib/nydp/helper.rb', line 49

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



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

def sym name, ns
  Nydp::Symbol.mk name, ns
end

#sym?(expr, name) ⇒ Boolean

Returns:

  • (Boolean)


64
65
66
# File 'lib/nydp/helper.rb', line 64

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