Introducing N-Lang

So, I've had these ideas brewing for a while, and thought I'd share it with you all. This is a programming language that I thought of. Please give me your thoughts. Constructive criticism is much appreciated.
1/3
[[$]] example. ;; define namespace.;;->multiline comments. Imports$

Other urls found in this thread:

gitgud.io/m712/nlang/
twitter.com/NSFWRedditGif

2/3
;;-> FunctionsSynopsis: %([name] {arg: type arg: type ...} return type -> function body).Name is optional, but required when directly exporting to registry.You can omit {args} to have no args.arg: type = default_val or arg := default_valUse arg: type... for varargs. The resulting argument will be a type[arglen].Using arg... will make arg a tuple with the remaining args.Omit return type for void.Call a function with no arguments: func!.Call a function with 1 argument: func arg.Call a function with 2+ arguments: func {arg arg arg}.The latter is still one argument (a tuple) which is implicitly converted tomultiple args. You can omit the space between the function name and the arg ifthe arg doesn't start with an alphanumeric character, i.e.printf"Hello World\n". or func{arg arg arg} but not square5. ;;-> Multiline string on the first line is docstring. num*num).;; The dot is not required on oneliners.;;-> Object Oriented Programming}.Example:$ $::printf err::message)}. 0.). You can omit $:: to refer to symbols in the same module, except whenexporting. i.e. $::vector -> or vector -> Creates a new vector with items. you can use special syntax sugar for creating new variables from the result of staticmethods: method var: obj.

3/3
;;-> Operator overloadingThere are 4 kinds of operator overloading in Nlang: - Prefix: $::`op`struct ...). - Unary prefix: $::`op`struct ...). - Unary suffix: $::struct`op` ...). - Suffix: $::struct`op` ...).You can add any kind of operator so long as it isn't alphanumeric.Operators must be used directly adjacent to the identifier.` pop this!).$::vector(T)` Usage of these operatorsvec item Shifts item in.vec> Pops the last item.vec< item Pushes item.Because the operator must be directly adjacent to the object, this does notcause conflicts with other objects' operators.i.e. obj$ ^obj.The default operators [+ - * / %] are special; if they aren't adjacent or theyare not overloaded on either of the objects they perform they try to doarithmetic operations. Prints FizzBuzz until n. {1..n} is a range. It's right hand exclusive by default. If evaluated, it becomes an array. You can define step with {start..end..step}. When range::map is used, this is optimized into a for loop in C code. i%15 == 0? $::printf"FizzBuzz\n" :i%5 == 0? $::printf"Buzz\n" :i%3 == 0? $::printf"Fizz\n" : $::printf{"%d\n" i}. ).).;;-> GeneratorsWhen a function uses the `yield` keyword to return a value, it becomes agenerator. Generators stop execution at the point they yield a value, andcontinue when called again. A generator's variables are static. yield a. a = b. b = a + b. ). a.).

Was C++ not ugly enough for you, OP?

cool logo dude!!!

yeah, since it's only a concept so far, it doesn't really do anything new that justifies the cumbersome syntax or not having while loops

My suggestion is that you write the compiler in rust. Also needs more semicolons.

shut up, Walken

I don't think the syntax is that bad, honestly. It allows for more one liners and more natural feeling code with `verb noun object` syntax sugar, i.e. `push vec item` or `unshift vec!`.

I'm writing a bootstrap transpiler in Python, which I will use to transpile the basic functionality of the transpiler and then work my way up. I'll release 1.0 when it can transpile all language features.

Looks like shit tbqh. Even Rust looks more readable.

...

Does it actually do anything or is it just an alternative syntax with unnecessary symbols that could be 1:1 translated to C by a perl program?

It does memory safety for arrays by storing the length of an array as its first item, and then doing bound checking with every operation that involves array bounds. It also corrects some of C++'s mistakes with object orientation like "methods are not functions with this as the first argument", and adds new operator overloading methods. There's also tuples, which are like arrays but also store type info to store different types of data in the same datastructure.

Addition: This will be a transpiled language to C, which is then fed into gcc or clang.

Why not just do that but following some syntax standard people are used to?

Then how can I be a special snowflake? :^)
Besides, C's syntax is mostly broken anyways.

Then tell us how your syntax fixes C's, because it's not exactly self-evident.

I never said it did. It's a different syntax. It may have its own shortcomings but I like it more.

lol at your "memory safety" that only amounts to bounds checking

...

Syntax is quite bad.

...

Close examination of OP's language leads me to believe that he is a doctor who treats repetitive strain injuries of the hands and wrists, and he's trying to drum up business.

is there a problem that this is a solution to?

The CISC esolang field has stagnated since INTERCAL

Why would I not just use Nim or Rust? Both of those languages have everything that N-lang offers, and more. Also why would you end the line with a decimal? Use a semicolon like every other language, and use // or # for comments. This just seems like a generic C-like language with funny syntax.

Introducing F-Lang 1/3

package example \ define a namespace0 [IF] a multiline comment. We won't be using these because it's better to comment out multiple lines[THEN]\ Importsother-package +order \ adds even private words to search order\ normally we don't do fancy shit with packages. We load libraries and\ packages are mostly used to hide package-internal words. You can open\ a package, modify it with access to its internal words, and then close\ it though:package yet-another-package \ where the package already existspublic: .secret ( -- ) package-secrets 100 dump ;end-package\ Variable declarations and definitionsvariable v15 value v25.2e fvalue f1\ Number types (with a 64-bit environment)-5 . \ signed output: 5-5 u. \ unsigned output: 18446744073709551611-5 -1 d. \ signed 128-bit output: -5-5 -1 ud. \ unsigned 128-bit output: 340282366920938463463374607431768211451-5e f. \ floating point\ specific kinds floating point only matter when working with memory-5e GL-address sf!-5e normal-float f!-5e who-even-uses-these df!123.456.789 \ any dots in non-float indicate a 128-bit number \ some implementations are even more flexible#123 . \ always decimal, decimal output: 123$123 . \ always hex, decimal output: 291%101 . \ always binary, decimal output: 5'c' . \ ASCII value for c, decimal output: 99\ You can convert (not cast) between some types5e f>d d>s \ float to double-sized integer to single-sized (64-bit)\ some other cast-like options are possible when writing to memory\ Arrays\ -- Arrays are not special. They are just contiguous spans of memory.\ Although cache effects and the speeds of different ways of accessing memory\ do mean that arrays are better types than you're perhaps aware.\ fucking lisp fags.create numbers 1 , 2 , 3 ,here numbers cell / constant #numbers \ ex. calculating membershipnumbers ? \ decimal output: 1numbers 1 cells + ? \ decimal output: 2\ Tuples\ Because F-lang gives you precise and explicit control over memory, you\ can do anything you want with it, including this stupid idea about\ heterogeneously-typed arrays, which is a stupid thing to have.\ Structs\ Do not have 'inheritance', although you can nest them in obvious ways.0 1 cells +field cdrconstant listlist 1 cells +field x 1 cells +field yconstant coordinate\ of course you could just use a generic cdr/car list and have car\ contain the address to a two-cell structure containing only the\ coordinates. You could do that if you were gay.\ The search order\ When a name is encountered, that name is looked up in each wordlist\ in the search order, obviously "in order", and then if found a\ function is performed according to that wordlist's definition of the\ word. This is such a simpler and yet more powerful concept than some\ kinda 'registry' that I feel bad for anyone not having it.\ If/else: some-word ( -- ) cond if (true-body) then (the-rest-of-the-word) cond if (true-body) else (false-body) then (the-rest-of-the-word) ;\ Loops\ There are no loops by default, a la Haskell.\ But in the standard library a loop is defined anyway, you fruitcake.\ And the standard library is loaded by default.\ What do you think that means about the default for the language?: some-word ( -- ) begin (test) while (while-case) repeat begin (while-case) (negative-test) until begin (infinite-loop) again \ this is dead code on account of the infinite loop \ but anyway 10 0 do (-this-ten-times) loop 10 0 do i . loop \ outputs: 0 1 2 3 4 5 6 7 8 9 begin (test) while (another-test) while (while-case) repeat then \ as many THENs as additional WHILEs \ that looks crazy? it's just mind-expanding a la Haskell

2/3
\ Functions\ Synopsis: : name ( stack comment ) words it does ; modifiers\ name is required. use :NONAME to create an anonymous word\ Call a function with no arguments: FUNC\ Call a function with 1 argument: FUNC\ Call a function with 2+ arguments: FUNC\ This is advanced shit. You need a computer science degree to\ understand the subtle differences between the previous examples.: square ( n -- n' ) dup * ;\ This could also be written as:: square ( n -- n' ) dup * ;\ Technically ( whatever ) is an inline comment but technically you\ can rape people if you want and it's purely a technicality that\ you'll be caught and thrown in prison. What I'm saying is include\ the comment or you'll be thrown in prison.\ Object Oriented Programmingclass vector variable items variable length : show ( -- ) \ this is a method ." v[ " length @ 0 ?do \ so it has direct access to attributes items @ i cells + ? loop ." ]" ;end-class\ Exceptions42 ( that's an exception code ) throw' some-word-what-may-throw catch\ Example:variable handler: fuck-you-exception true abort" something went wrong lol" ;: bad-word ( -- ) ['] fuck-you-exception handler ! 42 throw ;: main ( -- ) ['] bad-word catch dup if \ oh no BAD-WORD threw an exception! case 42 of handler @ execute endof dup throw \ we don't know about this one, rethrow it endcase else \ nothing happened yay then ;\ You can refer to words by just writing the name of the word\ if you want its execution token instead of actually executing\ it, you can write ' WORD , or ['] WORD within a definition.\ How's that for syntax sugar?vector builds v10 cells buffer: v-itemsv-items v items !:noname ." bugger" ; v items @ !:noname ." me" ; v items @ 1 cells + !2 v length !\ v is now a vector that contains a 10-cell buffer, which contains\ the execution token of a word that says 'bugger', and another\ that says 'me'. v's defined length is 2.\ this VECTOR word is a class that's defined above as an example.\ "Function overloading"vector subclass shy-vector : show ( -- ) ." noooo I don't wanna" ;end-classv show \ example output: v[ 270886848 270886912 ] v addr USING shy-vector show \ output: nooo I don't wanna

3/3
\ Some code examples: fizzbuzz ( -- ) \ it's an exercise defined to print until 100 101 1 do cr i 3 mod 0= i 5 mod 0= 2dup and if ." FizzBuzz" 2drop else if ." Fizz" drop else if ." Buzz" else i . then then then loop ;\ Using 'continuations': call ( cont -- ) >r ;: forever ( -- ) begin [email protected] call again ;: omg ( -- ) forever 5 . ;omg \ output: 5 5 5 5 5 5 5 5 5 5 5 5 ...(and so on)

ah fug I reversed Fizz/Buzz with the original's retarded in-order-of-factors implementation. Now I'll never get a job in programming.

Hmm, I don't like how radically different and complex the syntax is (though the fact that you encapsulated all your design documentation in a code tag doesn't help with readability either), it's like you're trying to remake Perl lol, but I do see some ideas that I like, like the 'registry'... Might incorporate that into my own programming language (I do find it funny how we both came up with strikingly similar ideas for constructors though).
If I were you I'd give functions without arguments a different name like 'procedure'. The 'yield' keyword's behavior is interesting but I think it would be hard to implement.

It's a post-modern parody of Rust. It has some stuff from Perl too.
It's going to be this big philosophy around it.
There isn't really a benefit to it, in fact func! is just $::Function`!`, it's just a postfix operator which does func {}.
Languages like JavaScript and Python have it already, with the same semantics.

I meant in terms of documentation, I think it would be a good distinction to make for beginners learning your language.

I've been doing python for 4 years now and I never knew that, how funny.

Okay then. There isn't even an official spec yet, I'm just trying to squeeze my ideas through the tiny hole of the reality filter.
That came out edgier than I thought
I think it's a Python 3 addition. I have personally never used generators, but it's an interesting feature.

btw update, I finished the lexer and am currently working on the type system and the parser. I do not have very much time nowadays so I can't do much with it yet. I'll put it on gitgud.io after I get Hello World to transpile.

the syntax makes me want to cut myself but what is this language used for OP? what's your goal with it?

dont think OP has thought about more than syntax because op is a nigger

Why should I use this over Myrddin?

Shit syntax, therefore write-only, therefore relegated to esolang status at best, meme status at worst.

Seriously, what's wrong with C-style syntax, and why do all memelangs try so hard to avoid it?

what does that mean?

It's supposed to be a general-purpose language, I guess. I haven't really thought about it. is right. :^)

literally who

syntax is subjective :^)
Let it be an esolang. It's just something I am trying to implement as a programming exercise/hobby. I plan to implement an operating system with it once it matures enough, to become a Parkourdude91 tier ebin trolll xD.

He's suggesting that the language is hard to read and that once you write it, nobody else can read it. He does have a point.

so it's a pleb filter. im ok with this

well technically it's agreed that perl is write-only too, and it's a good language, so :^)
i know, correlation is not causation, let me have some ego you autistic fucks

After long last, an update.
First off, I created a repo to push to for this. Currently only a (half-baked) parser is available, but I'll work on it in my free time to create the rest of the transpiler.
gitgud.io/m712/nlang/

Also, the parser is semi-working. You can feed it statements and some of the language gets processed fine. Currently identifiers, strings, numbers, floats, chars, arrays, most types, pointer types, array types, identifiers, function calls and `method obj arg` syntax sugar works. I'm adding more of the syntax as time goes on.>>> from src.parser import Parser, sparser>>> sparser.type('u8[4]')...>>> sparser.expr('$::printf"Hello World!".')...>>> sparser.expr('1*3+3/7-0')...
The ... is there as placeholder for the lines the lexer spits out for debugging.

>(((formatting))) gets inside code tags
good job cuckmonkey

Dear OP. (ur a phaggot)

These days every good programmer can design a programming language and some companies actually do it for some reason. (projects too)
As long as you don't aim to make a whole compiler yourself you can just rely on compiling your lang to something like barely-readable optimized JavaScript, C, C-- (yes, it's a thing) or to just about any other language depending on runtime you're going to use it in.
Either way, don't expect anyone to adopt your newly designed programming language if you don't give them any reason to nor expect it to land you any job.

OP is having fun making a language. You're the fag here.

Why the fuck would you make the first element in an array the length?
Aren't all elements in an array supposed to have the same length? Or are you confusing arrays with lists?
Why wouldn't you make arrays as structures in C with a length member and a C-array member?

I should be clear with my second sentence. What if what you have is an array of chars that is longer than 256?
Would your array have an int as the first element and then a bunch of chars? That's stupid.

How new are you OP is always a faggot regardless of circumstance. In this case you're confused because is also a faggot.

;; char small_str[5] = {4, 't', 'e', 's', 't'};small_str := "test".;; char long_str[288] = {255, 36, ..., 'e', 'r', 'e'};long_str := "imagine a long string here".;;-> In the transpilernew items: $::vector(u8).len := str::len.$::while %(i32 -> len > u8::max) %(-> push items u8::max. len = len - u8::max.).items::push len.str::map %({c: u8} -> push items c).etc. etc.

M8, I'm not sure you'll get a lot of people to use this. I used to write in assemblers, qbasic, gwbasic, Pascal and derivatives, C and derivatives and so on, and so forth. I gave up after the first part and just skimmed the rest for relevant parts.
The only thing I can advise from what I saw in that snippet from that other thread is dropping this last statement as return value madness. Use an explicit return keyword. Because otherwise just one even marginally hasty edit turns
$::meme sprudo: i32. sprade: i32. sprudo = argv[0] + argv[1]. argv[0]++. argv[1]--. sprade = argv[0] - argv[1]. sprudo * sprade.).
into complete fucking nightmare
$::meme sprudo: i32. sprade: i32. sprudo = argv[0] + argv[1]. argv[0]++. argv[1]--. sprudo * sprade.).
Or even
$::meme sprudo: i32. sprade: i32. sprudo = argv[0] + argv[1]. argv[0]++. argv[1]--. sprade = argv[0] - argv[1].).
or just
$::meme sprudo: i32. sprade: i32. sprudo = argv[0] + argv[1]. argv[0]++. argv[1]--.).

>it'll be memory-safe like rust
It seems like you've at least studied writing of compilers as part of your uni course, maybe even wrote something simple. My advise would be to stop reinventing the wheel for the billionth fucking time.

You should always know what you're returning though, TBF. If you don't want to return anything, just omit the i32 before -> and the function will be void, and the return wrapper won't happen. And again, I'm doing this as a programming exercise/for fun, I don't expect to get a job with it, I don't expect people to like it.

Also, I've made many commits to the git, I can get hello world to transpile 90% now.