Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Decide on syntax for optional type declaration #30

Open
MasonProtter opened this issue Jun 11, 2019 · 3 comments
Open

Decide on syntax for optional type declaration #30

MasonProtter opened this issue Jun 11, 2019 · 3 comments

Comments

@MasonProtter
Copy link
Contributor

MasonProtter commented Jun 11, 2019

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.

@oubiwann
Copy link
Contributor

oubiwann commented Jun 12, 2019

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:

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))))

@swadey
Copy link
Owner

swadey commented Jun 12, 2019

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.

@c42f
Copy link
Collaborator

c42f commented Jun 15, 2019

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants