StanzaOrg / lbstanza-old

L.B. Stanza Programming Language
Other
216 stars 23 forks source link

Overloading the `complement` operator ? #185

Open callendorph opened 1 year ago

callendorph commented 1 year ago

From the docs , the not operator maps to the complement function. This function is defined in core.stanza as:

public defn complement (a:True|False) -> True|False

This makes it impossible to override the not operator. For instance:

    public defstruct AST : 
        name:String

    public defn complement (x:AST) -> AST : 
        AST(string-join(["not ", name(x)]))

... 

val a = AST("a")
val b = not a           <-- This will not compile

This generates:

Cannot call function complement of type True|False -> True|False with arguments of type (AST).

I does not seem like I can overload the complement function because it doesn't allow for defmethod style usage. Thoughts ?