Initiation or main function in Julia

I read that global variables have a noticeable effect on performance.

To avoid them, I put everything inside the init function , as I read here .

Simple example: integer.jl:

function __init__()
    n = 0
    while n < 2
        try
            print("Insert an integer bigger than 1: ")
            n = parse(Int8,readline(STDIN))
        catch Error
            println("Error!")
        end
    end

    println(n)
end

When I run julia integer.jlfrom the command line, nothing happens. function main()doesn't work either.

What to do to make it work?

(Also, can you fix any errors, inefficient code, or non-idiomatic syntax?)

+4
source share
1 answer

__init__ , , , , , . main ( ), :

function main()
    # do stuff
end

main()
+11

Source: https://habr.com/ru/post/1628674/


All Articles