One of the bullet points is "Abstract data types (with `Option` and `Result` predefined)." I wonder if they mean "Algebraic data type", since I have seen Option/Result before as an example of those, and they're both commonly abbreviated ADTs. Or maybe they're trying to get at a concept I'm missing here?
Maybe off topic, but I do a lot of ad-hoc python scripts where I drop scripts everywhere in my filesystem, but I need dependencies installed in a virtualenv so my ad-hoc scripts can access them. The problem I'm having is that sometimes things will run for a whole day and then fail at the end because of a typo or something.
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.
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.
Author here. That's roughly what I was shooting for. Python was a big inspiration early on in the design, and later on some functional concepts were put into the mix. I found them and liked them too much to pass up on.
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.
Linters should catch most typos; failing that, Python's type hints are a pain to use, but you can address a lot of low-hanging fruit for free.
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.
If you're writing a lot of command line scripts and want some of the safety offered by types, but still want the flexibilty of python (+ more flexibility), you should check out perl6.
Take a look at kscript, which is a single-file wrapper around Kotlin that includes dependency specification in the script file: https://github.com/holgerbrandl/kscript
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)
> I took a look at Scala but instead of virtualenv style dependency management it's more like maven projects.
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.
I'm currently learning shelly haskell library. I tried to write a function in a haskell-emacs module and calling it as a elisp function in a eshell buffer and it worked flawlessly first try.
I took a look at Go but it seems to be more of a systems language than a scripting language and I assume that means it's less amendable to "This guy across the country needs this information in 2 hours max".
The point of my example is that my main priority is coding speed, and other things are an issue only if processing takes a long time. A systems language typically has a much slower coding speed than say, python, which is what I mainly use now.
I suppose that print statement was just a silly example, but just in case this may be of use to anyone, note that you can pass multiple arguments to print and they will be printed space-separated, each converted to a str, so you will (practically) never run into type errors.
True, that's a problem I don't have anymore but it's a quick and understandable example of a mistake that I think lots of people had made before.
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.
I absolutely agree that f-strings are excellent for formatting, but I don't quite understand why you would use formatting in a regular print statement, when you could just stick to the commas and let the concatenation happen naturally in the output buffer?
I read the first example of Lily on the site. I found nothing offensive in the language at all - in fact there's a lot to like particularly the readability.
Side rant. Unfortunate I can't get past the decision to use exception handling to deal with non-existing keys in map. I'm of the exception-disliking school which is thankfully growing but I guess not yet universal. For me
using an exception to indicate the lack of a value corresponding to a key in a map (is it really exceptional for this to happen?) is a textbook example of exception-abuse where the code is obfuscated by the non-locality of the control flow.
I actually didn't realize it was doable (not a heavy rust user - just an enthusiast). Kinda hidden away in docs under an example [0] and isn't in the book under hash maps [1]. Might be worth calling out somewhere explicitly? People getting started with rust probably aren't familiar with the trait-based operator overloading system yet.
> For me using an exception to indicate the lack of a value corresponding to a key in a map (is it really exceptional for this to happen?)
Sometimes it is, sometimes it isn't. Most languages allow you to choose whether you want a hash to throw a key error on non-existing keys or return a signal value. My favorite is the uber-flexible approach and nice syntax in Crystal:
hash[foo] is sugar for hash.fetch(foo)
hash[foo]? is sugar for hash.fetch(foo, nil)
hash.fetch(foo) will return the default value of the hash table on nonexistent keys if one was assigned, otherwise raise keyerror
hash.fetch(foo, nil) will return nil on nonexistent keys
You can use dict's get() method to get back a None for missing keys instead of throwing a KeyError exception. That avoids the overhead of checking `if key in dict` or catching KeyError.
Another option, it's very easy to wrap a dict in a defaultdict:
class optionaldict(defaultdict):
"""
A defaultdict that disregards KeyErrors and returns None for missing keys.
"""
def __init__(self, *original, **kwargs):
super().__init__(lambda: None, *original, **kwargs)
> Lily uses reference counting for memory management with garbage collection as a fallback.
I'd just call this GC where it's rc + (presumably) a tracing GC.
> .reject(|r| r.is_space() )
This is nice. I've always found "filter" to be a confusing name. Filter in? Filter out?
'reject' is a very clear name - if it is a space, reject it.
Code looks really reasonable.
I find `: {` to be a strange idiom. Why not one or the other? Seems to distinguish between single vs multiline? I guess that's reasonable. A bit noisy.
'reject:' is originally from Smalltalk, along with 'collect:' (map), 'select:' (complement of reject), 'detect:' (first matching element), and 'inject:into:' (foldl). I agree that these names are better -- they even rhyme so they're easier to remember!
Prior art like Wirth's or Modula-3 language added a minimal amount of features like exceptions or some OOP on top of simple, efficient, systems languages. Usually have a GC but many prefer ref counting for efficiency. This seems like that kind of thinking in an interpreted language.
Just going by what's on the front page: didn't dig deep into it or anything. Interesting project.
Reference counting isn't more efficient than GC; usually the value of reference counting is that it's deterministic and you can bind finalizers to them (with traditional GC, finalizers run when GC runs which may not even happen). The canonical example is a file object that closes its operating system file when the object is no longer used; this is nice in theory, but as the Python folks found out, not a good substitute for properly closing files.
The other recurring example for me was OpenGL resources like textures (this was in ObjC). Again, it turned out not to work so while once I got into more complicated examples, because of ordering issues: my GLWindow instance would get deallocated, and my refcounted GLTexture class would then get finalized after the underlying CGLContext was gone, or just not the active context. I started coming up with more elaborate schemes to deal with it but then it no longer felt elegant.
There is one other aspect of RC systems that I have come to appreciate but never seen anyone else write about: they play well with each other. It's fairly trivial to create foreign object wrappers for python and objective-c in both directions, that each call the appropriate refcount ops of the foreign system. You can then have allocated data structures referring back and forth across the language bridges and when you abandon the root, everything deallocates properly and deterministically in both runtimes. I do not have much experience with GC runtimes and their FFIs but from what I've read I suspect this might be trickier to reason about. This is an obscure point, but one that I did find interesting in terms of language interop.
I'm not seeing what sets this language apart. None of its features are very unique, and I believe all except garbage collection already exist in C(++). Can anyone explain what makes it interesting?
is a shift-hell challenge to type it. Most of my unproductivity goes from being tired of mistyping or too concentrated on precise shifting. Even $150 keyboards go with classic/tkl layout at most; no chance unless going handmade.