Hello everyone,

I would like to know if Nim allows me to check if a procedure exists for a 
given type at compile time ?
    
    
    .
        # As a library author I define a type `Car`
        type
            Car = object
                speed: int
         
         proc default_drive(self: Car):
              echo "vroom"
         
         
         # A user of this library define a procedure `drive` on this `Car` type
         proc drive(self: Car):
             echo "VROOM !!"
        
        var car = Car()
        
        # Somewhere in my library, I want to check if the procedure `drive` 
exists on type `Car`
        # NB: The code below is pseudo code
        if prodecure_exists(Car, "drive"):
            car.drive()
        else:
            car.default_drive()
    
    
    Run

Have a nice day :)

Reply via email to