Julia keywords

Hi,
Reading the Julia documentation, I understand that using, import, function …etc are reserved keywords.
I was wondering if users can create their own keywords? If yes, is there an example of how I can do that?
Thank you

What do you mean by custom keywords? A keyword is a word that is reserved by the language. If you “define your own word”, then it is not reserved by the language and so is not a keyword.

You can define constants, functions (and operators), or macros. Does it not satisfy your needs?

Try to explain what is your end-goal, please.

2 Likes

I would like to define my own word, not reserved by the default language. End goal is to extend the language.

No, you cannot do that without changing the code of the compiler/interpreter. I think this holds true to most if not all programming languages.

3 Likes

Thank you, that answers my question.

While you cannot define new keywords, Julia supports quite powerfull Macros. With these you essentially rewrite arbitrary syntactically correct Julia code to your liking. You’ll probably be able to achieve most of the stuff you want with clever use of macros. I’ll leave you with the Manual page about macros.

10 Likes

@gitboy16 I just want to note that the previous responses are in the context of defining a new syntax for your own code. If you are interested in extending the language as a whole (and submitting a PR into the main branch for the whole world to use), this would be done likely in JuliaSyntax.jl

Well, it’s pretty unlikely that significant changes to the syntax, including new keywords, would get merged: PSA: Julia is not at that stage of development anymore

Except maybe LISP and similar? But macros provide similar functionality in Julia, to some degree.