proc p(x: int, xIsSet: bool) = ...
    

or smth like
    
    
    type IntOrNil = object
      x: int
      isSet: bool
    
    proc p(x: IntOrNil) = (if x.isSet: echo x.x else: #[ something else ]# 
discard)
    
    # additional procs may be added for such a type
    proc `$`(x: IntOrNil): string = (if x.isSet: $x else: "nil")
    converter x(x: IntOrNil): int =
      if x.isSet:
        return x.x
      else:
        raise newException(ValueError,"int to nil conversion")
    
    # usage
    p(IntOrNil(x: 5, isSet: false))
    
    var v = IntOrNil(x: 5, isSet: true)
    echo v+2
    
    v.isSet = false
    try:
      echo v+2
    except ValueError:
      echo "v not set!"
    # or so:
    echo (try: $(v+2) except: "v not set!")
    

Like in most other languages.

Yet you can search github for "nim maybe" and the like queries, there were some 
libs.

Reply via email to