Class: Campa::Lisp::Cond

Inherits:
Object
  • Object
show all
Defined in:
lib/campa/lisp/cond.rb

Constant Summary collapse

FALSEY =
[false, nil].freeze

Instance Method Summary collapse

Constructor Details

#initializeCond

Returns a new instance of Cond.



6
7
8
9
# File 'lib/campa/lisp/cond.rb', line 6

def initialize
  @printer = Printer.new
  @evaler = Evaler.new
end

Instance Method Details

#call(*conditions, env:) ⇒ Object



15
16
17
18
19
20
21
22
23
# File 'lib/campa/lisp/cond.rb', line 15

def call(*conditions, env:)
  found = conditions.find do |cond|
    raise illegal_argument(cond) if !cond.is_a?(List)

    !FALSEY.include? evaler.call(cond.head, env)
  end

  eval_result(found, env)
end

#macro?Boolean

Returns:

  • (Boolean)


11
12
13
# File 'lib/campa/lisp/cond.rb', line 11

def macro?
  true
end