Kashmir: A statically typed Lispy language compiling to Go
owickstrom.github.io
owickstrom.github.io
(define (factorial n)
(if (< n 2)
1
(* n (factorial (- n 1)))))
and ;; here the type of y is inferred
(fn ([x : int] y) (+ x y))And a comment withe original code and a link back to your site :)
I'm mostly just annoyed because everyone releases all these incompatible Lisp wannabes, when Common Lisp, Scheme, and even Clojure, are all perfectly good languages. Common Lisp has a few really good compilers (sbcl, lispworks, etc.) that produce code that's competitive with C in some situations. QuickLisp has really modernized the CL library ecosystem, and while there aren't as many libraries available as there are for Python, Ruby, and Java, the situation has drastically improved recently, and is continuing to improve.
Anyhow, I wanted to get some feedback on this project and perhaps involve people early on, so not having macros yet is nothing that I'm ashamed of. I hope to implement them soon.
And yes, there are a lot of good compilers out there. Kashmir is not a replacement for any of them or any of the established Lisps. :)
I agree with the rest of your comment.
It's heartening to see a revival of Lisps. For reasons I can't explain, s-expr syntax has a certain symmetry and beauty and is far more understandable to me than the alternatives.
Not sure yet what Kashmir brings to the table besides the Go output, and what advantages that provides. I'll have to study it further.
A half-formed thought floats across my brain that a Lisp/Scheme compiling to Rust might have merit. Considering the idea that a Rust back end could possibly minimize the necessity for GC, performance of the resulting executable would be less encumbered.
Really don't know how far one could get in that direction, probably more difficult to achieve than I could imagine.
(If you can write reliable tentacles and dress them up so that people want to touch them frequently, you can become very, very rich.)
A few of the motivations:
* A lisp with an amazing startup time
* A lisp that can tap into a big and vivid ecosystem, like Clojure is tapping into Java's and its own
* Cross compilation and self-contained binary (I've personally tried doing this with various lisps, and none of them really support it)
* Go as a platform is improving version by version and is very performant already
Another way to think of it - if only Clojure compiled to binary directly, then this would be pointless. Because chances of that happening are virtually zero, is why this project made my day.
Go is the assembly language of cloud infrastructure, just as Javascript is becoming yet another "assembly" language. I believe Go is perfect for this, because it is also simple (as opposed to ES6, for example).
People say this about JavaScript because to run code in a browser, it has to execute as JavaScript. As a result, there are lots of actual libraries or webapps that are written in other languages and compiled to JavaScript.
In contrast, you can do cloud computing in Java, C++, or various other languages. Go may have advantages, but compiling to Go would just be a choice.
In short, I really don't know what you meant or why you'd say it.
Google did a pretty amazing job of walking back the "replacement for C" talk and positioning Go as the language for web/micro/cluster/distribution/cloud/interconnected services.
But maybe I misinterpreted and (s)he meant Assembly.
If you ask me following is the checklist it passes:
1. Low memory footprint/good GC
2. Concurrency (goroutines) builtin
3. Great dependency (package) management
4. Compiled/closer to bare metal
5. Fast compilation
If you check other languages against the list they lack at least one of the above. If you feel any other language is better suited please tell.
I don't think this makes any sense. Javascript is the assembly language of the web because it's the only choice for the web (or more specifically, the browser). At best, any other legitimate choice will just compile to JavaScript, which is why it's thusly named. Go has no such privileged position; it's not even clear what it would mean to be the "language of choice on the cloud." You can write cloud software in any language you want, provided that the language has libraries for networking. All of the features you list are great, but none of them are exclusive to Go, nor are they required for cloud computing.
Eh... Then why are people experimenting with vendoring?
> If you check other languages against the list they lack at least one of the above. If you feel any other language is better suited please tell.
Ocaml checks all of them. So does Haskell (with stack package manager), with only the low memory requirement being challengeable since many aren't used to optimizing lazy evaluation.
Regarding the package management comment. If it is an experiment let results get in. Some people consider vendoring bad yet others find some use in it. If vendoring happens like it or not it wont make dependency management bad as a whole.
That's said, the project states more flexibility as a goal - specifically supporting generics. Between code generation and the cross-language compiler, writing generics (but generating non-generic Go code) should be somewhat easy to reason about.
There are many advantages to writing real world applications in a lisp.
- structured editing of source code - macros (dry, dsl's, etc) - if your Go code uses interface{} everywhere you'll probably have more of an advantage using dynamic typing anyway.
Did you try Chicken Scheme?
$ echo "(print \"Hello, World"'!'"\")" > hello-world.scm
$ csc hello-world.scm
$ ./hello-world
Hello, World!
$ du hello-world
16 hello-world* Fast compilation * Very very easy cross-compilation * A pretty good garbage collector * A huge library of easy-to-use libraries (they don't suffer from StringCollectorBeanFactoryProxy-syndrome) * Good concurrency support
Makes sense if you ask me.
https://github.com/owickstrom/kashmir/tree/master/experiment...
However, Kashimir is the first statically typed language implemented in Go that I have seen. The rest are dynamically typed.
[0] GLISP - https://github.com/zhemao/glisp
[1] golisp - https://github.com/SteelSeries/golisp
[2] go-lisp - https://github.com/janne/go-lisp
[3] Kakapo - https://github.com/bytbox/kakapo
[4] Golua - https://github.com/akavel/goluago
[5] Gisp - https://github.com/jcla1/gisp
[6] Gsp - https://github.com/gsp-lang/gsp
There were a bunch of reasons to change the name and I was going to create a GitHub organization for it anyway. Kashmir was not a good choice for Googleability and it turned out there's some city or region in the Kashmir region called "Golang"... :S
Sorry about the confusion!
One of the things I'm not sure you're looking at, and that you really ought to decide sooner rather than later, is how much interaction with Go itself you want. You very much do not want to leave the Go FFI interactions until the end.
In fact I daresay this is a critical decision that needs to be the next thing you really spend a lot of time thinking about, because a Kashmir that has a very poor Go FFI leaves me little reason to prefer it to Haskell, or Liskell if you want to get closer to Lisp. (Truthfully, reading over your goals & features, this sounds closer to Haskell than a Lisp, except in syntax, so I'm going to use Haskell as my benchmark.)
However, many of those goals and things in the type system will be at odds with having a simple Go FFI. If all functions in Kashmir are auto-curried, then Go has a hard time calling in to them, with a clumsy syntax and probably slow performance. If Kashmir's type system ends up complicated enough that the Go type system can't express Kashmir function types at all, then Go can't call into Kashmir at all, or some complicated "generic instantiation" step will be required. On the other side, you have to worry about data structure compatibility, too; if Kashmir data structures don't have a nice mapping to Go data structures then Kashmir is going to have a hard time calling into Go code.
Also, I'd suggest before proceeding much farther that you are very, very sure that you understand Hindley-Milner deeply, including what can break it. It offers a lot of inferring power, but at the corresponding cost of laying a lot of very specialized restrictions on your program. These carefully mathematically-specified things often have a way of breaking down the instant you put a toe outside their specified line. (The Haskell community has added things to it that have good bang/buck, but it's always something they have to be careful about.) Go's native type system, for instance, has one huge difference with Haskell that would have me a bit nervous, which is the difference between:
(+) :: Num a => a -> a -> a
type Num interface {
Add(Num, Num) Num
}
Haskell's type there guarantees all the a's are the same Num type. The Num typeclass does not promise that all "Num"s can be added together, only that a Num can be added to other same type things. Go's type system can not guarantee this; that interface in Go is promising that either A: You can hand it any two things that implement Num and it will return yet something else that implements Num which may or may not have any particular relationship to the original types or B: it will panic at runtime. (Or loop forever, I suppose, but it seems strange to be seriously discussing "bottom" in Go at all....)Where in practice you can turn to a programmer and say "Hey, obviously, it makes no sense to add a rational and a Peano integer together, and if you did, you obviously wouldn't expect a BigInt back. So just don't do that.", your type inferencer will not be able to make such assumptions, and if it does, you're right back to the problem that that will raise all sorts of hell in your FFI.
These are not necessarily unsolvable problems! For one thing, there's the sort of degenerate solution of simply not permitting any FFI, and only permitting Kashmir->Go in a very restricted, stereotypical manner that requires a specialized binding step. You could also write off calling Kashmir from Go, if that helps, which is not a bad decision, but is one you should be deliberate about. But I would suggest it is deserving of being the very next issue you tackle, and spend a lot of time thinking about. Go's type system is really, really weak for a static type system, in the sense of what guarantees it is capable of expressing, and trying to cozy that up to a Hindley-Milner system without giving up on a lot on one side or the other is going to be a challenge.
Kashmir resonates very strongly and has strong meaning for a significant % of the world's population. Think about coming up with a name like "Crimea" for a language if it has no connection whatsoever. If it does, that's great, may be the author can draw the connection to it on the website.
I have been to Kashmir. All I associate with it is sheer beauty. Just ignore the two big babies with the big guns, fighting over it.
My first association was cashmere wool, which is called kashmirvilla (or kašmirvilla depending on orthographic preferences) in my native Finnish.
Author of Kashimir could use a similar solution.
In my mind, the second one is where this language can really find it's niche.
(let ((x :string "hello"))
(fmt.Println (+ x "owickstrom")))
(Although in that case the type can probably be infered...) (let (([x : string] "hello"))
(fmt.Println (+ x "owickstrom")))