![]() |
|
If you were to design a programming language, what would it be like? - Printable Version +- Sinisterly (https://sinister.ly) +-- Forum: Coding (https://sinister.ly/Forum-Coding) +--- Forum: Coding (https://sinister.ly/Forum-Coding--71) +--- Thread: If you were to design a programming language, what would it be like? (/Thread-If-you-were-to-design-a-programming-language-what-would-it-be-like) |
If you were to design a programming language, what would it be like? - Blink - 07-26-2017 Make multiple entries, whatever you want. At the top of your post, please state what the language is deigned for (Ex: Stats, Esoteric, Web Back end, Simple Scripting, larger programs, etc.) Please provide example code written in the language, illustrating the syntax, features, and whatever else. I'll post a few ideas when I get on my laptop. If yo DO NOT want your ideas used anywhere else, you should say so at the bottom of your post(s). RE: If you were to design a programming language, what would it be like? - Blink - 07-26-2017 Purpose: Scripting (nothing heavy) Code: /*
Nearly everything is a 'function', or in this case, a compound
Stuff within parenthesis get executed like an 'anonymous function'
Everything has a return value
Everything is passed to a function as a list. If a list has only 1 item, it can be treated as a normal variable
*/
import [uselesscrap.lib]
/* .lib will look for installed libraries, .b will look for built-in libraries, and .lo will look for local files */
int x = 1 //Assignment, returns @x (you'll learn this later)
str z = "Hello" //Assignment, returns @z
/*Curly brackets/braces are used for passing code to execute. >> starts a multiline block*/
/*If syntax: `if [boolean, stuff to do, else other stuff]` or `if [boolean, stuff to do, boolean, stuff to do]` or just `if [boolean, stuff to do]`*/
/*You can also do this: if [boolean, stuff to do else stuff to do*/
if [(x == 1), { >>
print["hi"]
}, {
print["no"]
}]<< //<< ends multiline block (I'll show you why this is unnecessary later)
/* Anonymous variables? I might keep, might not if I make it. "com" is short for compound, which will also work */
com duoAdd[(int add1[int *, int *, int *]), (int add2[3])] { //Tip: {} is multiline by default
int z
int x
fore [(int f), (add1), {z += f} ::[@z]] //for each. Variable z is passed into the scope of the fore call
fore [(int f), (add2), {em:x += f} ::em[@x]] //named scope. f doesn't carry over from last call.
return[z, x] //Yes, return is also a compound, so a list gets passed to it
}
add[[1, 2][3, 4]] //should return [3, 7]Spoiler: cleaner
Version without comments: Code: import [uselesscrap.lib]
int x = 1
str z = "Hello"
if [(x == 1), { >>
print["hi"]
}, {
print["no"]
}]<<
com duoAdd[(int add1[int *, int *, int *]), (int add2[3])] {
int z
int x
fore [(int f), (add1), {z += f} ::[@z]]
fore [(int f), (add2), {em:x += f} ::em[@x]]
return[z, x]
}
add[[1, 2][3, 4]]I might actually implement this Just better, because this is shit rn. RE: If you were to design a programming language, what would it be like? - apb - 07-31-2017 I've wanted to take the lazy parts of imperitive, oo, and functional code design and make a hobby language. The main ideas would be: - syntax is completely configurable. use newlines to end statements if you want, use ; if you want, changing them should be easy. - grouping symbols group things. () are only used to change the order of evaluation. [] form an array. <> form a vector. {} form a map. - everything has at least one type. primatives have one, functions and groups have two, one for domain and one for codomain, and tuples have one for each element. - array indices are arbitrary. start at zero with type `int[0,10]` or one with `int[1,11]` - operators are functions. functions should be arbitrarily fixed, prefix infix or postfix are all allowed and overloadable. Todo: flow control, classes. This is just supposed to remove common programming annoyances and be fun to use :3 |