Hacker News new | ask | show | jobs
by pansa2 2134 days ago
In the absence of a return type, and with an LL(1) parser, there needs to be a keyword to indicate the start of a function definition. `def` is a little unusual, but it's also used by Ruby.

I once designed a Python-like language and used `function`, because the language made a distinction between `function`s and `method`s.

2 comments

And lispy langs mostly use "define…" keywords.
doing simply funname(args): would work fine
How would the parser know that’s a function definition and not a function call?
by the :
That's too late. The parser needs to know whether it's looking at a definition or a call before that - for example, to know whether to parse "args" as a `parameters` or an `arglist` [0].

[0] https://docs.python.org/3/reference/grammar.html