I am wondering how a function is processed in a certain language due to the two errors caused by the following two functions in Python.
def fun(a=[0], b: int):
pass
The error reads that SyntaxError: non-default argument follows default argument
.
# to show that this function is not trivial
def fun(a:list=[0], b=len(a)):
pass
Araises the error: NameError: name 'a' is not defined
The first example shows obviously that a
is processed before b
, that is the compiler should know a
when it encounters b
, but it seems that the compiler doesn't as shown in the second example.
When(or how) is a parameter defined in a function? Or how can I know what's going on under the hood? I mean the related part of the compiler code, may be implemented in context-free grammar.