Class: Skeem::SkmConditional
- Inherits:
-
SkmMultiExpression
- Object
- Struct
- SkmElement
- SkmExpression
- SkmMultiExpression
- Skeem::SkmConditional
- Defined in:
- lib/skeem/s_expr_nodes.rb
Overview
class
Instance Attribute Summary collapse
-
#alternate ⇒ Object
readonly
Returns the value of attribute alternate.
-
#clauses ⇒ Object
readonly
An array of couples [test, sequence].
Attributes inherited from SkmElement
Instance Method Summary collapse
- #evaluate(aRuntime) ⇒ Object
-
#initialize(aPosition, theClauses, anAlternate) ⇒ SkmConditional
constructor
A new instance of SkmConditional.
- #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, theClauses, anAlternate) ⇒ SkmConditional
Returns a new instance of SkmConditional.
250 251 252 253 254 |
# File 'lib/skeem/s_expr_nodes.rb', line 250 def initialize(aPosition, theClauses, anAlternate) super(aPosition) @clauses = theClauses @alternate = anAlternate end |
Instance Attribute Details
#alternate ⇒ Object (readonly)
Returns the value of attribute alternate.
248 249 250 |
# File 'lib/skeem/s_expr_nodes.rb', line 248 def alternate @alternate end |
#clauses ⇒ Object (readonly)
An array of couples [test, sequence]
247 248 249 |
# File 'lib/skeem/s_expr_nodes.rb', line 247 def clauses @clauses end |
Instance Method Details
#evaluate(aRuntime) ⇒ Object
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 |
# File 'lib/skeem/s_expr_nodes.rb', line 256 def evaluate(aRuntime) clause_matching = false result = nil clauses.each do |(test, consequent)| test_result = test.evaluate(aRuntime) next if test_result.boolean? && test_result.value == false clause_matching = true result = consequent.evaluate(aRuntime) break end unless clause_matching result = alternate ? alternate.evaluate(aRuntime) : SkmUndefined.instance end result end |
#inspect ⇒ Object
287 288 289 290 291 292 293 294 295 |
# File 'lib/skeem/s_expr_nodes.rb', line 287 def inspect result = "#{inspect_prefix}@test #{test.inspect} , " result << "@clauses \n" clauses.each do |(test, consequent)| result << ' ' << test.inspect << ' ' << consequent.inspect << "\n" end result << "@alternate #{alternate.inspect}#{inspect_suffix}" result end |
#quasiquote(aRuntime) ⇒ Object
276 277 278 279 280 281 282 283 284 285 |
# File 'lib/skeem/s_expr_nodes.rb', line 276 def quasiquote(aRuntime) quasi_clauses = clauses.map do |(test, consequent)| test_qq = test.quasiquote(aRuntime) consequent_qq = consequent.quasiquote(aRuntime) [test_qq, consequent_qq] end quasi_alternate = alternate&.quasiquote(aRuntime) self.class.new(position, quasi_clauses, quasi_alternate) end |