You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Multiple script languages have an idiom to detect if the current file is being imported by another file or is the main file of the program (in this case, being the main file means that this is the file that started the program).
This is useful since it allows the file to be imported by other files, however at the same time it allows the file to be executed directly. This doesn't make a lot of sense in compiled languages like Clojure (since they only have one entrypoint), however in script languages they make more sense since you can basically execute any as a full program.
Having something like a variable called *name* for example would allow for something like:
Multiple script languages have an idiom to detect if the current file is being imported by another file or is the main file of the program (in this case, being the main file means that this is the file that started the program).
For example, in Python we have this idiom (an explanation what is happening here can be found in https://stackoverflow.com/a/419185):
This is useful since it allows the file to be imported by other files, however at the same time it allows the file to be executed directly. This doesn't make a lot of sense in compiled languages like Clojure (since they only have one entrypoint), however in script languages they make more sense since you can basically execute any as a full program.
Having something like a variable called
*name*
for example would allow for something like:Btw, this is common enough that Hy for example has a
(defmain)
to be used in those cases: https://docs.hylang.org/en/stable/language/api.html#defmain. However this may be too much.The text was updated successfully, but these errors were encountered: