3 ms·
I'd have just written this as a Python library that lazily evaluates expression via numpy personally. The API is useful, language is not
by xyzsparetimexyz 4mo ago
I'd have just written this as a Python library that lazily evaluates expression via numpy personally. The API is useful, language is not
- mswphd 4mo agothat has some technical limitations. For example, their impl can compile to wasm, which makes giving an online interpreter simpler/lighter weight than relying on running python in the browser.
- kccqzy 4mo agoPeople do this kind of computation using numpy all the time. If you weren’t developing a new language with a new syntax, there really isn’t much of a library to write. At that point it’s just using numpy.
- manucorporat 4mo agothe language can do a lot of very expressive things, every language feature works in your favor too, but agree with you, i would not use my own language for anything production. like this: D ~ unif_int(1, 6); Print("P(rolled a 6 | rolled > 3) =", P(D == 6 | D > 3)); or: loss ~ unif(0, 1000); claim = if loss > 200 { loss - 200 } else { 0 }; p = P(claim > 0); Print("P(insurer pays a claim) =", p) notice that "claim" is also a random variable! result of a if expression
- kccqzy 4mo agoYeah sure this is how numpy people would do it: N = 10**6 D = np.random.randint(1, 6, N) print("P(rolled a 6 | rolled > 3) =", ((D == 6) | (D > 3)).mean()) loss = np.random.uniform(0, 1000, N) claim = np.where(loss > 200, loss - 200, 0) p = (claim > 0).mean() print("P(insurer pays a claim) =", p) It’s concise enough that people generally wouldn’t bother writing a library. Unless they really want their custom syntax, then perhaps they write a parser.