[HN Gopher] Nelua Programming Language
       ___________________________________________________________________
        
       Nelua Programming Language
        
       Author : nonbirithm
       Score  : 114 points
       Date   : 2021-08-24 19:38 UTC (3 hours ago)
        
 (HTM) web link (nelua.io)
 (TXT) w3m dump (nelua.io)
        
       | pshirshov wrote:
       | Cool. I didn't find in the docs how do I make higher-kinded types
       | and typeclasses there?.. Could you give me a hint?
        
         | nixpulvis wrote:
         | This language has what looks like a potentially interesting
         | macro system.
        
           | pshirshov wrote:
           | Good macro system is a must, indeed, that's very nice. Though
           | just macro system is not enough.
           | 
           | In order to be useful a language should support a combo of
           | HKTs, typeclasses (better implemented with implicits) _and_
           | macros with implicit materialization. Scala has that (and I'm
           | using Scala) but it has some quirks and problems and I would
           | be really happy to see something with these features but with
           | fast compiler and separated from JVM.
        
             | pull_my_finger wrote:
             | I'm not a Scala user, but are they similar to generics?
             | Nelua has generics[1] and 'concepts'[2]
             | 
             | [1]: https://nelua.io/overview/#generics
             | 
             | [2]: https://nelua.io/overview/#concepts
        
       | 6d65 wrote:
       | I will definitely give it a try.
       | 
       | Even after many years of not using terralang I still cannot
       | forget what a good of an idea it is.
       | 
       | Nelua seems like a more pragmatic implementation of similar
       | ideas, but generates C code instead of embedding the llvm. And
       | doesn't generate code at runtime. But still, things like ecotypes
       | should be possible.
       | 
       | It will be interesting to play with the compile time lua
       | scripting. Also, as mentioned in the other comments not sure
       | about the GC. But there seems to be a manual memory management
       | option.
       | 
       | But still, looks great, kudos to the author, keep up the great
       | work.
       | 
       | PS: If I would implemented it, I would deviate a bit from Lua and
       | replace local with let. It's highly subjective but I think it
       | would make code "prettier"(whatever that means)
        
         | stephen82 wrote:
         | > PS: If I would implemented it, I would deviate a bit from Lua
         | and replace local with let. It's highly subjective but I think
         | it would make code "prettier"(whatever that means)
         | 
         | The idea behind it is to have the lowest syntax barrier
         | possible for Lua developers so they can migrate from Lua to
         | Nelua without a sweat.
        
           | mst wrote:
           | Could you macro up an alias if you wanted to?
        
             | edubart wrote:
             | You could change the language grammar through the
             | preprocessor to accept "let" as an alias for "local". But I
             | recommend people get used to Lua syntax because the
             | metaprogramming will be done in Lua anyway, thus both
             | programming and metaprogramming contexts have similar
             | syntax.
        
       | soapdog wrote:
       | Looks really cool. I wonder how it compares to teal
        
       | bsaul wrote:
       | Is there a way when using those kinds of new languages in a given
       | platform (let's say iOS) to use a modern set of libraries to
       | perform common tasks ( such as http networking, json parsing,
       | websockets, basic multimedia features, etc) ?
       | 
       | Or would i be doomed to rebuild it myself from scraps and random
       | C libs i'd have to gather myself ?
        
         | stephen82 wrote:
         | Well, Eduardo has also created this
         | https://github.com/edubart/nelua-decl
         | 
         | Plus, whatever C library you may have used thus far, you can
         | use it with Nelua as well without a fuss [1].
         | 
         | https://nelua.io/overview/#c-interoperability
        
       | Zababa wrote:
       | The website to present it is beautiful and has all the necessary
       | info, it's great. I also really like the name and logo.
        
         | strappedup wrote:
         | It looks like every other Bootstrap site
        
           | lonk wrote:
           | At least better than brutal design
        
             | [deleted]
        
         | nixpulvis wrote:
         | Documentation needs a better way to navigate by module and
         | ident.
        
       | Svoka wrote:
       | Interesting. If you want to write whole application in Lua-like
       | language, this looks very nice _. However one would need some
       | framework to work with it to make, say a simple game.
       | 
       | _ nice if you are brave enough to use language which wasn't
       | released yet and installs from `master`.
        
       | abraxas wrote:
       | This would be an amazing language to use with one of those SBC
       | boards like Arduino or STM32.
        
       | andrewmcwatters wrote:
       | Seems nice. I don't agree with all of it's deviations from Lua,
       | which unfortunately breaks portability, but I get it.
       | 
       | I wish C was scriptable, versus Lua being compliable, but this is
       | really cool.
        
         | stephen82 wrote:
         | Well, you can still use Lua 5.4 from inside Nelua since it's
         | integrated as part of the backend mechanism for the
         | metaprogramming and not only, therefore I don't think it breaks
         | portability...unless I did not fully understand you correctly.
         | 
         | Can you please clarify a bit more your concern about it?
        
           | newobj wrote:
           | Well, for starters, the arrays are 0-based, so ...
        
             | pull_my_finger wrote:
             | Arrays are 0 based, when tables are implemented they will
             | be indexed from 1. I believe one of Nelua's design goals is
             | that unaltered Lua code will be valid Nelua code.
        
           | andrewmcwatters wrote:
           | It seems like global is a requirement for newindexing on _G
           | (or if _G is even a thing in Nelua) from the documentation
           | unless I'm reading it incorrectly.
        
       | ysleepy wrote:
       | Uses 0-based indexing, if you were wondering like me.
        
         | 7thaccount wrote:
         | I'll never understand why this is such a big item of importance
         | for developers :). Both 0 & 1 are pretty natural in my eyes.
        
           | jimsimmons wrote:
           | Off by one errors are one of the most common type of errors.
           | So it's a real gotcha for most programmers
        
           | IshKebab wrote:
           | I guess it's because there isn't a huge difference but 0
           | definitely _is_ slightly more elegant than 1. And when you
           | 're used to programming with the elegant system it's really
           | jarring to switch to an unusual and slightly worse system.
        
           | 0-_-0 wrote:
           | Because modulo arithmetic needs to include 0, so if you do
           | modulo arithmetic on indices 0 based indexing is better.
        
             | romwell wrote:
             | One solution to that is have inherently modular array
             | indexing, so that any index is valid.
             | 
             | If A[1] is the first element, then A[0] would be the last;
             | etc
        
               | mst wrote:
               | I do appreciate languages that allow -1 for the last
               | index.
        
               | layer8 wrote:
               | That makes it difficult to calculate the distance (length
               | of the slice) between two arbitrary indices though.
        
           | rxhernandez wrote:
           | It can definitely create problems when translating an
           | algorithm from one to the other. I know it was a frustration
           | when I translated algorithms from Matlab to C++.
        
           | lonk wrote:
           | Because 0 is first natural number and 1 is second :P
        
             | dkarl wrote:
             | Very unfortunate choice of terminology in this context.
             | Most of the math textbooks I used in college used "natural
             | numbers" to mean the positive integers. Others used it to
             | mean the nonnegative integers. So the term "natural
             | numbers" presents the same uncertainty to a reader as
             | indexing in an unknown programming language does :-)
        
         | andre-la wrote:
         | Is 0-based like C, but on libraries that reimplements the Lua
         | libraries, it's 1-based as Lua, because the language aims Lua
         | compatibility.
         | 
         | Due to this, the string and "sequence" libraries (which works
         | as a Lua-like vector), and the table library in the future, are
         | 1-based.
        
       | duped wrote:
       | Something I'd like to see more of are GC and memory allocation
       | guarantees, not just an option to disable it.
       | 
       | Most of the time GC is fine as long as it's low enough latency.
       | Where it matters you don't really want _any_ memory management -
       | which isn 't useful, since the memory needs to me managed
       | _somewhere_ in the code. For that reason the pattern isn 't to
       | switch to a non-GC'd language because it doesn't have GC but
       | because you can guarantee all the memory is allocated up front
       | and that no freeing or allocation happens in the tight loops.
       | 
       | That's not actually sufficient though. Even in production code
       | bases accidental allocation can slip through. What you'd really
       | like to see is a `no-alloc:` block which forbids operations that
       | may allocate or free memory - GC'd or otherwise - and force the
       | programmer to allocate before entering the block and free outside
       | it.
        
         | jasperry wrote:
         | I've thought about something like this...that if a compiler
         | could tell that code uses only stack-based allocation, it could
         | turn off GC. Of course, that's very limiting, which is why we
         | need more complicated things like Rust's type system to avoid
         | GC.
        
         | stephen82 wrote:
         | You are free to manage memory yourself, if that is what you
         | mean [1].
         | 
         | [1] https://nelua.io/overview/#memory-management
        
           | duped wrote:
           | That's not really what I meant. The example is showing the
           | problem, the transition to manual memory management just
           | makes it a bit easier to write a program without memory
           | operations in critical sections.
           | 
           | What I'm talking about is a hypothetical language that makes
           | memory operations in critical sections _forbidden_ and
           | considered a compilation error.
        
             | stephen82 wrote:
             | A discussion about GC and memory management can be found
             | here https://github.com/edubart/nelua-lang/discussions/70
             | 
             | Maybe it can answer to some parts of your reasoning? :/
        
       | gautamcgoel wrote:
       | This looks really fucking cool. I've long said that Lua is a neat
       | language, but hobbled by a few warts/footguns. I think this
       | project corrects many of those issues. Does this project provide
       | a package manager with automated dependency resolution? That was
       | an issue in Lua, IIRC.
        
         | stephen82 wrote:
         | About package manager, I don't think it has one yet (at least
         | officially that I know of), but feel free to join discord [1]
         | and ask the core developers about it.
         | 
         | [1] https://discord.gg/7aaGeG7
        
       | ubertaco wrote:
       | > There is no interpreter or VM, all of the code is converted
       | directly into native machine code. This means you can expect
       | better efficiency than Lua. However, this also means that Nelua
       | cannot load code generated at runtime. The user is encouraged to
       | generate code at compile-time using the preprocessor.
       | 
       | Sounds like this is less like Typescript (take the "base"
       | language, add typechecking, and then "transpile" back into the
       | base language) and more like Crystal (take the "base" language,
       | and create a separate language that's similar to it but with
       | static types and AOT compilation)
       | 
       | If you're looking for something more in the Typescript
       | "transpiler" vein, there's Teal (https://github.com/teal-
       | language/tl), written by the guy who created LuaRocks (and htop,
       | interestingly). It still seems a little "early" in its life; it
       | supports most everything you'd need, including some support for
       | Typescript-style "type declaration files" for third-party libs,
       | but it lacks the nice distribution mechanism Typescript grew over
       | time for shipping/installing those declaration files (right now
       | just have to "vendor" them yourself).
        
       | haolez wrote:
       | Looks similar to Terra: https://terralang.org/
        
       ___________________________________________________________________
       (page generated 2021-08-24 23:00 UTC)