Ya vs C++

Programming Language Ya (pronounce /jˈʌ/) is being created to improve C++, yet to fully preserve and even to extend the domain of applicability. Improvements are invented and gathered from many languages: Ceylon, Scala, Rust, Thelop, JetBrains MPS, XL, P++; and gathered from papers: The Library Scaling Problem and the Limits of Concrete Component Reuse by Ted J. Biggerstaff, Nov 1994 , Steps Toward The Reinvention of Programming, Viewpoints Research Institute, Dec 2007. Features: Blocks by tabs; No keywords; Broad use of signs instead of keywords; Sigils (sign prefixes before idents) speed up code understanding by fast instinct; Metaprogramming: like compile time execution; support for syntax parsers for more than LR(1): new statements and operators and DSL Domain Specific Languages, and so it's simple to implement a language for Graphical User Interface and XML and HTML and .ini; No project files used; Sources are shorter by 20-40%, and even 3 times shorter when specifying or using Domain Specific Languages.

Ya Summary

Block structure is primaryly described by tabs at start of lines, ala in Python. Tabs at start of line are counted and used for specifying code blocks {... }. This feature is even improved by allowing 1-2 chars before the tab to allow prefixed block, as useful for - that works as else inside ? if statement, or works as default: in ||| switch statement. But blocks made by { and } are also supported. However they must follow the same indent by tabs rule. Pervasive use of signs and thus no kewords. Sigils (sign prefixes before identifiers) @ ` % # $ $@ speed up understanding of sigids (sigil+identifier pairs) by fast instinct. ` is a prefix for types: like `0 void, `01 bool, `8 char, `32 int, `.32 float : see [# Types] below. % is a prefix for annexes (modifiers): like %Public, %Private, %C++, %Ya, %Inline; %Outline (yes, real function body and function call could be enforced for a function which is written inside a type declaration, instead of auto inlining). @ is a prefix for modules ie module file names: @C:/Ya/Yaco/Ident.Ya, @Std/StdIo with .Ya auto added if no extension written. # is a prefix for compile time execution items: #? is that is executed during compilationif. C++ also supports compile time execution but only through #define and template-s, feeble for complex cases. $ is a prefix for nonterminals, used to describe syntax parsing ang generation. Syntax is intro into syntax. $@ is a prefix for syntax language name. Sigid started by sigil may continue by digits or signs; but var or function name, which are not prefixed by sigil, should start by usual letter char [A-Za-z] or by _ if digits or signs are required at start. Signs inside sigids are started by sigilled sigid start or by _, and signs of sigid should be terminated by letter or digit or or _. Like _@#$_ is correct var name, while _@#$ is wrongly not terminated. Statement are named by signs: ? ||| * *? ^= |= ^ + ?^ ?+ And many others, like \ for declaring new sigids (variables, functions, types). All statements are greatly enhanced over their C C++ parents, see below. Multiple names for any entity is allowed. Sigids (variables, functions, types) may be named by a number of names. No need to use #define instead. Declaration of a new identifier always starts by \ prefix before each name of identifier, as \M \Min \Minimum =0 `8+*? - which declare 1 variable with names M and Min and Minimum - yes: it could by used by any of 3 names. And note that the type of a var is at the end of declaration. Spaces are meaningful. Expressions: No priorities of operators specified and used. Closer operands and operators are of higher priority. Like 1+2 * 3 & 100h is ((1+2)*3)&0x100. Definition of multinamed variable, function, type requires to use exactly 1 space between names. Numbers are enhanced. As 100h. 20d. 0101b. 111o. 13.25h. 13.25h@-10101b for 0x100; 20; 0b0101; 0o111; 0x1325/16./16.; 0x1325/16./16.*pow(10, -0b10101); Unusual radixes supported: as 9Hwz is 9*(10+'w'-'a') + (10+'H'-'A') Modules, ala #include and no project file. Named modules: \@FileName at the start of each source file. Module name is sigilled (started) by @ and module name is module's file name. Example: @C:/Ya/YaParser.Ya and @Ya/YaParser and @YaParser - all cases are Ok for this file, directory (folder) of file can be specified fully, partially or not at all. And all modules used inside a module are located from the root of module name at start. Header files are not used. Instead dependencies (ala includes) are specified after module name. Like \@"Module Name with Spaces" :@module0 :@module1 :@module2 ... So separate header and implementation for a module does not used, since modules with : prefix after \@ModuleName gets interface of modules into work but not implementation details. No project files used as a result. Each Ya project has main or starting source that is specified for compiler. Main source includes module dependencies at start, so that all required modules will be included and compiled. As a result a separate project file is not required. Syntax description and parsing support. Including implementation and use of DSL. Such as GUI, XML, HTML each of which could be implemented as a library. And allowing broad range of syntax additions - like new statements, complex operators, complex constants for new types, and use of DSL Domain Specific Languages inside Ya code. Support for databases and internal structures like databases - ala SQL - using a library which uses DSL. Ok to write expressions that works with a number of tables, which are sets (f.e. arrays, lists) of fielded type (of class), and perform join where sortby of SQL. In C# it is named LINQ Language Integrated Query. Operators are simple to define. Let's declare = = ie assignment for type `T : \a `T* \= \b `T* `T*.. Both args and return type are specified as pointers - this is since there are no references at all in Ya and since working with pointers is simple, no need to dereference or getting address, all this is automatically inserted. More full checking of types with using of requirements specifications for parameters for types and functions. Also error messages become more appropriate and in time since both requirements and their application when such type or function is used are checked for compatibility to requirements at start of its use, not as in C++ when the use is checked only by production of a valid code from type or function code.

Advantages of Ya vs C++

Already described features are Advantages of Ya vs C C++, but they give rise to other ones. Sources become shorter by 20%-40% than the equivalent С++ code for simple cases; and can be at times shorter when using DSL, as in case of describing Graphical User Interface or accessing XML and HTML. It also makes it easier to make changes. As a result Ya is applicable for any task. This is possible even when some not included extra features are required: they could be added to Ya by implementing DSL Domain Specific Language, as for expert systems; logic programming; GUI through usage of convenient DSL for description of windows layout and content and feedback actions. The only ;) Disadvantage: Ya is very peculiar language, so really requires study. Else Ya code looks as an odd mix of signs, like \P2 \Ptr2 \PtrToPtrToChar `8+*-*- - have you guessed it defines a variable with 3 names of type const pointer to const pointer to unsigned char? Versus now familiar char unsigned *const *const PtrToPtrToChar which is times longer, and with only 1 name, more not supported, yet clear. Yet this deficiency is natural for real improvements. All other features are Advantages ;)

Block structure is described by tabs at start of lines

Like in Python. Tabs at start of line are counted and used for specifying code blocks {... }. But blocks made in single line with { and } are also supported. Typical Ya program has near to no one { and }. 1-2 character prefixes before the tab is also allowed: it just eliminates 1 extra line used by this prefix. See example at ? statement

Statement delimiter dot . is used, more appropriate for statements which are equivalent to phrases, instead of common ;.

And . is not required if no other statement follows. Which is mostly.

Declarations are always started by \ and being declared idents. You see the declared idents first, and so the code is clearer and faster to grok.

And for variables and functions are finished by type: As \IsIt `01 for bool IsIt;

Types

Types use sigil ` . Ya type specification is much shorter than C++'s: no spaces used, no keywords const signed unsigned. Examples show Ya code and the same C++ code, counting characters: `32+*-*- 8 chars vs int unsigned *const*const 25 chars. Type modifiers are always signs, any sign sequence is possible, and arguments are allowed, such as for associative arrays (hashes) which are written for dictionaries like `DictEntry[`8+[]] (here `8+[] is an array of chars with added extra functions for string handling). `8+ unsigned char is used for signed char for working with characters and strings: unsigned is chosen for indexing of arrays by characters and for character comparisons. `8+[] Ya standard library array of unsigned chars and it's descendants `8+[^], `8+[=], `8+[+] are used for strings, using basic arrays (which are not predefined types but ordinary standard library types), not special string type, since Ya arrays support most required features of strings, and string addons are added specifically for character arrays (yes, it's allowed). `8, `8+, `16, `16+, `32, `32+, `64, `64+ are most used integer types, being written 2-5 times shorter than char, unsigned char, short int, unsigned short int, long int, unsigned long int, long long int, unsigned long long int. `I:* is integer with a length of pointer: for use for arithmetic on addresses, like in memory allocators and garbage collectors. `.32, `.64, `._ float, double, long double show by . dot that they are floating point numbers. All types are considered fielded types (so called classes), for example it is possible to inherit from `32. New types similar to typedef are described like here: \`ConstInt32 = `32-. \`PtrToUnsignedChar = `8+*. Keyword class is not used. Instead you just write \`MyClass { body of fielded type } No references &, only pointers * are used. References in C++ is a feature with side-effects and is of value only since no need to write *reference to dereference a reference. But the same is with pointers in Ya, even more, see below. Work with pointers is simple, no need to dereference or getting address, all this is automatically inserted. Example: \ptrptr `32**. \i = ptrptr `32. - here in i = ptrptr; is automatical double dereferencing a pointer. Specification of requirements for args of types and functions is added, like a not included feature of C++ 2011.

Statements use blocks {... } always instead of single statements

Just to prevent eroros. And most blocks are tab specified.

Multiple names for any entity is allowed

Variables, functions, types may be named by a number of names. No need to use #define instead. Example: \Begin \Start \Min `8+* declares a variable of type `8+* = pointer to unsigned char which is usable by any of it's names Begin or Start or Min.

Broad use of signs

Since signs are shorter and no English used. Sigils (sign prefixes before identifiers) @ ` % # $ instantly give the nature of items. \ is a prefix for declarations of smth new: \`MyNewType starts the declaration of the new type `MyNewType; \MyNewVar `01 declares `01 variable MyNewVar. All statements are named by signs instead of keywords: ? ||| * *? ^= ^ + ?^ ?+ - is for else. -? is for else if. | is a case in syntax declaration.

All statements are named by signs and greatly enhanced over their C C++ parents if switch for while do...while break continue #include. Compare:

\`NewTypeName ... <- typedef and class and struct

typedef

	\`StringAsInC = `8*

	typedef char* StringAsInC;
Requires usage of 0-termination. class and struct

	\`MyOwnString
		\At `8+*
		\Len `32+

	struct MyOwnString {
		unsigned char* At;
		unsigned int Len;
	}
Assuming that int is 32 bits. Fields are public by default.

\Var = StartValue `Type <- Type Var = StartValue;


	\Min \Minumum =0; \Max \Maximum = 0FFFFFFFFh `32+
	\CStr0; \CStr1 `8+*

	unsigned int Min=0, Max=0xFFFFFFFF;
	#define Minimum Min
	#define Maximum Max
	unsigned char *CStr0, *CStr1;

Assuming that int is 32 bits. In C type has base and additions, and this additions are to be copied for each variable. In this example * is copied for each variable. Ya supports multiple names for a variable. This could be emulated using #define.

||| <- enum

enum statement is extended:enums are not only `int; but of any type, the type is specified. Example: \`StringEnum ||| `8+[] \Str1 = "lala" \Str2 = "bebe" \`ErraType ||| `8+ // i.e. they are unsigned bytes \eFatal. \eErr. \eWarn. \eMess.

? -? - <- if else if else


	? condition0
		if0 block
	:? condition1
		else if1 block
	:	else block


	if(condidtion0){
		if block
	} else if(condidtion1){
		else if block
	} else {
		else block
	}

Ya code: Note that else block is started by - and tab before else block, thus eliminating the line with only - which is equivalent to } else {. C code: 2 extra lines are used: } else { and terminating } condition0 and condition1 may include variable declaration. ? \arg0 = CommandLineArgs[0] `8+[] // if there are some command line args. process arg0

	char* arg0 = argv[1];
	if(arg0){
		process arg0
	}

//??? надо переделать пример на открытие файла с именем из cmdline

||| <- switch


	||| ex
		case00; case case01; ...
			block for cases0
		case10..case11 // for range of cases
			block for cases1
		:	block for default case


	switch(ex){
		case case00: case case01: ... {
			block for cases0
		}
		case case10: case case11: ... {
			block for cases1
		}
		defaul: {
			block for default case
		}
	}

Each case starts without case or any sign, and terminates without : after case values. Case values can include many values and also ranges value..value, like in 0..3; 7 - this case works for 0,1,2, (no 3 since 3 is not inclusive upper bound), and 7. ||| switch by any type is possible. This is done primarily for strings. Case code is a block, as usual. no ^ break required at the end of each block for casesN since auto exit from the block is entered, eliminating all futile break-s. Yet if next block for cases N+1 should be executed after block for cases N then you are to write + continue at the end of block for cases N.

* <- foreach:


	* \item ∈ SomeArrayOrOtherSequence
		... using item


	// foreach to be added
	foreach(item in SomeArrayOrOtherSequence){
		... using item
	}

Or shorter: * SomeArrayOrOtherSequence ... which is equal to * \it ∈ SomeArrayOrOtherSequence ... so that item is auto named \it

*? <- for and while:


	*? pre; cond; inc
		...


	for(pre; cond; inc){
		...
	}

or

	*?; cond
		...


	while(cond){
		...
	}

; inc or both ; cond; inc or all pre; cond; inc could be omitted. cond may include variable declaration: ??? Код очень неудачный тк не ловит посл арг

	*? \i=0 `8+; \arg = CmdLineArgs[i] `8+[]; ++i
		process next arg of command line


	char* arg;
	for(unsigned char i=1; arg = argv[i]; ++i){
		process next arg of command line
	}

^ for break and + for continue allow breaking from and continuing for multiple levels, and so to remove goto-s used in C C++ world to implement it.

As ^ *?|||* or the same ^ *? ||| * is equal to goto to the end of nested *? (for while do...while) and ||| (switch) and * (foreach) at once. Examples to be written.

*? <- do...while and combined statement ?+ <- if(cond) continue;


	*?
		...
		?+ postCond


	do {
		...
	} while(postCond);

*? <- Pascal repeat...until and combined statement ?^ <- if(cond) break;


	*?
		...
		?^ untilCondition


	repeat
		...
	until untilCondition;

So *? effectively covers all for, while, do...while, repeat...until.

^= <- return

Example:

	\Double `32(\arg `32)
		?= arg*2


	int Double(int arg){
		return arg*2;
	}

@+= <- #include

Example:

	@+= @Gen/Array @Std/
		@IoStream @STL


	#include "Gen/Array.H"
	#include "Std/IoStream.H"
	#include "Std/STL.H"

Support for implementation and usage of DSL Domain Specific Languages allows to extend Ya syntax and to implement another language parser simply.

- Чую надо DSL заменить на синт+парсер гены: а то слова про DSL пусть красивше но не дело Возможность добавлять новые операторы Возможность добавлять новые читалки констов: аля 17:23:00 Возможность добавлять новые нонты: но тут надо придумать хор примеры - ээ! это ж GUI - т.е что пока зову DSL. Ну и др аля GUI надо _список_ целый и тут его по стро на случай

Sources are shorter by 20-40% if common; and up to times shorter if complex.

As for Graphical User Interface, implemented by DSL.

Ya is applicable for any task, extending suitability of C++]: even hard extra features could be implemented, such as for expert systems; logic programming; GUI" href="https://en.wikipedia.org/wiki/Graphical User Interface" href="https://en.wikipedia.org/wiki/Graphical_User_Interface">GUI">Graphical User Interface" href="https://en.wikipedia.org/wiki/Graphical_User_Interface">GUI through usage of designed DSL" href="https://en.wikipedia.org/wiki/Domain-specific Language" href="https://en.wikipedia.org/wiki/Domain-specific_language">DSL">Domain-specific Language" href="https://en.wikipedia.org/wiki/Domain-specific_language">DSL for description of windows layout and content and feedback actions.

== Удобство работы с проектом No project files used. No need: compiler links all compiled modules if it has to. не нужны аля makefiles из-за компила всегда целой проги в которой все зависимости (типа как #include в С С++) указывают на реализации, а headers нет ваще опции компила в сорце сорцах

double compilation: нужны юзы - это принципиально главное

// Некие идеи на Advantages которые выше описаны но тут детали+дополнения+идеи о чом писать

Sources become shorter by 20%-40%

than the equivalent C++ code for simple cases; and can be significantly shorter when using DSL, as in case of describing GUI. It also makes it easier to make changes. Type specification is much shorter, no spaces used, no keywords const signed unsigned, no English words ala `Int. As `01`I:* `32 `64 `8 `8+ `8+[=] `._ `.32 `.64 for bool int with length of pointer int __int64 char unsigned char ArrayL long double float double. Blocks by tabs (similar to Python): removes lines with single }; removes { and } itself; and if { occupies whole line then { line is also removed.

History of Ya

Ya /jˈʌ/ had been started as an attempt to make better C++ with the same applicability for any task, just as C++ allows. Yet Ya significantly changes C++ syntax and adds many extra features: so Ya and C++ are incompatible. Many additions has been invented , and many gathered from languages: [WL Ceylon], [WL Scala], [WL Rust], Thelop, JetBrains Meta Programming System, [WL XL]. Ya is designed to allow clean, expressive, concise and lightweight low ceremonial code to be written. - DSL - new sy - double compilation - не нужны аля makefiles из-за компила всегда целой проги в которой все зависимости (типа как #include в С С++) указывают на реализации, а headers нет ваще - опции компила в сорце сорцах Преимущества Ya: - краткая запись: на 30-50% короче чем на С++ для простых участков; и может быть в разы короче при юзе DSL, как например при описании синта - табблоки - много имён у чего угодно - little ceremonial: мало keywords и их тоже разрешено использовать иначе // не пошло, да и может и неверно - хм, тут бы надо подробней - DSL - new sy - сигилы для подсознательного быстрого понимания - не нужны аля makefiles из-за компила всегда целой проги в которой все зависимости (типа как #include в С С++) указывают на реализации, а headers нет ваще - опции компила в сорце сорцах - requ: контроль за юзом типфй - делат ошибки своевремнными и аккуратными и по сути ошибки - double compilation . statement delimiter is a must only before a statement which starts on the same line after another statement. Else not required but could be used anyway. As a result most statements are without terminating statement delimiter. Note that . is used for standard ;. /* Ya adds to C++: - Double Compilation aka metaprogramming: possibility to execute parts of compiled program during it's compilation; - LOP Language Oriented Programming: supports declaring a syntax and parsing it both on runtime and compile-time. Enables extensible syntax, like adding new statements and operators; - Library for SQL-like requests for processing database-like data including real SQL; - And many small improvements over C++. Ya adds to C++ extensible syntax, extensible lexical tokens, possibility to execute parts of compiled program during it's compilation (metaprogramming, we name it [double compilation]), support for SQL-like operations for processing databases and database-like internal data, and [many small improvements over C++|Basics]. */ !!Example: Hello World Hello World example is here in 2 cases: As it is planned for future: \@HelloWorld.Ya @Std/StdIo/Print; "Hello, %s!\n"; ProgramArgs/Length > 1 ? ProgramArgs[1] : "World" And as it is already implemented in current compiler: \@HelloWorld.Ya // each module starts by specifying it's name which is file name. Module names are @...s, sigil @ is used for not confusing modules with ids, types... \ specifies a definition of sigil ident that is after \, ie of module @HelloWorld.Ya here. Use @stdio.h // to use printf // это не сработает тк .h будут парсить как Ya, а надо пронести на выход. хм, это ныне не решаемо. %С++ `Int \main(`Int \argc; `Char* \argv) // %C++ specify calling convention. Type name is sigilled `type_name. Array is a library defined type, not a predefined language type. \ before name specifies that it's definition of name: all definitions are always prefixed by \. `Char* \name = argc > 1 ? argv[1] : "World\0"/Min // so program says Hello to start arg in command line if it exists, else to World. World is appended by 0 to make it 0-terminated, as usual for C C++ yet not for Ya where arrays used instead and no trailing 0es. printf("Hello, %s!"/Min; name) // "string"/Min is used to access data field of a start of this string. Ret 0 - In Ya each program first initializes static variables and then executes function main, just like as in C C++. ???- Yet main in Ya differs in its args: there are no separate int argv, char** argc args but `char[][] args : array of strings, which are arrays of chars themselfs. - Function Print is used for outing formatted text. First param specifies a file. It's not specified here, see ; after Print(, so default param value is used, which is Std.Out, that is C's stdout. Note that use of defaults is possible for any param, including first one, even if some next param is specified. - This program outputs to stdout "Hello, World!" if executed with no params. If with params, then it outputs "Hello, " and first param and "!". Other examples see at [Examples of programs|Examples].

Basics of Ya

- Operator precedence in expressions: in Ya spaces around operators are counted and it's used for defining precedence. Example: 1+2 * 3; - it's (1+2) * 3; since no spaces in +2 and 1 space in 2 *. Author's experience shows that it's extremely useful when forgotting operator precedences and also to write less parentheses in simple cases like with * / + -. - ` сигил типов: для фй включает арги и потому арги это явно часть типа а не неявно как в C C++ Java C# где арги пишут после имени ф: тут пример - числа в многих системах счисления - простые примеры примеры на ints: - примеры на FP: - сложные примеры на ints: - сложные примеры на FP: ?