Araq/Nimrod — Issue #75: Macro for constructors
Author: Tass
Created: 2011-12-17 12:34:53+00:00
State: open

Gracefully handle struct constructors

proc newLanguageModel(order: int, charBased: bool): TLanguageModel =
result.model = initTable[string, float](32)
result.order = order
result.charBased = charBased

so you can express them as in

constructor(type: TLanguageModel, model: initTable[string, float](32), order, charBased):
# execute this block after all the above assignments are done

Which generates either

new(var model: TLanguageModel, order: int, charBased: bool)

or

newLanguageModel(order: int, charBased: bool)