# defimpl Implement a protocol's methods for a specific type. ## Syntax
defimpl TypeName ProtocolName {
    method-name { ||
        # $self is the instance
    }
    method-with-args {|arg1|
        # $self and $arg1 available
    }
}
## Examples
defprotocol Showable { show }
deftype Point %{ x %{} y %{} }

defimpl Point Showable {
    show {||
        "Point($self~x, $self~y)"
    }
}

set p [Point 10 20]
echo [$p show]    # Point(10, 20)
defimpl Point Showable {
    show {|| "($self~x, $self~y)" }
    format {|prefix|
        "$prefix: ($self~x, $self~y)"
    }
}

echo [$p format "=>"]   # =>: (10, 20)
## Notes - `$self` refers to the instance inside method bodies - Use `||` for zero-param methods - Can implement protocols for types defined in other files - Child types inherit parent implementations (can override) - Method bodies are full blocks with multiple statements ## See Also `defprotocol`, `deftype`, `defmethod`, `satisfies`