This is my dream language. Is it real?
Meghan (she/her)

Meghan (she/her) @nektro

About: 24. Local trans witch who prefers to do magic with a keyboard. she/her. Currently hacking away at making the Web less centralized.

Location:
Massachusetts, USA
Joined:
Mar 13, 2017

This is my dream language. Is it real?

Publish Date: Mar 21 '18
15 18

For a while, I've had a vision for my "dream" language. ((Sorry @mortoray , I don't think it's Leaf, still love your content))

The syntax I've come up with is inspired by JavaScript but with some added flair that would make it (best case scenario) compatible with ASM and WASM compilation.
I've left some sample code below, and I was wondering if anyone knew if a language similar to the snippet below exists.

import { sqrt, pow } from "math"

export class Point {
    struct {
        Int x,
        Int y
    }
    constructor(Int a, Int b) {
        this.x = a;
        this.y = b;
    }
    constructor(Int a) {
        this(a, a);
    }
    constructor() {
        this(0, 0);
    }
    distanceTo(Point pt) -> Float {
        return sqrt(pow(pt.x - this.x, 2) + pow(pt.y - this.y, 2));
    }
}

export class Circle {
    struct {
        Point center,
        Int radius
    }
    constructor(Point c, Int r) {
        this.center = c;
        this.radius = r;
    }
    constructor(Int r) {
        this(new Point(0, 0), r);
    }
    constructor() {
        this(1);
    }
    intersects(Point pt) -> Boolean {
        return pt.distanceTo(this.center) <= this.radius;
    }
}
Enter fullscreen mode Exit fullscreen mode

Thanks in advance for any help!


In hindsight this looks a lot like a real Java-Script like syntax but I was still curious if anyone knew if this existed before I went out and tried to start making a compiler for a project that's already been worked on :)

Comments 18 total

  • Dian Fay
    Dian FayMar 21, 2018

    TypeScript seems closest. There are other static type checkers like flow.

    • Gert Sønderby
      Gert SønderbyMar 22, 2018

      Flow is much like that, yeah. Variable declaration is slightly different, but overall, at first I thought the example was ES2015. 😀

  • Jochem Stoel
    Jochem StoelMar 21, 2018

    I don't know if such a language exists but writing an interpreter for it should be fairly easy. You can modify an existing Javascript interpreter or use Pegjs to generate a parser.

  • Idan Arye
    Idan AryeMar 21, 2018

    I find it confusing that the types come before the name for variables and after the name for functions...

    • Martin Becker
      Martin BeckerMar 21, 2018

      That looks like the return value, similar to how it's done in rust, what goes in the function is on the left, what comes out of the function is on the right.

      • Idan Arye
        Idan AryeMar 21, 2018

        In Rust the type is on the right in both variables and the return:

           name          type
            | name  type   |
            |  |    |      |
            V  V    V      V
        fn foo(x: i32) -> i32
        

        In C, the type is on the left for both the variables and the function (though one can argue that the arguments are also part of the function's type):

        type name
         |   | type name
         |   |   |  |
         V   V   V  V
        int foo(int x)
        

        In this syntax the order is sometimes type...name and sometimes name...type:

        name          type
         | type name   |
         |   |  |      |
         V   V  V      V
        foo(Int x) -> Int
        
        • Martin Becker
          Martin BeckerMar 21, 2018

          AH, yes you're right, I missed what you were specifically talking about.

    • overcache
      overcacheMar 22, 2018
         name          type
          | name  type   |
          |  |    |      |
          V  V    V      V
      fn foo(x: i32) -> i32
      

      did you make the illustration by hands? or there is some tools can do this

      • Idan Arye
        Idan AryeMar 22, 2018

        Just use a monospace font - any programming-oriented text editor will do.

    • Meghan (she/her)
      Meghan (she/her)Mar 22, 2018

      The type is on the left when it's required and on the right when it's optional

  • Andrew Walpole
    Andrew WalpoleMar 21, 2018

    Looks very similar to Processing. processing.org

  • Max Cahill
    Max CahillMar 22, 2018

    Wren might be getting there? It's not 1:1, of course, and it's not "for the web".

    As a few other folks have mentioned, Typescript indeed also sounds close to what you want, especially if you're looking for interoperability with the JS ecosystem.

  • Charles Crete
    Charles CreteMar 22, 2018

    Seems close to Dart, especially in strong mode.

  • edA‑qa mort‑ora‑y
    edA‑qa mort‑ora‑yMar 22, 2018

    Your dream language has semi-colons!? :P

    The challenge of any language, as I'm learning, is the addition of more features. In isolation one can come up with pretty syntax. Thrown into an app where a coder wants to do a lot, ugliness starts to appear.

    Having examples of what people like and dislike though is an important process in language design.

  • Dmitry Popov
    Dmitry PopovMar 22, 2018

    Looks like Kotlin, Dart and lots of other OO languages.

  • Márton Kardos
    Márton KardosMar 22, 2018

    This is basically every statically typed OOP language ever. Btw no idea on semantics? Really? I mean syntax is probably one of tge least inportant aspects in a programming language...

  • Antonio Radovcic
    Antonio RadovcicMar 23, 2018

    Swift gets close.

  • Harrison
    HarrisonMar 23, 2018

    Looks a lot like es6 but then if you wanted something smoother then typescript

Add comment