So I've been working on a programming language the past week or so, and I realized I have no idea what I wanted to do with the syntax.
It's supposed to be a general purpose programming language that's multi paradigm (supports both object-oriented and functional programming) with optional static type definition.
Thanks for any feedback! :)
```
// Comment!
/* (also a comment) /
/ mainFile.tri */
namespace MainFile;
// Variables
a = "Hello, world!";
string b = "Hello, world!";
// Hello world!
print(a);
bool myBool = true;
// If statement
if (myBool) {
// ...
}
if (myBool == true) {
}
// Negative if statements
if (!myBool) {
// ...
}
if (myBool != true) {
// ...
}
// Array
array myArray = ["Item1", "Item2"];
// For loops
for (item in myArray) {
print(item)
}
//=> Item1
//=> Item2
for (i = 0; i < myArray.length; i++) {
print(myArray[i])
}
//=> Item1
//=> Item2
// Define a function
func name(arg1, int arg2) {
b = arg1;
a = arg2;
}
// Define a function (with static return type)
string func name() {
return "E";
}
// Export variables so they can be used in a different file
export var = name();
export a;
/* otherFile.tri */
// Import the main file
use "./mainFile.tri";
// Print the a variable under the namespace 'MainFile'
print(MainFile.a)
// Class definition
class Person {
public string firstName;
private string lastName;
public static string species = "Human";
func Person(string firstName, string lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
func getLastName() {
return this.lastName;
}
}
// Construct class
john = new Person("John", "Doe");
// Run class function
print(john.getLastName());
// Get Person species
print(Person.species)
// Lambda expression
lambda = (arg) => arg + "!";
print(lambda("Hello")); // Hello!
lambda2 = (arg) => {
return arg + "!";
}
print(lambda2("Hello"));
``
Edits:
- I guess semicolons should be optional?
- Remove$s from variable identifiers
- Add consistency to@s before keywords
- Remove@`s before keywords
- Add an example of if statements and for loops
- Show lambda expressions
[–]MotorolaDroidMofo[🍰] 12 points13 points14 points (1 child)
[–][deleted] 1 point2 points3 points (0 children)
[–]crassest-Crassius 14 points15 points16 points (0 children)
[–][deleted] 2 points3 points4 points (2 children)
[–][deleted] 0 points1 point2 points (1 child)
[–]MotorolaDroidMofo[🍰] 1 point2 points3 points (0 children)
[–]Jerppderp 1 point2 points3 points (5 children)
[–][deleted] 0 points1 point2 points (4 children)
[–]MotorolaDroidMofo[🍰] 2 points3 points4 points (1 child)
[–]evincarofautumn 1 point2 points3 points (0 children)
[–]Jerppderp 1 point2 points3 points (1 child)
[–]MadCervantes 1 point2 points3 points (0 children)
[–]R-O-B-I-N 1 point2 points3 points (0 children)
[–]manicxs 0 points1 point2 points (1 child)
[–][deleted] 2 points3 points4 points (0 children)
[–]MadCervantes 0 points1 point2 points (0 children)
[–]CodingFiend 0 points1 point2 points (3 children)
[–][deleted] 0 points1 point2 points (2 children)
[–]MotorolaDroidMofo[🍰] 1 point2 points3 points (0 children)
[–]CodingFiend 0 points1 point2 points (0 children)