Module: SchemeBooleans

Includes:
SchemeBooleansHelper
Included in:
Tokenizer
Defined in:
lib/lisp/interpreter/core/boolean.rb

Overview

Scheme booleans module

Instance Method Summary collapse

Methods included from SchemeBooleansHelper

#if_helper, #if_idx_helper

Instance Method Details

#equal?(other) ⇒ Boolean

Returns:

  • (Boolean)


25
26
27
28
# File 'lib/lisp/interpreter/core/boolean.rb', line 25

def equal?(other)
  raise arg_err_build 2, other.size if other.size != 2
  other[0].to_s == other[1].to_s ? '#t' : '#f'
end

#if(other) ⇒ Object



37
38
39
40
41
42
43
# File 'lib/lisp/interpreter/core/boolean.rb', line 37

def if(other)
  raise arg_err_build 3, 0 if other.empty?
  expr, other = find_next_value other
  raise arg_err_build 3, other.size + 1 if other.size < 2
  res = if_helper expr, other
  (find_next_value res)[0]
end

#not(other) ⇒ Object



30
31
32
33
34
35
# File 'lib/lisp/interpreter/core/boolean.rb', line 30

def not(other)
  raise arg_err_build 1, other.size if other.size != 1
  valid = check_for_bool other[0]
  raise type_err '<boolean>', other[0].type unless valid
  other[0] == '#t' ? '#f' : '#t'
end