If you don't mind the eager evaluation, you can even do it without macros. This 
way of doing things tends to compose much better:
    
    
    type
      BranchPair[T] = object
        then, otherwise: T
    
    # This cannot be a template yet, buggy compiler...
    proc `!`*[T](a, b: T): BranchPair[T] {.inline.} = BranchPair[T](then: a, 
otherwise: b)
    
    template `?`*[T](cond: bool; p: BranchPair[T]): T =
      (if cond: p.then else: p.otherwise)
    
    echo(true ? 3 ! 4)
    

Reply via email to