Skip to content

Commit 9f37ba8

Browse files
authored
define entry point as main(args) instead of main(ARGS) (#54288)
fix #54252 see also: #50974 (comment)
1 parent e80a880 commit 9f37ba8

File tree

5 files changed

+18
-18
lines changed

5 files changed

+18
-18
lines changed

HISTORY.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ Compiler/Runtime improvements
5959
Command-line option changes
6060
---------------------------
6161

62-
* The entry point for Julia has been standardized to `Main.main(ARGS)`. This must be explicitly opted into using the `@main` macro
62+
* The entry point for Julia has been standardized to `Main.main(Base.ARGS)`. This must be explicitly opted into using the `@main` macro
6363
(see the docstring for further details). When opted-in, and julia is invoked to run a script or expression
6464
(i.e. using `julia script.jl` or `julia -e expr`), julia will subsequently run the `Main.main` function automatically.
6565
This is intended to unify script and compilation workflows, where code loading may happen

base/client.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -582,13 +582,13 @@ The `@main` macro may be used standalone or as part of the function definition,
582582
case, parentheses are required. In particular, the following are equivalent:
583583
584584
```
585-
function (@main)(ARGS)
585+
function (@main)(args)
586586
println("Hello World")
587587
end
588588
```
589589
590590
```
591-
function main(ARGS)
591+
function main(args)
592592
end
593593
@main
594594
```
@@ -601,7 +601,7 @@ imported into `Main`, it will be treated as an entrypoint in `Main`:
601601
```
602602
module MyApp
603603
export main
604-
(@main)(ARGS) = println("Hello World")
604+
(@main)(args) = println("Hello World")
605605
end
606606
using .MyApp
607607
# `julia` Will execute MyApp.main at the conclusion of script execution
@@ -611,7 +611,7 @@ Note that in particular, the semantics do not attach to the method
611611
or the name:
612612
```
613613
module MyApp
614-
(@main)(ARGS) = println("Hello World")
614+
(@main)(args) = println("Hello World")
615615
end
616616
const main = MyApp.main
617617
# `julia` Will *NOT* execute MyApp.main unless there is a separate `@main` annotation in `Main`

doc/src/manual/command-line-interface.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,8 @@ See also [Scripting](@ref man-scripting) for more information on writing Julia s
4242
## The `Main.main` entry point
4343

4444
As of Julia, 1.11, `Base` exports the macro `@main`. This macro expands to the symbol `main`,
45-
but at the conclusion of executing a script or expression, `julia` will attempt to execute the function
46-
`Main.main(ARGS)` if such a function has been defined and this behavior was opted into
45+
but at the conclusion of executing a script or expression, `julia` will attempt to execute
46+
`Main.main(Base.ARGS)` if such a function `Main.main` has been defined and this behavior was opted into
4747
by using the `@main` macro.
4848

4949
This feature is intended to aid in the unification
@@ -59,7 +59,7 @@ expression.
5959
To see this feature in action, consider the following definition, which will execute the print function despite there being no explicit call to `main`:
6060

6161
```
62-
$ julia -e '(@main)(ARGS) = println("Hello World!")'
62+
$ julia -e '(@main)(args) = println("Hello World!")'
6363
Hello World!
6464
$
6565
```
@@ -70,19 +70,19 @@ the macro `@main` was used within the defining module.
7070
For example, using `hello` instead of `main` will not result in the `hello` function executing:
7171

7272
```
73-
$ julia -e 'hello(ARGS) = println("Hello World!")'
73+
$ julia -e 'hello(args) = println("Hello World!")'
7474
$
7575
```
7676

7777
and neither will a plain definition of `main`:
7878
```
79-
$ julia -e 'main(ARGS) = println("Hello World!")'
79+
$ julia -e 'main(args) = println("Hello World!")'
8080
$
8181
```
8282

8383
However, the opt-in need not occur at definition time:
8484
```
85-
$ julia -e 'main(ARGS) = println("Hello World!"); @main'
85+
$ julia -e 'main(args) = println("Hello World!"); @main'
8686
Hello World!
8787
$
8888
```
@@ -93,7 +93,7 @@ The `main` binding may be imported from a package. A *hello world* package defin
9393
module Hello
9494
9595
export main
96-
(@main)(ARGS) = println("Hello from the package!")
96+
(@main)(args) = println("Hello from the package!")
9797
9898
end
9999
```

test/cmdlineargs.jl

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1124,14 +1124,14 @@ end
11241124
## `Main.main` entrypoint
11251125

11261126
# Basic usage
1127-
@test readchomp(`$(Base.julia_cmd()) -e '(@main)(ARGS) = println("hello")'`) == "hello"
1127+
@test readchomp(`$(Base.julia_cmd()) -e '(@main)(args) = println("hello")'`) == "hello"
11281128

11291129
# Test ARGS with -e
1130-
@test readchomp(`$(Base.julia_cmd()) -e '(@main)(ARGS) = println(ARGS)' a b`) == repr(["a", "b"])
1130+
@test readchomp(`$(Base.julia_cmd()) -e '(@main)(args) = println(args)' a b`) == repr(["a", "b"])
11311131

11321132
# Test import from module
1133-
@test readchomp(`$(Base.julia_cmd()) -e 'module Hello; export main; (@main)(ARGS) = println("hello"); end; using .Hello'`) == "hello"
1134-
@test readchomp(`$(Base.julia_cmd()) -e 'module Hello; export main; (@main)(ARGS) = println("hello"); end; import .Hello'`) == ""
1133+
@test readchomp(`$(Base.julia_cmd()) -e 'module Hello; export main; (@main)(args) = println("hello"); end; using .Hello'`) == "hello"
1134+
@test readchomp(`$(Base.julia_cmd()) -e 'module Hello; export main; (@main)(args) = println("hello"); end; import .Hello'`) == ""
11351135

11361136
# test --bug-report=rr
11371137
if Sys.islinux() && Sys.ARCH in (:i686, :x86_64) # rr is only available on these platforms

test/project/Rot13/src/Rot13.jl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ end
77

88
rot13(str::AbstractString) = map(rot13, str)
99

10-
function (@main)(ARGS)
11-
foreach(arg -> print(rot13(arg), " "), ARGS)
10+
function (@main)(args)
11+
foreach(arg -> print(rot13(arg), " "), args)
1212
return 0
1313
end
1414

0 commit comments

Comments
 (0)