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
User-defined functions were added in #3247 with the following syntax:
foo(a, b) := a + b
They are currently unstable, since I'm not sure about the syntax. The alternative that I'm considering is:
fnfoo(a, b) := a + b
I personally think the syntax without fn looks better, but with fn allows grepping for function definitions with ^fn, however I'm not sure if that's a huge advantage.
Feedback on the syntax is most appreciated, in either direction. In addition to the syntax, the behavior questions below need to be settled before stabilization.
Reacted by jonaslewis-tor, kadidra-gura, Andrew Ferreira and aplmngo
The other issue that I didn't think of is disambiguation in the expression language, if the expression language ever permitted function definitions.
In the context of expressions f(a,b) is a valid function call, so to disambiguate a function call from a function definition f(a,b) := ... you would have to use an unlimited amount of lookahead, whereas fn f is already disambiguable.
Hm really? Couldn't you do ^\w+\([^\)]\) := to ensure it's a function definition? It wouldn't trigger for nested function calls, either. Not sure what you're referring to with expression language tho - asked llm, something about the parser?
I'm not really being precise. In Just, the parser operates in a few contexts. One is at the top level, when it's parsing items like recipes, settings, assignments, and function definitions. Then, in certain places within items, it starts parsing expressions, which I'm imprecisely calling "the expression language". This happens in a few places, for example, on the right side of := in assignments, or in recipe argument defaults.
At the top level, IDENT ( is not ambiguous, because a function call cannot appear in that position. When parsing an expression, IDENT ( is ambiguous, because a function call can appear in that position.
The parser doesn't use regular expressions to recognize what it's about to parse, just because regular expressions are super fragile. It processes the text one token at a time, and uses some amount of lookahead, i.e., looking at tokens past the current token, to disambiguate what's coming next.
An example which would break the regular expression is:
foo() \
:= "bar"
A function definition with a line continuation before the :=. The line continuation is just whitespace, so it doesn't bother the parser, but it does break the regular expression.
Another example is:
foo(a=("a")) := a
In this case, the default argument ("a") contains a closing-paren, which causes the regex not to match, even though it is a function definition.
In general, regular expressions just aren't powerful enough to make parsing decisions. Especially HTML ;)
For the parser to disambiguate a function definition from a function call, without a leading fn, it has to look ahead a potentially unbounded amount of tokens, which is pretty rough.
This already happens when parsing a recipe at the top-level, since recipes can be named after keywords (set, alias, etc, are valid recipe names), so we have to disambiguate with lookahead, which is super gross, and a source of bugs.
Fun fact, one of the very few non-backwards compatible changes I made when just hit 1.0 was changing assignment from using = to using :=, because = can appear in recipe signatures to introduce argument defaults, and having = be used both there and in assignments made disambiguation really awful.
For a manual immediate parser it makes sense to use a keyword for disambiguation. For example, this is the way Pascal language was designed.
Manual language parsing may be fast, but it's rough in terms of development and maintenance. Usually, language developers define a language grammar file, which is then processed by an automated tool producing the actual parser code. When you work on a grammar level, doing a lookahead is a piece of cake - the implementation will be autogenerated and will be reasonably fast.
To fn or not to fn is the question of the project ideology:
If you prioritize fast manual parsing without lookaheads, having a fn keyword is a way to go forward
Otherwise, fn is not strictly required as it has no purpose neither for the language nor for its users
Since just is a command runner, favoring a syntax without lookahead aligns well with the simplicity and philosophy of traditional Unix tools.
The binary might be task runner but the language is read and written by humans using other tools.
Generally I'd recommend designing syntax with highlighting / LSP support as core concerns. IMHO they are table-stakes for a modern usable language and developing them in tandem can guide you away from some language-design clangers.
Consider:
a textmate grammar (archaic but widely supported)
a tree-sitter grammar (quickest path to creating an LSP)
I have no comment on fn but were any proposed syntax tortuous to support then I'd consider it a red-flag for the language rather than "someone else's problem".
FYI current IDE support for just is not great : extensions are unmaintained, break on certain syntax or newer AI slop that I would trust less than an emailed executable. Given the risks of malicious extensions, I hope for IDE support from language developers these days.
If it helps, this is the textmate grammar of the most popular vscode extension with 60k users despite being unmaintained for years and highlighting that can fail catastrophically:
Just found out these were finally added. Very much appreciated ❤️ ! User-defined functions + guard sigils leave me with few remaining woes.
Regarding syntax: I prefer the former (no fn). I think the visual consistency of
ident := expr
ident(var...) := expr
is very pretty compared to
ident := expr
fn ident(var...) := expr
I really don't think worse support for grep is going to be a super serious inconvenience anyone faces.
I'm more curious about the parsing disambiguation issues.
At the top level, IDENT ( is not ambiguous, because a function call cannot appear in that position. When parsing an expression, IDENT ( is ambiguous, because a function call can appear in that position.
Are you implying that function definitions might be allowed in expressions i.e. you might add closures? I'm not sure where the ambiguity lies otherwise, as calls/definitions seem clearly delineated by context. Plus, if you ever do add closures, it's probably best to have a distinct syntax for those.
Activity
hrumhurum commentedon Apr 5, 2026
Mathematically speaking, function and data are the same thing. Using that assumption, the syntax without
fnis more preferable.Historically, math prevails even when we have strong personal opinions.
CaptaiNiveau commentedon Apr 7, 2026
I mean if it's just about grepping, you could just do
^\w+\(and be set, too. I'll play with it tomorrow, but I think I agree with @hrumhurumcasey commentedon Apr 7, 2026
The other issue that I didn't think of is disambiguation in the expression language, if the expression language ever permitted function definitions.
In the context of expressions
f(a,b)is a valid function call, so to disambiguate a function call from a function definitionf(a,b) := ...you would have to use an unlimited amount of lookahead, whereasfn fis already disambiguable.CaptaiNiveau commentedon Apr 7, 2026
Hm really? Couldn't you do
^\w+\([^\)]\) :=to ensure it's a function definition? It wouldn't trigger for nested function calls, either. Not sure what you're referring to with expression language tho - asked llm, something about the parser?casey commentedon Apr 7, 2026
I'm not really being precise. In Just, the parser operates in a few contexts. One is at the top level, when it's parsing items like recipes, settings, assignments, and function definitions. Then, in certain places within items, it starts parsing expressions, which I'm imprecisely calling "the expression language". This happens in a few places, for example, on the right side of
:=in assignments, or in recipe argument defaults.At the top level,
IDENT (is not ambiguous, because a function call cannot appear in that position. When parsing an expression,IDENT (is ambiguous, because a function call can appear in that position.The parser doesn't use regular expressions to recognize what it's about to parse, just because regular expressions are super fragile. It processes the text one token at a time, and uses some amount of lookahead, i.e., looking at tokens past the current token, to disambiguate what's coming next.
An example which would break the regular expression is:
foo() \ := "bar"A function definition with a line continuation before the
:=. The line continuation is just whitespace, so it doesn't bother the parser, but it does break the regular expression.Another example is:
foo(a=("a")) := aIn this case, the default argument
("a")contains a closing-paren, which causes the regex not to match, even though it is a function definition.In general, regular expressions just aren't powerful enough to make parsing decisions. Especially HTML ;)
For the parser to disambiguate a function definition from a function call, without a leading
fn, it has to look ahead a potentially unbounded amount of tokens, which is pretty rough.This already happens when parsing a recipe at the top-level, since recipes can be named after keywords (
set,alias, etc, are valid recipe names), so we have to disambiguate with lookahead, which is super gross, and a source of bugs.Fun fact, one of the very few non-backwards compatible changes I made when just hit 1.0 was changing assignment from using
=to using:=, because=can appear in recipe signatures to introduce argument defaults, and having=be used both there and in assignments made disambiguation really awful.hrumhurum commentedon Apr 7, 2026
For a manual immediate parser it makes sense to use a keyword for disambiguation. For example, this is the way Pascal language was designed.
Manual language parsing may be fast, but it's rough in terms of development and maintenance. Usually, language developers define a language grammar file, which is then processed by an automated tool producing the actual parser code. When you work on a grammar level, doing a lookahead is a piece of cake - the implementation will be autogenerated and will be reasonably fast.
To
fnor not tofnis the question of the project ideology:fnkeyword is a way to go forwardfnis not strictly required as it has no purpose neither for the language nor for its usersSince
justis a command runner, favoring a syntax without lookahead aligns well with the simplicity and philosophy of traditional Unix tools.duncanawoods commentedon Apr 8, 2026
The binary might be task runner but the language is read and written by humans using other tools.
Generally I'd recommend designing syntax with highlighting / LSP support as core concerns. IMHO they are table-stakes for a modern usable language and developing them in tandem can guide you away from some language-design clangers.
Consider:
I have no comment on
fnbut were any proposed syntax tortuous to support then I'd consider it a red-flag for the language rather than "someone else's problem".FYI current IDE support for
justis not great : extensions are unmaintained, break on certain syntax or newer AI slop that I would trust less than an emailed executable. Given the risks of malicious extensions, I hope for IDE support from language developers these days.If it helps, this is the textmate grammar of the most popular vscode extension with 60k users despite being unmaintained for years and highlighting that can fail catastrophically:
https://github.com/skellock/vscode-just/blob/master/syntaxes/just.tmLanguage.json
dylan-hachmann commentedon May 21, 2026
Just found out these were finally added. Very much appreciated ❤️ ! User-defined functions + guard sigils leave me with few remaining woes.
Regarding syntax: I prefer the former (no
fn). I think the visual consistency ofis very pretty compared to
I really don't think worse support for grep is going to be a super serious inconvenience anyone faces.
I'm more curious about the parsing disambiguation issues.
Are you implying that function definitions might be allowed in expressions i.e. you might add closures? I'm not sure where the ambiguity lies otherwise, as calls/definitions seem clearly delineated by context. Plus, if you ever do add closures, it's probably best to have a distinct syntax for those.
casey commentedon May 21, 2026
My pleasure!
I'm thinking more arbitrary blocks:
It's really unlikely that I would add such a thing, but it would be nice to keep the possibility open.