# outline **Repository Path**: will-captain/outline ## Basic Information - **Project Name**: outline - **Description**: 基于轮廓(outline)的大模型原生编程语言 - **Primary Language**: Unknown - **License**: Apache-2.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 0 - **Forks**: 0 - **Created**: 2023-03-16 - **Last Updated**: 2025-01-06 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # outline编程语言白皮书 #### 介绍 outline是基于轮廓(outline)的一门推导式编程语言。 语言特性设计主要特征包括: 1. 基于轮廓的推导:符合函数申明,对象申明的变量传递都可强类型识别。将例如java的is关系变为ducktyping关系转换 2. 函数式编程为主导:函数符合x->y->z式声明,所有函数均只有一个入参和一个返回值。作用域内同名重载函数为函数的多态,函数可通过|关键字做参数条件路由,通过||来做韧性降级。 3. 大模型原生支持:注释元数据+响应式 4. 声明:let/var identifier:类型 #### key word outline, fx, class, module int, float, double, decimal, string, enum export, import #### type system ##### virtual type type typeof(type) is (category:virtual, name:type, super:_,abstract:true);//abstract means cant be used in programming ##### basic type number/text/():type () which is empty tuple typeof(number) is (category:basic, name:number, super:type); typeof(text) is (category:basic, name:text, super:type); typeof(())) is (category:basic, name:tuple, super:type); super:type means the type could be used in outline, but can't be instantiated int/float/double/decimal/byte/bit/bool:number string/char:text typeof(int/float/....) is (category:basic,name:int/...,super:number,position:stack,len:1/8/...) typeof(string) is (type:basic,name:string,super:text,position:heap,len:_) typeof(char) is (type:basic,name:char,super:text,position:stack,len:8) **_all types from basic type will be declared like this : let/var abc:number/int/string_** ##### meta type typeof(outline) is (category:meta, name:outline, super:type); **_outline_** : specification of other meta type outline only use base type,[],{},(),'get','set',',',':':'->' to construct outline |type| specification in outline | |:------|:------------------------ | |tuple| (string, int, (string,int)->int,(string, string))| |enum | {male(age:int, name:string,fight:()->()); female(age:int,name:string,smile:()->()); unknown(int)} | |fx| (string,int)->string| |prop| string{get;set;} |class| {smile: ()->()); age:int{get;}}| |module| same as class specification| **_all other outline type is a form of outline_** 1. func_spec is: (type(,type)*)-> type 2. prop_spec is: type{get;set;} 3. tuple_spec is: (((key:)?type(,(key:)?type)*)?) 4. enum_spec is:{(key(type?);)*} Meta Data of different outlines: 1. typeof((int,int)->int) is (category:meta,name:func_outline,super:outline,class:func_decl,spec:(arguments:[int,int],return:int)) 2. typeof(int{get,set}) is (category:meta,name:prop_outline,super:outline,class:prop_decl,spec:(type:int,operator:[get,set])) 3. typeof((name:string,age:int)) is (category:meta,name:tuple_outline,super:outline,class:tuple_decl,spec:([("name",string),("age",int)])) 4. enum: detail in enum description 5. class.... 6. moudle.... ##### custom type **_all custom type will be declared like this : func/class/module abd ....._** an implementation of particular outline is a custom type func|class|module id (:outline)?{|( statements )|} **_note:in custom type definition from type of type, keyword could be ignored_** calss some_class{...} == some_class{...} #### tuple ```` //anonymouse tuple let somebody = ("will",47,()->console.log("laughing")) let (name,age,action) = somebody; //name is "will" and age is 47 and action() will print "laughing" let somebody = (name:"will", age:47, laugh:()->console.log("laughing")); //somebody.name is "will" and somebody.age is 47 and somebody.laugh() will print "laughing" outline human:(name:(last_name:string, first_name:string), age:int); let somebody:human = (("will","zhang"),47); let somebody:human = ("will","zhang");//will raise type error ```` #### enum #### outline ##### outline constraint ```` outline add: (int,int)->int; outline strict add: (int,int)->int; ```` ##### outline for function ```` outline add_outline: (int,int)->int;//this implys that the outline is based on an anonymous outline (int,int)->int outline prop_get_outline: string{get;} outline change_property_outline: obj_outline->();//means return void outline tuple_return: string->(string,string);//use tuple to return multi value outline object_return: string->{name:string{get;},title:string{get;}};//use object to return multi value, difference is object has property name ```` ##### outline for tuple ```` outline pair: (string,string); outline named_tuple: (name:string,age:int,weight:float); outline nest_tuple: ((string,string),int); ```` ##### outline for object ```` outline root_outline:{ id:string{get;} age:int{get;} } ```` ##### referee outline ```` outline obj_outline: { name:string{get;set;} do_something:string->string; parent:root_outline{get;};//refer root_outline get_parent:()->root_outline;//another way to refer outline } ```` ##### nested outline ```` outline human_outline:{ age:int{get;}; arm:{ len:int{get;} side:string{get;} } } ```` #### property ```` prop name:string{//same as name:string{...} get; set; } ```` #### function ##### function declaration ###### function with return type reference ```` func add(x:int, y:int) x+y;//function declaration //or func add(x:int, y:int){//same as add(x:int, y:int)... return x+y; } let add = (x:int, y:int) x+y;//function expression ```` ###### function with return type declaration ```` func add(x:int, y:int)->int{ return x+y; } ````` ##### multi-value function declaration ```` func tuple_return_func(name:string)->(string,string){ return (name,name); } func tuple_return_func:tuple_return(name) (name,name); func obj_return_func(name)->{name:string{get;},title:string{get;}}{ } ```` ##### curry function ```` //(int,int)->int actual specification is: int->int->int func add(x:int,y:int) x+y; //is actually like below: func add(x:int){ return (y:int)->x+y; } //we can say: add(3,4) equals to add(3)(4) let add3 = add(3); //or func add3->add(3); ```` ##### function polymorphism ###### arguments range polymorphism with "when" ```` func add(x:int, y:int) abs(x)+y when x<0; //default function without "when" is necessary func add(x:int, y:int) x+y; ```` ###### outline polymorphism ```` outline strict add_outline: (int,int)->int; outline add_outline_loose: (int,int)->int; func add:add_outline(x, y) x+y; func add1:add_outline(x, y) x+y+100; func add2(x:int, y:int) x+y;//it is actually based on an anonymous outline (int,int)->int func invoke_anonymous(my_add:(int,int)->int, x:int, y:int) my_add(x,y); invoke_anonymous(add);//legal invoke_anonymous(add1);//legal invoke_anonymous(add2);//legal func invoke_outline(my_add:add_outline, x:int, y:int)->my_add(x,y); invoke_anonymous(add);//legal invoke_anonymous(add1);//legal invoke_anonymous(add2);//illegal, add2 is not based on strict outline, should comply the type; func invoke_outline_loose(my_add:add_outline_loose, x:int, y:int)->my_add(x,y); invoke_anonymous(add);//legal invoke_anonymous(add1);//legal invoke_anonymous(add2);//legal, add2 is based on loose outline ```` ##### degradation/altnative with "enhance" ```` //substract is degradataion function of add func substract1(x:int,y:int) x-y enhance add(x,-y)|substract; ```` #### single function aop with "before" and "after" func check(x:int, y:int)->bool{ return true; } before add(x,-y)| func polish(z:int)->int{ return z; } after add **_ -z,-y means paramter could be modified_** ##### closure function ```` func multiply_and_add(x:int,y:int,z:int)->{ let multiply = (a:int,b:int) a*b; let add = func(a:int, b:int) a+b; return x|>multiply(y)|>add(z);//add(multiply(x,y),z); return add(x)<|multiply(y)<|z;//add(x,multiply(y,z)); } ```` ##### immediately-invoked function expression (IIFE) ```` let result = ((x:int,y:int) x+y)(5,6);//result = 11; ```` ##### function flow ###### function pipe ```` data|>func1|>func2;//left to right opertor: fun2(func1(data)) ```` ###### function composition ```` fun2<|func1<|data;//right to left operator: func2(func1(data)) ```` #### class ##### declaration of class without constraint ```` class some_class{//same as some_class without class keyword _name:string; mut _age:int;//_age is changeable constructor(name:string,age:int){ this._name = name;//first assign, can't be changed anymore this._age = age; } do_something(){ } } export {some_class} ```` 1. there is no field in class 2. there is closure variant in class 3. use let to declare a readonly variant, and use var to declare a mutable variant 4. _method is protected 5. method is public 6. method is always virtual 7. name{get:(){} _set:(v){}} means getter of name is public and setter of name is protected 8. export will allow other lib to access the class ##### declaration of class under outline constraint ```` class obj_class:obj_outline{ let _name = null; // same as let _name:string = "my name"; name:string{//same as prop name get:()->this._name; set: value->this._name = value; } do_something(name:string){//same as func do_something _name = `my name is ${name}`; return _name; } constructor(name){ _name = name;//constructor is able to set null mutable variant } flatten()->(...){ } } ```` ##### closure class ```` class some_class{ get_parent(){ //closure class let parent = root_outline{ ...implementation constructor(x:int,y:int){...} } return parent(1,2); } }; ```` ##### anonymous class and IIFE ```` class some_class{ get_parent(){ return (root_outline{ ...implementation constructor(x:int,y:int){...} })(1,2); } }; ```` ##### instantiation of class ```` let obj = obj_class("somebody"); obj.do_something(...); ```` #### module module is a singleton object, will be initialized by system ##### declaration of module ```` module obj_module:obj_outline{//same as obj_module withoud module keyword //.....same as class //only have one initializer with no args initializer(){ this._name = config.get("name"); } } **__module specification is same as class, difference is that module has inializer and class has constructor__** ```` ##### use module ```` obj_module.do_something(...); ```` #### meta programming //function generic func asy_call(fx:(...A)->R)->((...A)->promise){ return async (...arg:A)->R{ console.log("before invoke"); let result =fx(...arg); console.log(`the result is ${result}`); return result; } } func add(x:int, y:int) x+y; match asy_call(add)(10,10) { then(x){ ... } error(e){ } } class exceptional{ let fx; var thenfx,errfx; constructor(fx:(...A)->R); then(thenfx:R->())){ } error(errfx:exception->())); } func try(fx:(...A)->R)->((...A)->exceptional){ let ex = exceptional(fx); try{ fx } } //object generic class flowable{ let data:T[]; var action; constructor(data);//by default, data will assgin to data map(fx:T->R){ let result = R[]; data.forEach((d,i){ result.push(fx(d)); }) return result; } subscribe(fx:) } ```` #### outline inference ##### function inference ```` func add(x:int,y:int)->x+y; function use_add(my_add:(int,int)->int,x:int,y:int)->my_add(x,y);//my_add is an anonymous function outline ```` ##### object inference todo ```` class human{ } ```` #### modifier 1. there is no 'private' concept 2. function/property: _somefunction is accessable in the file; somefunction is accessable in the lib 3. class: _someclass is accessable in the file, someclass is accessable in the lib 4. in class/module: _method is protected, method is public 5. export: for function/property/class/module, is public to other lib, without export all functions/properties/classes/modules is not accessable by other libs 6. import is same as java import, c# using 7. #### declaration there is no to-level variant. all let/var must be in function. all top level states should be modules ##### common type variant declaration ```` let number = 0;//mutable let someone:string = ""this is me;//:string can be ignored var numbr = 0;//immutable ````