unless i kept the language very simple, there are bound to be some inconsistencies in the syntax of oh-lang. there are some minor ones between declaring function-like things and calling them.
here are the different ways to declare function-like things:
here are the different ways to declare function-like things:
my_fn(args...): #return_instanceis declaring a standard function that returns an instance of type#return_instancem[args...]: #return_instanceis for declaring a subscript access overload in a class body, which will return an instance of#return_instance†fn[generic_args...](args...): #return_instanceis a generic function#my_type(args...): #my_typeis for declaring a constructor, which returns an instance of#my_type. usually this is seen as#m(args...): #minside a class body, since#mis shorthand for the class type.#my_type[generic_args...]: #another_typeis for declaring a class, which does not return an instance of#another_typebut uses it for a typedef#my_type[generic_args...](args...): #my_type[generic_args...]is for declaring a generic constructor, which returns a specified instance of#my_type
my_fn(args...)is calling a standard function that will return an instance of something (possiblynull)some_var[args...]is for calling a subscript access overload and will return an instancefn[generic_args...](args...)is calling a generic function, which will return an instance#my_type(args...)is for calling a constructor, which returns an instance of#my_type(or technically could be a result type)#my_type[generic_args...]is for specifying a generic typedef, which does not return an instance, but instead is a valid type designator. e.g.,my_array: #array[#f32].#my_type[generic_args...](args...)is for calling a generic constructor, which returns a specified instance of#my_type.
- i would have liked to see
#my_fn(...)and#my_type[...]both "return" types, but the first one returns an instance. this inconsistency is mostly for convenience of the type name to variable name correspondence. if you havesome_variable_nameas an argument of some random type, you can use#some_variable_name(...)as a constructor to build other instances of that same type, and not some other more confusing syntax likesome_variable_name(...). it would make me want to get rid of subscript access overloading, but being able to dosome_array[3]rather thansome_array at(3)is super engrained. i also wanted to avoidnewif possible, so#my_type(args...)seemed like the best way to go. fn[generic_args...](args...)could potentially be confused with(some_var[args...])(new_args...); i.e., if your subscript accessor returns a function, we'll likely require you to use the parenthetical version orsome_var[args...] fn(new_args...)to avoid confusion. the alternative is to make the grammar scope-aware, but that doesn't seem ideal.- types are not exactly first-class citizens in oh-lang. as a strongly-typed language, oh-lang needs to be able to say what the type of something is at compile time, so returning a type from a function (e.g.,
my_random_type[]: #type { if random() < 0.5 { #int } else { #f64 } }isn't possible. however, types are not flying economy either, since oh-lang offers things like type reflection.
Comments
Post a Comment