A C-like scripting language.
Here is a small program that iterates and prints the contents of a list:
list fruits = [
"apple",
"banana",
"pear",
"lemon"
];
int i = 0;
while (i < fruits.length)
{
print(fruits[i]);
i += 1;
}Hermes can execute functions written in C. To load a function written in C, you can use the
dloadmethod, to load a function from a shared object file (.so). Example:
dload("librequests.so", "httpget");
string response = httpget("http://example.org")
print(response)Here, the
httpgetfunction was loaded from thelibrequests.sofile. Read more about how to write C methods for Hermes here.
Here is a list of implemented data types:
- list
- int
- bool
- float
- char
- string
- object
- source
list colors = [
"red",
"green",
"blue"
];To add an item to a list:
list names = [];
names.add("john");To remove an item from a list by index
list names = ["john"];
names.remove(0);Everyone knows what an integer is.
int age = 22;Everyone knows what an boolean is.
bool x = 10 > 3;Everyone knows what an float is.
float x = 0.5;char c = 'a';Everyone knows what a string is.
string name = "John Doe";Objects are sort of what you think they are.
object person = {
string name = "john";
int age = 22;
};
print(person.name);Sources are basically objects that represents a parsed source code.
source s = include("examples/functions.he");To have hermes interpret the source, simply use the built-in
visitmethod:
visit(s);Now you can also dump that source to a serialized
.datfile using the built-inwadmethod:
wad(s, "functions");This will create a
functions.datfile. To read the use case for these.datfiles, please read this.
- aprint
- include
- wad
- lad
- visit
- fopen
- fputs
- fclose
- input
- free
Prints what ever you gives it, example:
print("hello world");Prints the adress of a value, example:
object person = {string name = "John Doe";};
aprint(person);Loads an external source file, example:
source s = include("examples/functions.he");Writes an AST compound to disk, example:
source s = include("examples/functions.he");
wad(s, "functions");This creates a
functions.datfile.
Loads an AST compound from disk, example:
source s = lad("functions");Visits and executes a source, example:
source s = include("examples/functions.he");
visit(s);Open a file, here is an example to read the contents of a file:
object file = fopen("examples/functions.he", "r");
string x = file.read();
print(x);
fclose(file);Write string to file, example:
object file = fopen("myfile.txt", "w+");
fputs("hello world", file);
fclose(file);Close file, example:
object file = fopen("myfile.txt", "w+");
fclose(file);Read from user input, stdin:
string a = input("Say something: ");
print("You said: " + a);Deallocates a variable, example:
string x = "hello";
free(x);
To define an anonymous function, name it
@; like this:
void somefunction(void func)
{
func();
}
somefunction(void @(){ print("Hello from anonymous function"); });- new
- iterate
object get_person(string name)
{
object o = {
string name;
};
o.name = name;
return o;
}
object person = new get_person("Hanna");The
newstatement will always return a new address of whatever is to the right of the statement.
void char_iterator(char c)
{
print(c);
}
void list_iterator(string name)
{
print(name);
}
string x = "john doe";
list y = ["john", "sarah", "hannah"];
iterate x with char_iterator;
iterate y with list_iterator;- this
The
thisvariable exists within local scopes. Accessingthiswithin a function will return the address of that function:
void myfunc()
{
print(this);
}
myfunc(); // 0x55824ee44970Accessing
thiswithin a function inside an object will return the address of the object:
object person =
{
void myfunc()
{
print(this);
}
}
person.myfunc(); // { object }Hermes now also support compositions, like this:
int add_2(int x)
{
return x + 2;
}
int remove_1(int x)
{
return x - 1;
}
int mycomp(int x) =
add_2, remove_1;
int x = mycomp(10);
print(x);For loops does not exist, you can acheive the same thing with while loops and we are trying to keep the language simple.
This might not be obvious, but lists can contain any sort of value. Example:
list cool_stuff = [
"this is a string",
{ string x = "Wow, this is an object"; },
[
"a string in a list in a list"
]
];To install Hermes on your system, simple run:
make && sudo make install