No more 'isprime' function in Julia 1.9.3?

I typed ?, then isprime, and got the message

Couldn’t find isprime

But I saw this function in the video

Is the function deleted?

This function can be found in the package Primes.jl. So you need to do Pkg.add("Primes") aonce to add to the current environment and then you can load it with using Primes. Afterwards the function isprime will be available.

1 Like

For a guy used to MATLAB, the ‘using’ practice is annoying.

Yea, having used MATLAB for a while, the change-up can be a bit onerous at first. It does get a bit easier with time. Also, a pattern that is valid both in Julia and Python is something like:

import Primes:
    isprime

# rest of your code here

You can exactly see where things are coming from where sometimes finding the right toolbox in MATLAB can be a little tricky. Hope that helps makes the transition a little easier!

1 Like

It might be worth nothing why we have the “using practice”.

  1. Reduced startup time: Loading all features/packages automatically on startup would take quite some time. And it would be largely unnecessary because we would load all kinds of features that you’re not going to use anyways. (I might have used isprime like once or twice in over 7 years of using Julia.)

  2. Faster development: Backed in features are tied to the Julia release cycle (say, ~ 2 releases per year). Packages (that you load via using) can move much faster and tag new releases - with new amazing features - at a much higher frequency. (Imagine isprime had a bug and you would have to wait half a year for the fix to land in a new Julia version.)

  3. Extensibility: Everyone can create there own package and than load it via using. No need to “ask for permission” or to debate with the Julia devs about whether this feature is (generally) useful enough to be baked into Julia itself.

(There are likely more reasons but those are the most important ones IMO.)

4 Likes

One more thing, you can load all the packages that you regularly need in your startup.jl so that you don’t have to type using ... all the time. Or create your own “superpackage” that just loads all relevant packages and re-exports all features. In this case, it would just be a single using AllMyTools.

5 Likes