Tamgu(탐구)是一个函数式、命令式与逻辑一体化(FIL,Functional、Imperative、Logical)的编程语言,主要用于注解和数据扩充。
Tamgu 是一种多线程编程语言,特征包括:
- 接近 Python 的命令式风格,但具有强大的类型系统。
- 受 Haskell 启发的函数式风格,可自由地与命令式范式相结合。
- 由 Prolog 启发的逻辑风格,可以自由地与命令式和函数式范式相结合。
使用 Tamgu,可以对于编程中的每个特定问题,选择最合适的形式,并自由地混合函数式、命令式和逻辑方法,以实现最具表现力但最紧凑的代码。
此外,Tamgu 还提供了一个注解语言实现,它提供了一个结合了词汇和规则的综合规则机制,允许以有效的方式检测文本中的复杂模式。它提供了许多功能,同时也提供了许多库,有助于设计和实现复杂文档的注解方案。
Code Example
//An imperative language
int i=10;
string s="20";
------------------------------------------------------------------------------------
//Containers
map m = {'a':1, 'b':2}; //all sorts of containers
treemap t = {"u":10, 'v':'toto'};
vector v = [1,2,3,"a","b"];
ivector iv = [1..10]; //iv = [1,2,3,4,5,6,7,8,9,10]
iv = [1,3..10]; //iv = [1,3,5,9]
------------------------------------------------------------------------------------
//Functions, threads and frames
function mycall(int i, string s) {...} //functions
thread mythread(int i, string s) {...} //threads
frame myclass {...} //class definition
------------------------------------------------------------------------------------
//Native Korean string support
s="에버랜드 알쏭달쏭 Quiz";
if (s[0].ishangul()) println("Ok");
uvector dec = s.jamo(); //['ᄋ','ᅦ','ᄇ','ᅥ','ᄅ','ᅢ','ᆫ','ᄃ','ᅳ'...]
dec = s.romanization(); //['-/ng','e','b','eo','r/l','ae','n','d',...]
------------------------------------------------------------------------------------
//Functional approach based on Haskell
ivector iv = [1..20]; //a list of integers between 1 and 20
iv.shuffle(); //The order of the elements is now random.
; //if the list is empty, we return an empty "list"
), //we sort the list with elements smaller than fv
let maxlist = fastsort(fv) v>)>; //we sort the list with elements larger than fv
//we can call a functional definition as regular code
v=fastsort(iv);
------------------------------------------------------------------------------------
//Predicates
concat([],?X,?X).
concat([?H|?T],?Y, [?H|?Z]) :- concat(?T,?Y,?Z).
//You can mix freely your predicate definition with some regular tamgu code
v=concat(["english",'russian',"french"],['spanish'],?L);
println(v); //["english",'russian',"french","spanish"]
注解示例
//We define some lexical rules (starting with a "@")
@food <- burger.
@food <- tartare.
//Our rule: if "the food" word is found in a sentence, then we return a "meal" label
meal <- "the", #food.
//We need a specific object to scan a sentence
annotator r;
//a sentence
string
vector v = r.parse(sentence);
//Result: v = [['meal',[10,16]],['meal',[25,32]]]
//It reads: two 'meal' were found at position 10-16 and position 25-32...