Live data from Hacker News

The Janet Language

janet-lang.org

131–140 of 203 posts

Re: The Janet Language

#132
post #125

Sounds a lot like the space of Lua. How do they compare?

They're similar! The author of Janet previously wrote https://fennel-lang.org/, a compile-to-Lua language.

Janet has more traditional scoping rules than Lua. Tables and arrays are separate types in Janet, and arrays are 0-indexed. Biggest runtime difference is probably that Janet has value types.

I think the compile-time programming is the real differentiator, but it's hard to summarize what that means in a comment.

Performance is pretty similar to the vanilla Lua interpreter in the benchmarks I've seen and run (Janet typically wins slightly), but there's no LuaJIT.

Re: The Janet Language

#133
post #108
post #86

Earlier quoted context omitted.

I tried to translate it to python, I translated (defn sum3 "Solve the 3SUM problem in O(n^2) time." [s] (def tab @{}) (def solutions @{}) (def len (length s)) (for k 0 len (put tab (s k) k)) (for i 0 len (for j 0 len (def k (get tab (- 0 (s i) (s j)))) (when (and k (not= k i) (not= k j) (not= i j)) (put solutions {i true j true k true} true)))) solutions) into def sum3(s) : """Solve the 3SUM problem in O(n^2) time.""…

One thing the Python version doesn't suffer from is lines that have to end in something like "))))". Syntax readability may be subjective, and I agree that the business logic in both examples are equally readable, but I think having to read and write a bunch of repeated punctuation at the end of a line, depending on how deeply the final statement is nested, is annoying. I don't know how Janet in particular handles er…

You don't HAVE to write lines that way, though it is the convention which as a mostly outsider I've never been a huge fan of. Think about languages like c# where you often have multiple closing curly braces but the convention is separate lines. You could write them like Lisp if you wanted but no one does.

Re: The Janet Language

#134
post #70

Earlier quoted context omitted.

> So, you start out with g(x) and then need to go all the way back and add f. That's one thing I will say after coming from Perl/PHP to Java, is that despite its verbosity and the uselessness of having to write .stream(), I much prefer Java's stream.map(...).filter(...) syntax over the more functional-style filter(map(list, ..), ..) syntax. The Java syntax reads left-to-right, which is the order you want when you're…

It's notable that raku (previously known as perl6) lets you write things in either direction, if I remember correctly something like @source >>> map { ... } >>> grep { ... } >>> my @sink; though note I'm typing from memory on my second coffee so I may have got that slightly wrong. Plus of course there's many languages with a |> operator so you can do g(x) |> f I also (the example is specialised for I/O but the implem…

Raku also has map and grep methods for collections, so it could be written as...

  my @sink = @source.map({...}).grep({...}).sort;
Which also makes multithreading the operation easy:

  my @sink = @source.hyper.map({...}).grep({...}).sort.list;
That said, I think the operator you're looking for is the feed operator, ==>:

  my @sink;
  @source ==> map {...} ==> grep {...} ==> sort ==> @sink;
It also has the corresponding reverse, may at some point do automatic parallelization, but I don't know what the status of that feature is.

* https://docs.raku.org/routine/==%3E

Re: The Janet Language

#135

One thing that bothers me about languages that compose functions like this f(g(x)) is that when programming interactively f is typically an afterthought. So, you start out with g(x) and then need to go all the way back and add f . Similarly, when x turns out like it needs to be elaborated, and you either have to go all the way back, or edit the expression in place making it longer and inevitably facing problems with…

Thank you for making an actually relevant point about syntax. I agree with this 100%, and I love Janet, and was recently doing a lot of interactive Janet programming for a generative art playground.

So I added postfix function application. So instead of (f (g x)), you can write (g x | f).

I liked the syntax a lot, but it looked really weird with operators: (calculate x | + 1). So I made operators automatically infix: (calculate x + 1).

I also didn't like that the transformation from foo to (foo :something) (record field access) required going back and adding parentheses before the value, so I added foo.something syntax that means the same thing.

The result is something that's very easy for me to type and read:

    (def eyes
      (eye-shapes
      | color (c + 0.5)
      | color (c - (dot normal (normalize eye-target) - 0.72
              | clamp -1 0
              | step 0))
      | color [c.b c.g c.r]))
(Excerpt from the logo of https://toodle.studio -- https://gist.github.com/ianthehenry/612c980f0db04ea3c2ccab27...)

Is this even Janet anymore? I dunno. It's a Janet dialect, and it's implemented as regular old Janet macros. But it's much easier for me to type like this. I recognize that it makes my code necessarily single-player, but that's fine for the sorts of dumb projects that I do for fun.

I think a lot of lisp programmers use paredit exactly so that they can write (f (g x)) in the order g x f, but with their editor re-positioning their cursor and taking care of paren-wrapping automatically. But I don't use paredit, and I don't want to wed myself to a particular mode of editing anyway. So I like a syntax that lets me type in the order that I think.

Re: The Janet Language

#136

Earlier quoted context omitted.

> I feel the need to say it every time I see new lisp-like language. Normal people don't like lisp, it looks weird. So? Normal people aren’t computing enthusiasts, so... > Are lisp-like language designers aware of that? No, lisp-like language designers have never hears the parenphobes that jump into every discussion of lisp-like languages to make their feelings known. Also, no one involved in Python, YAML, etc., has…

vaguely kinda related. I want to like lisp for its features but the syntax is too much for me to pick up without serious time investment, which I am not sure I want to make. are there any other languages that support for example lisp-like interactive REPL, eg analyzing program state while it is running?

> I want to like lisp for its features but the syntax is too much for me to pick up without serious time investment

There's atoms, and lists, and at the highest level of a program, the head of the list is the thing to be invoked (function, macro, special form) and the tail is a list of args. At lower levels, the higher level context says what a list means, but either a list itself or the same head/tail interpretation are the main things.

And there are some quoting constructs that control if things are bare atoms or references to the values of names, etc., and that's about it. Lisp has very little syntax. I mean, unless your main language is raw assembler or some esoteric toy like brainfuck, lisp almost certainly has much less syntax.

> are there any other languages that support for example lisp-like interactive REPL, eg analyzing program state while it is running?

Erlang.

Ruby (via Pry).

Lots of others.

Re: The Janet Language

#137

One thing that bothers me about languages that compose functions like this f(g(x)) is that when programming interactively f is typically an afterthought. So, you start out with g(x) and then need to go all the way back and add f . Similarly, when x turns out like it needs to be elaborated, and you either have to go all the way back, or edit the expression in place making it longer and inevitably facing problems with…

I'm not familiar with Janet, but I know it's Clojure-inspired, so it probably has threading macros, which are like shell pipes on steroids. In practice, when doing REPL-based development, it's very common to use these as opposed to (g(f x)).

Janet does indeed have those.

Re: The Janet Language

#138

Earlier quoted context omitted.

I went there, saw the Lisp syntax, and noped back out.

Same reaction here... wow that is a rough looking language. Then again I always disliked those kinds of languages like Clojure. The syntax is just too much for me. I feel like if I used it, it would atrophy my skills in other more traditional languages.

I've been using Lisp for hobby projects for a few years. Yes the syntax takes some time, but

> I feel like if I used it, it would atrophy my skills in other more traditional languages.

was not the case for me at all. If you go into a text editor and remove all the parentheses, I find that's how Lisp programmers tend to see Lisp, (function argument) isn't that far from function(argument).

Learning Lisp has only improved my skills as a programmer, after getting ideas like code as data, macros, let over lambda, CLOS and the metaobject protocol. It's a simple model that to me shows how other languages have picked an abstraction and stuck with it, but Lisp has all the tools to implement those abstractions and more.

More mainstream languages are great at focusing the developer, and that makes them very practical. It is amusing though to watch many of the "new features" in languages come out even though Lisp had them years ago.

Re: The Janet Language

#139
post #130
post #42

Earlier quoted context omitted.

The empirical evident would be against you, as tens of millions of programmers prefer writing code in those other languages that lack the parent :-)

My claim was that normal people preferred not to write any programs at all in any language. As to programmers, obviously there are smarter ones and less smart ones and to each his own. Here, a weirdly misplaced smiley back at you :-)

Smugness doesn't make one smart. Lispers have plenty of the former, though ;-)

Re: The Janet Language

#140

Earlier quoted context omitted.

I went there, saw the Lisp syntax, and noped back out.

Nope as a verb is new to me - just heard it for the second time this week. First time was from my child.

It's somewhat youthful internet slang. You'd hear it at the American public highschool I was at 12 years ago.
Post reply on HN