123
-=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- (c) WidthPadding Industries 1987 0|619|0 -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=- -=+=-
Socoder -> Misc Languages -> Coding in NIL

Thu, 17 Oct 2019, 15:14
Tricky

Coding in NIL


NIL is a programming language I developed myself. Now it more acts like a pre-processor to Lua, than an actual language, however loads of things are significantly different from Lua.
A nice tool to experiment with NIL is QuickNIL which I developed just for that purpose. Though the tool is an .exe file, it uses the .NET Framework, so Linux and Mac users should be able to use it with Mono.

NIL is just a recursive abbreviation standing for "NIL Isn't Lua".

And in order not to break with traditions: HELLO WORLD!


Faculty calculations also come back a lot so let's throw it in:



Now as you can see I combined some elements of C in NIL. Contrary to Lua NIL does require all identifiers to be declared. I chose this approach since I often write script code that easily surpasses over 10,000 lines, and really, tons of bugs that kept up with me for months (so I began to call them cockroaches) came from typos, but the question always is: Where is that typo? NIL tries to look that typo up by itself. Variable declarations and function definitions are pretty similar to C, however unlike C were { and } have to be used, NIL follows the Lua kind of scopes and thus ending with the "end" command. NIL can tell the difference between a variable and a function by the presence/absence of ().

Furthermore, Lua has no real class support. You can "cheat" a bit with tables, and maybe even with metatables. NIL takes that trouble away. Below a simple class in NIL based on the Pythagorean Theorem



Of course, if you prefer the class Lua style with plain tables or even metatables, NIL supports that too (or rather, NIL can just refer to Lua like that and let Lua handle it the way it always did).

The language is far from perfect yet, but I am currently using it in a big project, and it appears to be doing what I ask of it. When it comes to a NIL vs Lua "battle" I'd say the "con" of NIL is that it's by far more restrictive than Lua, where Lua can take pride not to force you into a kind of coding paradigm, where NIL does, however NIL can offer several things in return, that Lua does (by default) not offer. For small scripts that you only want to set up in a few minutes Lua may be the better option. For very big projects with tons of lines of code NIL can (imho) be better.

NIL has been create to interface everything that has been set up in regular Lua code, but also vice versa. Functions and classes set up in NIL, should work in pure Lua too. Properly explaining how would make this post too long, but hey, I hope you like NIL. Now I did in the first place write it for my own benefit, but if more people see the pros of NIL, maybe it can become something
Thu, 17 Oct 2019, 16:34
HoboBen
Looks pythony (in a good way!)

Does it start counting array indexes from 0 like most languages, or 1 like Lua? (Or either, like some BASICs!)

-=-=-
blog | work | code | more code
Fri, 18 Oct 2019, 01:03
Tricky
Since it's a kind of Lua pre-processor it follows the Lua rules in arrays, and thus arrays start with 1. NIL actually doesn't process the arrays and completely leaves that to Lua.

Will translate to:


Now I must say that I created a Linked List library and an alternate array library, and when using the latter 0 is once again the starting point.
Mon, 11 Nov 2019, 15:50
Tricky
In order to elaborate a bit more on things NIL can do, which Lua can't.... Lua has no constant support.... Well, neither has NIL, but NIL does offer something in return, so that way, I can get rid of "magic numbers".


Now the support is not as sophisticated as in C where macros can even have parameters, but some C properties do remain, and that's that macros are always substituted first before compiling the code they are used in, and ANYTHING can be replaces, yes even keywords, so in other words, use these with care. I have the tendency to prefix them all with "__" to avoid conflicts, and yes they do work in string (technically speaking they even work in-comment, but nobody gets to see the result of that)

In my current game (where I use NIL for) is loaded with macros, and it makes my code a lot cleaner and, of course, when I see I gotta change some numbers or other data used a lot, I now only have the change the macro definition, and pop... It changes all over the project... And since you cannot overwrite them it's safer than using a variable (and since they work with code substitution, rather than accessing variable references and are therefore handled when the code is loaded and compiled I think they should be faster than variables, although I think that speed-win is minimal).