Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

abstract class ElementBase(...) extends OOLAGHost { 

requiredEvaluations(typeDef)
requiredEvaluations(isSimpleType)
requiredEvaluations(if (hasPattern) patternValues)
requiredEvaluations(if (hasEnumeration) enumerationValues)

lazy valdef typeDef = typeDef_.value
LV('typeDef){ private lazy val typeDef_ = LV { // objectfunction LV constructs an OOLAGValue
....
// compute the type definition
....
}.value // take the value of the LV

}

In the above , you see the two lines associated with the typeDef attribute of ElementBase. The first obtains the value, if possible from the LV (lazy value) created by the associated private typeDef_. This is the common idiom, to have two lines together like thisyou see that def of 'typeDef' which defines it using this LV function. The LV function takes a symbol, and an expression, which is not evaluated. The computation is done exactly once, and cached internally to the OOLAG system. Hence, calling typeDef repeatedly just accesses the cache.

Use of 'def' above saves a per-object slot to hold a lazy val. However, for debug reasons, you may want the value to be apparent in the object. In that case the right idiom is:

  lazy val typeDef = LV('typeDef){ .... }.value

This will allow more convenient inspection of the typeDef value when debugging code.

Scala Note: I have no idea how one can do this with less syntax baggage in Scala. In Lisp this would be (defAttribute typeDef ... computation...), one line, one statement. This is my primary argument for why Scala needs Lisp-like macros, as defining forms like this cannot be created with Scala's supposedly powerful Domain-Specific-Language (DSL) capabilities.

...