LispSyntax.jl
LispSyntax.jl copied to clipboard
Decide on syntax for optional type declaration
We'll need a type declaration syntax at least for method definitions.
I was thinking something like this
f(x::Number, y::String) = (x, y)
translating to
(defn f [(x :: Number) (y :: String)]) (tuple x y))
which leads to the question of parametric types and where
. I'm not as sure about how to deal with those.
I’ve run into this in other Lisps, too ... we explored it in LFE a while ago; more recently in a Go Lisp I’ve been playing with, I explored all sorts of possibilities:
- https://github.com/zylisp/zylisp/issues/49
Ultimately, I think I’d go with the following (mostly to stay closer to Go):
(type point struct
[X float64]
[Y float64])
(defn distance
[a *Point b *Point] float64
(math/Sqrt
(+ (math/Pow (- b.X a.X) 2)
(math/Pow (- b.Y a.Y) 2))))
This seems to be analogous to what you have proposed, namely staying close to the parent language:
(struct Point
x ::Float64
y ::Float64)
(defn distance
[(a ::Point) (b ::Point)] ::Float64
(sqrt
(+ (^ (- b.x a.x) 2)
(^ (- b.y a.y) 2))))
Although, I might rather have the Lisp do the interleaving of the args/types for me?
(defn distance
[a ::Point b ::Point] ::Float64
(sqrt
(+ (^ (- b.x a.x) 2)
(^ (- b.y a.y) 2))))
worth a discussion. there are lots of ways to do this including the racket and clojure (core.typing) ways. As julia has parametric types with 'where' conditions, that would have to be thought through too.
Since LispSyntax.jl is clojure-flavored, maybe syntax borrowed from defmethod would be a good analogy? https://clojuredocs.org/clojure.core/defmulti
Or alternatively, perhaps it would be better to move away from the focus on clojure per se and focus on a lispy syntax which is as close as julia as possible. I think this is probably my preferred option if the mission of LispSyntax.jl is to be a lispy veneer over julia semantics.