Class: Skeem::SkmCondition
- Inherits:
-
SkmMultiExpression
- Object
- Struct
- SkmElement
- SkmExpression
- SkmMultiExpression
- Skeem::SkmCondition
- Defined in:
- lib/skeem/s_expr_nodes.rb
Overview
class
Instance Attribute Summary collapse
-
#alternate ⇒ Object
readonly
Returns the value of attribute alternate.
-
#consequent ⇒ Object
readonly
Returns the value of attribute consequent.
-
#test ⇒ Object
readonly
Returns the value of attribute test.
Attributes inherited from SkmElement
Instance Method Summary collapse
- #associations ⇒ Object
- #evaluate(aRuntime) ⇒ Object
-
#initialize(aPosition, aTest, aConsequent, anAlternate) ⇒ SkmCondition
constructor
A new instance of SkmCondition.
- #inspect ⇒ Object
- #quasiquote(aRuntime) ⇒ Object
Methods inherited from SkmMultiExpression
Methods inherited from SkmElement
#accept, #boolean?, #bound!, #callable?, #char?, #complex?, #done!, #eqv?, #integer?, #list?, #null?, #number?, #pair?, #procedure?, #quoted!, #rational?, #real?, #skm_eq?, #skm_equal?, #string?, #symbol?, #unquoted!, #vector?, #verbatim?
Constructor Details
#initialize(aPosition, aTest, aConsequent, anAlternate) ⇒ SkmCondition
Returns a new instance of SkmCondition.
206 207 208 209 210 211 |
# File 'lib/skeem/s_expr_nodes.rb', line 206 def initialize(aPosition, aTest, aConsequent, anAlternate) super(aPosition) @test = aTest @consequent = aConsequent @alternate = anAlternate end |
Instance Attribute Details
#alternate ⇒ Object (readonly)
Returns the value of attribute alternate.
204 205 206 |
# File 'lib/skeem/s_expr_nodes.rb', line 204 def alternate @alternate end |
#consequent ⇒ Object (readonly)
Returns the value of attribute consequent.
203 204 205 |
# File 'lib/skeem/s_expr_nodes.rb', line 203 def consequent @consequent end |
#test ⇒ Object (readonly)
Returns the value of attribute test.
202 203 204 |
# File 'lib/skeem/s_expr_nodes.rb', line 202 def test @test end |
Instance Method Details
#associations ⇒ Object
240 241 242 |
# File 'lib/skeem/s_expr_nodes.rb', line 240 def associations %i[test consequent alternate] end |
#evaluate(aRuntime) ⇒ Object
213 214 215 216 217 218 219 220 221 222 223 |
# File 'lib/skeem/s_expr_nodes.rb', line 213 def evaluate(aRuntime) test_result = test.evaluate(aRuntime) condition_result = nil if test_result.boolean? && test_result.value == false # Only #f is considered as false, everything else is true condition_result = alternate ? alternate.evaluate(aRuntime) : SkmUndefined.instance else condition_result = consequent.evaluate(aRuntime) end condition_result end |
#inspect ⇒ Object
233 234 235 236 237 238 |
# File 'lib/skeem/s_expr_nodes.rb', line 233 def inspect result = "#{inspect_prefix}@test #{test.inspect}, " result << "@consequent #{consequent.inspect}, " result << "@alternate #{alternate.inspect}#{inspect_suffix}" result end |
#quasiquote(aRuntime) ⇒ Object
225 226 227 228 229 230 231 |
# File 'lib/skeem/s_expr_nodes.rb', line 225 def quasiquote(aRuntime) quasi_test = test.quasiquote(aRuntime) quasi_consequent = consequent.quasiquote(aRuntime) quasi_alternate = alternate.quasiquote(aRuntime) self.class.new(position, quasi_test, quasi_consequent, quasi_alternate) end |