You have revealed my true identity...
If you have a look on the page, you'll see that I do worse. I also provide a French version (VO) of the article.
216 karma · joined July 20, 2019
You have revealed my true identity...
If you have a look on the page, you'll see that I do worse. I also provide a French version (VO) of the article.
There are some methods to traverse a UTF8 string:
begin(): to initialize the traversal
end() : is true when the string is fully traversed
next(): which goes to the next character and returns the current character.
s.begin();
while (!s.end()) {
u = s.next();
}This comes at a cost. Every time you extract a sub-string from a string, you have to scan it first for its codepoints, then convert character positions into byte positions. One way to speed up stuff a bit, is to check if the string is in ASCII (see https://lemire.me/blog/2018/05/16/validating-utf-8-strings-u...) and apply regular operator then.
We implemented many techniques based on "intrinsics" instructions to speed up conversions and search in order to avoid scanning for codepoints.
See https://github.com/naver/tamgu/blob/master/src/conversion.cx... for more information.
?X is actually a true Prolog variable that can be unified over and over again. Furtheremore, you can call Tamgu functions from your predicate description, in which these variables can be used if they are unified.
grandparent(?X,?Y) :- parent(?X,?Z), println(?Z), parent(?Z,?Y).
In the case above, the "println", which is not a predicate, will try to display the content of ?Z, if ?Z has been unified.
println could be replaced with a call to an actual function, as long as this function returns true. If the function returns false, then it will be considered as a fail.
println(vector("i" in s));
In this example, I implement a join that takes a vector and transforms it into a string.
//type declaration
<joining:: vector -> string>
//The function itself
<joining(v) = x | x <- v>
println(joining(['a'..'z']));
I provide binaries for Windows, Mac OS, Fedora, Centos and Ubuntu: https://github.com/naver/tamgu/releases
You also have some examples in: https://github.com/naver/tamgu/tree/master/examples
I provide makefiles for all platforms:
Windows: Visual 2013
Mac OS: both command line Makefile and Xcode Makefiles (including the native Mac OS GUI)
Linux: (also for Mac OS), I provide a python script: install.py that determines what is available on your machine and create a Makefile.in.
i = int(s)+10;
Each type can be used as a "function" to create the object you like, which is basically what a cast is...
Well, I did my fair share of programming over the years in so many different languages (Pascal, Cobol, C, C++, Java, Python, APL, Lisp, Prolog, Basic, Small Talk, various assemblers) that I honestly cannot remember all of them.
Tamgu is the result of this experience and my choice was always towards compactness and readability, with Perl being my personal nemesis.
The advantage of this approach is that you don't need to remember a long list of operators, they are simply re-interpreted in context and the re-interpretation is pretty consistent over most of the code.
But, well as the adage goes: Of tastes and colors...
I guess I should have been more explicit. I'm sorry for the confusion.
First, Tamgu is a language in which the recipient variable defines the context in which the instruction is evaluated.
If your recipient variable is an integer then everything on the right side of your assignment will be treated as an integer. If it is a string, well everything will be treated as a string.
We use this approach in many other instances:
int pos;
vector v;
string s="This is a testing case";
pos = "i" in s; //we are looking for "i" in the string
In this case, pos==2.
v = "i" in s; //we are looking for all positions of "i" in the string
v == [2,5,14]
We can therefore apply operations like: [?X|?Z].
Finally, Tamgu considers that the reception variables before the "=" sign define the execution context. Therefore, if we take the following program:
parent ("John", "Peter").
parent ("John", "Mary").
parent ("Peter", "Roland").
parent ("Roland", "Pierre").
bool b = parent("John",?X);
vector v = parent(?X,?Y);
The first case will return "true" if we find a matching occurrence. Here "b==true".
The second case will return all the possibilities that match:
[parent("John", "Peter"),parent("John", "Mary"),parent("Peter", "Roland"),parent("Roland", "Pierre")
Access to each parameter is possible:
v[0] = parent ("John", "Peter")
v[0][1] == "Peter"
v[0].name() == "parent"
string s = 10; s += 20;
What I define is an operation within a string. The context is defined by the recipient variable. In the same way:
int i = 20; i += "30";
The variable "i" defines an integer context and therefore string 30 is considered in this case as a number.