With https://github.com/DanielKeep/cargo-script you can have single file Rust "scripts" with ecosystem dependencies.
When executing the file (via the cargo-script wrapper), dependencies are fetched and a binary is compiled on demand (and cached for re-runs).
It's pretty awesome for scripts where type safety is important.
#!/usr/bin/env run-cargo-script
//! This is a regular crate doc comment, but it also contains a partial
//! Cargo manifest. Note the use of a *fenced* code block, and the
//! `cargo` "language".
//!
//! ```cargo
//! [dependencies]
//! time = "0.1.25"
//! ```
extern crate time;
fn main() {
println!("{}", time::now().rfc822z());
}
Then you can just execute it with ./my-script, which will download dependencies, compile and execute. #!/usr/bin/env groovy
// @Grab annotation won't work in scripts
import static groovy.grape.Grape.grab
grab(group: 'org.apache.commons', module: 'commons-csv', version: '1.5')
println "Starting to parse CSV"One advantage of Lily not mentioned (with regard to typing), is that the type-checking is very fast. One of the reasons I made Lily interpreted and homebrewed all the parts was because as much as I like static typing, it's often slow. Slow static typing, I think, diminishes some of the value of it since you're still waiting but in a different way.
I think for your use case though, Go would be perfect. Everything is statically compiled, so you don't need to mess with virtualenvs, and everything is statically typed ahead of time. I'm a professional Python developer, but I often do my prototyping in Go because the type system is more ergonomic than Python/mypy.
Gradual typing: https://perl6.party/post/Perl-6-Types--Made-for-Humans Command line arguments: https://perl6advent.wordpress.com/2010/12/02/day-2-interacti...
And at the end of the day it's perl, so it's the king of command line scripts.
Example:
#!/usr/bin/env kscript
// Declare dependencies
@file:DependsOn(“com.offbytwo:docopt:0.6.0.20150202“)
import org.docopt.Docopt
val usage = “...”
val doArgs = Docopt(usage).parse(args.toList())
println("Hello from Kotlin!")
println("Parsed script arguments are: \n" + doArgs)You could do virtualenv style by setting the CLASSPATH environment variable if you really want. The ecosystem tends to prefer using explicit dependencies though.
> It has Ammonite where you can declare dependencies at the top of files but that seems kind of hacky.
Sort of, but I don't think you'll do better anywhere else. Lots of other replies are suggesting various languages that do essentially the same thing - a magic comment at the top of the file that declares your dependencies.
go run source.go
gives you the compile time checks, while still giving you the source code visibility and simplicity of scripts
print(str, int)
Instead of a comma I would actually recommend f-strings, which are python's string interpolation. The only downside is that the code within the f-strings I think have even less prechecking.
https://www.python.org/dev/peps/pep-0498/
Example: print(f"There are {len(lights)} lights!")
print("There are", len(lights), "lights!")
I've been looking at other languages to see if there's a language like python but type checked, or some kind of prechecking so I don't lose hours of processing to a print(str+int).
I took a look at Scala but instead of virtualenv style dependency management it's more like maven projects. It has Ammonite where you can declare dependencies at the top of files but that seems kind of hacky.
The other option is Python compile time checks using type hints and mypy, which I think I should eventually learn but haven't gotten around to.
The Lily language looks like the closest thing to "functional type checked python" that I've seen and that's cool.