Welcome to the NewLang project website!

NewLang — NewLang is a general-purpose high-level programming language with a syntax based on a strict system of grammatical rules.
But with the help of preprocessor macros, the syntax is turned into DSL based on keywords..

Tensor calculations and rationals of unlimited precision are supported at the level of language syntax and basic data types without the use of additional libraries.

The ownership-based memory management model does not require the use of a garbage collector and eliminates major errors at the stage of compiling the source code of the program.

The main properties and features:

  • the ability to work both in interpreter and compiler mode*
  • dynamic and static typing with the ability to specify types explicitly
  • static typing is conditionally strong (there is no automatic type casting, but conversion between some data types is allowed. For example, an integer can be automatically converted to real or rational, but not vice versa)
  • automatic memory management without garbage collector*
  • bject-oriented programming in the form of explicit class inheritance and "duck typing"*
  • several types of functions (regular and pure functions without side effects) are supported at the syntax level of the language
  • optional and named function arguments
  • direct insertion of C/C++ code is possible*
  • easy integration with existing software libraries (including import of native variables, functions and classes* from C/C++).
  • there is a REPL (read-eval-print loop)
  • symbolic calculations**

*) These features are planned for implementation when the compiler is created.
**) Symbolic calculations are supported at the syntax level, but not implemented.

Why do we need NewLang?

All modern programming languages have a constant development (complication) of syntax as new versions are released.
This is a kind of payment for the emergence of new features and is perceived by users as a natural process.

But at the same time it is also a serious problem, since with the release of versions new keywords and syntactic constructions are added, which inevitably raises the entry threshold for new users.

Another consequence of this process is the constant increase in the complexity of developing and supporting already created software products, when the old code is being finalized using the already new standards.

NewLang naturally limits the complexity of language constructs by splitting the syntax of the language into two parts, making it easier to learn and use.

Basic syntax - for writing programs in object-oriented (imperative) and declarative styles, which is based not on reserved keywords, but on a system of strict grammar rules. It is possible to extend the basic syntax through the use of macros.
Extended syntax - program inserts in the implementation language (C / C ++), when the main syntax becomes insufficient.


Another disadvantage of modern languages is that most of them were created before the era of machine learning, therefore, tensor calculations are performed in the form of separate libraries.
The same applies to calculations with unlimited precision, which also require the use of additional library functions.

NewLang has tensor calculus and unlimited-precision rationals out of the box.
They are supported at the syntax level for writing literals of the corresponding types, and simple arithmetic data types are scalars (tensors of dimension zero).
The implementation of tensor calculations is based on the library libtorch, and rational numbers using OpenSSL.

Hello world script example in NewLang


    #!../output/nlc

    printf('Hello, world!');
    
Output:
    Hello, world!
    14

An example of calculating factorial 40 on NewLang (base syntax)


        #!../output/nlc 

        ### Example of calculating factorial of 40 using basic syntax

        fact := 1\1;        # Rational number 1 (no precision limit)
        mult := 40..1..-1?; # Iterator from range for factors from 40 to 2
        [mult ?!] <-> {     # Loop until the iterator data runs out
            fact *= mult !; # Get the current multiplier and move to the next iterator element
        };

        @assert(fact == 815915283247897734345611269596115894272000000000\1);

        fact    # Return final result
    
Output:
    815915283247897734345611269596115894272000000000\1
    

Same code using DSL syntax


        #!../output/nlc 

        ### Example of calculating factorial 40 using DSL syntax

        fact := 1\1;                # Rational number 1 (no precision limit)
        mult := @iter( 40..1..-1 ); # Iterator from range for factors from 40 to 2
        @while( @curr(mult)) {      # Loop until the iterator data runs out
            fact *= @next(mult);    # Get the current multiplier and move to the next iterator element
        };

        @assert(fact == 815915283247897734345611269596115894272000000000\1);

        fact    # Return final result    
    
Output:
    815915283247897734345611269596115894272000000000\1