[HN Gopher] Terra: Low-level system programming language meta-pr...
       ___________________________________________________________________
        
       Terra: Low-level system programming language meta-programmed from
       Lua
        
       Author : teleforce
       Score  : 86 points
       Date   : 2021-05-30 15:49 UTC (7 hours ago)
        
 (HTM) web link (terralang.org)
 (TXT) w3m dump (terralang.org)
        
       | aeldidi wrote:
       | I remember reading something particularly negative about terra in
       | 2019[1]. Although I haven't used terra at all since the time I
       | first tried it (not long after I read the above mentioned
       | article), I think it's relevant to mention that at least at one
       | point, terra has had major problems regarding design. If anyone
       | has used terra in any non-trivial capacity I'd love to hear what
       | your experience with it has been like.
       | 
       | [1] https://erikmcclure.com/blog/a-rant-on-terra/
        
         | blackhole wrote:
         | Please note: The entire "windows" portion of that article has
         | largely been resolved at this point, because I fixed it myself.
         | Some of the more egregious documentation problems have been
         | fixed, but others remain unresolved.
         | 
         | Unfortunately, we have since discovered even more insane
         | behavior: https://github.com/terralang/terra/issues/460
        
       | rektide wrote:
       | Also runs in GPU via CUDA. That's it's well known claim to fame.
       | 
       | Appears to be going 1.0[1]!
       | 
       | [1]
       | https://github.com/terralang/terra/commit/1ea278278c104580a0...
        
         | eslaught wrote:
         | We're working on 1.0. The language is basically stable but
         | needs a little polish. As usual everything depends on what time
         | people have to put in. Always looking for more help!
        
       | nerdponx wrote:
       | Am I understanding this right?
       | 
       | Code inside a `terra` function is statically-typed and executed
       | at runtime, while the rest of the code is just plain Lua and is
       | executed at compiled time.
       | 
       | It's a really interesting idea and I'd be interested to try it
       | for something like an X11 application.
        
         | hollerith wrote:
         | I think it is more like this: the Lua code emits assembly code
         | or LLVM intermediate representation or C source code, then
         | arranges for the assembly code to be assembled (then possibly
         | arranges for the code to be executed, then terminates).
         | 
         | Many years ago, someone wrote a Haskell library along the same
         | lines that lets the library's user mimic assembly language with
         | Haskell code. One thing I particularly liked about this library
         | is that (by deviating a little from the standard way of
         | indenting Haskell code) the user could mimic the 2 columns of
         | assembly language. E.g., in                 foo <-  statement
         | statement2       bar <-  statement3
         | 
         | "foo" and "bar" would be a labels, and that mimics the look of
         | assembly language in that the leftmost 15 or so characters
         | (columns) in an assembly-language file are usually reserved for
         | labels. (I.e., if a line has no label, those 15 characters are
         | blank.)
        
         | eslaught wrote:
         | You can interleave Terra and Lua execution. Terra functions are
         | JITted if you call them from Lua. You can call Lua from Terra
         | too, though the language makes you jump through some hoops to
         | encourage code to avoid Lua dependencies in Terra code. So
         | "execution" is more like you'd expect from standard Lua (or
         | Python or whatever), it's just that functions can be compiled
         | if you want.
         | 
         | Of course Terra functions can also be saved out to a file too,
         | and if you do that they're free of any dependency on Lua (i.e.,
         | no need to like liblua*.so).
        
       | tooltower wrote:
       | I wonder how well it handles or rejects syntax-level expansions.
       | E.g. can the outer language produce half an expression for the
       | next level? Do I need to worry about the common pitfalls of
       | macros?
       | 
       | I hope this works out. C++ has been deliberately evolving in the
       | same direction, e.g. using `if constexpr` for conditional
       | compilation. Plus, since the C++ compiler is aware of both levels
       | of the language, it can catch some errors even for compilation
       | paths not taken.
       | 
       | But the C++ syntax for metaprogramming still leaves a fair bit to
       | be desired. So I like that folks are still experimenting in this
       | area.
        
       | FranchuFranchu wrote:
       | It's like Rust's procedural macros, but more flexible because
       | they're interpreted, right?
        
         | eslaught wrote:
         | Well Rust procedural macros can run arbitrary code, so that's
         | not such a big difference. I'd say the larger one is having
         | access to actual AST data structures available if you want
         | them. Rust forces you to parse the token stream yourself and
         | serialize it again. Also, Terra allows user defined keywords so
         | it's a lot easier to create nice looking DSLs (which is my
         | personal use case).
        
       | a9h74j wrote:
       | Well-presented in the OP.
       | 
       | Dumb question: It was not clearly instruction-set specific; could
       | Terra compile to webassembly? Would one want to?
        
         | eslaught wrote:
         | We use LLVM, so hypothetically yes. I don't think anyone has
         | tried though.
        
       | eslaught wrote:
       | Hi HN,
       | 
       | I help maintain Terra, and also use it to build Regent, my
       | distributed programming language[1].
       | 
       | A bit busy at the moment, but if you leave questions here I'll
       | try to answer them (possibly in some hours).
       | 
       | [1]: regent-lang.org
        
       | hkt wrote:
       | I've been following this for a while and think it is a gorgeous
       | idea. Particularly nice is the fact that one can still use C and
       | C++ libraries from lua, then dip out into Terra for things that
       | require more speed that don't currently have a library.
       | 
       | Lua tying it all together means you have a tiny, dynamically
       | typed language that can be embedded in lots of popular C based
       | software, which can now be accelerated to (even more) incredible
       | speed. I predict big things and wish them well.
        
       | w_t_payne wrote:
       | Is there anything similar for Python?
        
         | canadianfella wrote:
         | Maybe this
         | 
         | https://pypi.org/project/TMPPy/
        
           | w_t_payne wrote:
           | Ooooh! Thank you!
        
       | test9753 wrote:
       | A Singly Linked List implementation in Terra (just testing out):
       | 
       | https://pastebin.com/xt3Wddtu
       | 
       | Output:
       | 
       | https://pastebin.com/KwSTiN8L
        
       ___________________________________________________________________
       (page generated 2021-05-30 23:00 UTC)