Class: Upl::Functor

Inherits:
Object show all
Defined in:
lib/upl/functor.rb

Overview

Just an idea, not used yet.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(atom, args_or_arity) ⇒ Functor

Returns a new instance of Functor.



4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/upl/functor.rb', line 4

def initialize( atom, args_or_arity )
  @atom = atom

  case args_or_arity
  when Array
    @args = args_or_arity
    @arity = args.size
  when Integer
    @arity = args_or_arity
  else
    "dunno bout #{args_or_arity.inspect}"
  end
end

Instance Attribute Details

#atomObject (readonly)

Returns the value of attribute atom.



18
19
20
# File 'lib/upl/functor.rb', line 18

def atom
  @atom
end

Instance Method Details

#argsObject



19
# File 'lib/upl/functor.rb', line 19

def args; @args || [] end

#arityObject



20
# File 'lib/upl/functor.rb', line 20

def arity; @arity || args.size end

#functor_tObject

create a functor_t pointer

Raises:

  • (NotImplementedError)


23
24
25
# File 'lib/upl/functor.rb', line 23

def functor_t
  raise NotImplementedError
end

#predicate_tObject

create a predicate_t

Raises:

  • (NotImplementedError)


28
29
30
# File 'lib/upl/functor.rb', line 28

def predicate_t
  raise NotImplementedError
end

#pretty_print(pp) ⇒ Object



32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/upl/functor.rb', line 32

def pretty_print(pp)
  unless atom.to_sym == :','
    pp.text atom.to_s
    if arity > 0
      pp.text ?/
      pp.text arity.to_s
    end
  end

  if arity > 0
    pp.group 1, ?(, ?) do
      args.each_with_index do |ruby_term,i|
        ruby_term.pretty_print pp
        pp.text ?, if i < arity - 1
      end
    end
  end
end