r/ProgrammingLanguages • • Jun 25 '26

Is letting call syntax determine function priority a bad idea?

Hi everyone. I am continuing my work on DinoCode, my interpreted (untyped) language, and I want to share a hidden dispatch mechanic that I implemented too hastily while coding the compiler for my university thesis. This feature isn't documented yet because I was already regretting it while writing the documentation haha, but I finally need to decide what to do with it. In DinoCode, functions are first-class citizens, so shadowing a native function is completely possible. The language supports two different call syntaxes:

Classic parenthesis calls like

result = add(5 10)
print("Hello")

and a dollar syntax like

result = $(add 5 10)
print "Hello"   # Statement-level calls are equivalent to a dollar call

Because it was incredibly easy for me to distinguish between these two call types during the parsing and compilation phase, I impulsively decided to tie the syntax directly to identifier dispatch priority to resolve name collisions between native built-ins and user-defined functions.

The mechanic shifts dispatch priority entirely at compile time (it has zero impact on runtime execution engine performance since everything is resolved during compilation). The explicit call syntax with parentheses func(args) prioritizes native functions (falling back to user functions only if no native match exists). On the other hand, the dollar syntax prioritizes user functions known at compile time (falling back to natives only if no user match is found):

# Override print function
:print text
    # Not recursive, prioritizes the native print
    print("Log: " text)

print "Starting..."  # Outputs: "Log: Starting..."

# Regardless of the user override, the native print is invoked
print("Hello")        # Outputs: "Hello"

This way, native functions are always accessible even if shadowed by the user, simply by using the classical syntax. That was the idea I had while coding the compiler back then. However, analyzing it more closely, this behavior can easily turn into total chaos where the syntax you choose for your functions becomes more than just an aesthetic preference.

I feel that making both syntaxes completely equivalent is the right choice for DinoCode's predictability. However, before removing it, since it is currently fully implemented and I am preparing a minor version that introduces improvements and fixes, I would love to know if anyone sees a legitimate pragmatic benefit to keeping this syntactic divide or if it is just a footgun waiting to happen

3 Upvotes

26 comments sorted by

View all comments

Show parent comment

2

u/AverageHot2647 Jun 25 '26

If I understand correctly what you’re going for, using brackets to delimit expressions would be more conventional and still effective at resolving ambiguity, e.g.

// Instead of
result = $(add 42 $(multiply 3 4))

// This
result = (add 42 (multiply 3 4))

// Or even
result = add 42 (multiply 3 4)

This also means that you don’t need to special case your function call syntax. The following works just as well:

add 42 (3 * 4)

While the $(…) syntax does have precedent I wouldn’t exactly look at languages like bash as a beacon of good PL design.

It still feels a little odd having the two function call syntaxes, but if it’s important to you to allow the command-line style of function invocations, it seems reasonable to allow it in cases where it’s necessary to resolve ambiguity (e.g. method chaining).