Dao (programming language)

Dao (programming language)

Infobox programming language
name = Dao

paradigm = Multi-paradigm
year = 2006
designer = Limin Fu
latest_release_version = dao-1.0-preview
latest_release_date = 2008-04-25
typing = statically typed or dynamically typed
influenced_by = C++, Lua, Python, Perl
operating_system = Cross-platform
license = LGPL
website = http://www.xdao.org

Dao is an object-oriented scripting language with dynamically typed variables supporting complex data structures. It has powerful text processing abilities, such as regular expression matching. It provides a wealth of built-in numerical data types such as complex numbers and multi-dimensional numeric arrays, as well as their corresponding arithmetic operations. Support for multi-threaded programming is also an integrated part of Dao. The Dao interpreter is implemented as a lightweight and efficient virtual register machine (Dao VM) in standard C. The Dao VM can be easily extended with C or C++, through a simple and transparent interface.

Advanced features of the language include:

* A mixed static and dynamic type system with automatic type deduction capabilities
* A flexible macro system that allows definition of new syntax
* Concurrent and distributed programming with message passing interfaces
* Direct embedding of C code into Dao programs

Basics

Hello World

The classic hello world program can be written as follows:

stdio.print ( "Hello world!" )

Here stdio is the standard library to handle input and output. In Dao, there are no built-in functions; all functions are part of a certain library, such as stdio, stdlib, math, coroutine, reflect, mpi (message passing interface), network, and thread.

The stdlib.listmeth routine can be used to display the methods in a library. The methods in math, for example, can be displayed using: stdlib.listmeth ( math )

Data Types

A Dao variable can be implicitly declared by assigning the result of an expression to a variable name.

a_number = 123 a_string = "abc" a_list = { 1, 2, 3 } a_
123, "AB"=>456 } a_tuple1 = ( 123, "ABC" ) a_tuple2 = ( index => 123, name => "ABC" ) # tuple with named items a_vector = [ 1, 2, 3 ] a_matrix = [ 1, 2; 3, 4 ] ">

By default, a variable will have a fixed type that is inferred from the expression that is used to declare the variable; this is called implicit typing. The type of a variable can also be specified explicitly, using the following Pascal-style declaration syntax:

var_typed : "type" var_typed : "type" = "value"

"type" can be one of the following built-in types: int, float, double, string, complex, list, map, tuple, array, buffer, routine, or some composition of these types.

For example:

a_list2 : list<list<float> > a_list3 : list<list<string> > = {} a_map2 : map<string,int> = { "ABC"=>123 } a_tuple1 : tuple<int,string> = ( 123, "ABC" ) a_tuple2 : tupleint,name:string> = ( index => 123, name => "ABC" )

"type" can also be a Dao class name or the name of a user-defined C type. Special keywords for typing include: any for any type , ? for undefined types and @X for a type holder that can be initialized to a certain type in a parameter list.

All typed variables undergo static checking.

Control Flow

If-Elif-Else:

a = math.rand(); if( a > 0.75 ){ a -= 0.75 }elif( a > 0.5 ){ a -= 0.5 }else{ a -= 0.25 } While:

i = 0; while( i < 10 ) i++

For:

for( i=0; i<10; i++ ) stdio.println( i ) for( i=0 : 9 ) stdio.println( i ) for( i=0 : 2 : 9 ) stdio.println( i )

For-in:

a_list = { 1, 2, 3 } for( it in a_list ) stdio.println( it ) a_list2 = { "a", "b", "c" } for( it in a_list; it2 in a_list2 ) stdio.println( it, it2 )

For-in also works for hash.

Switch

a = "abc" switch( a ){ case 1 : a += 123; case "abc" : a += "456" default : stdio.println( "default case" ) }

Functions

The declaration of a basic function (known in Dao as routines) looks like this:

routine foo( a, b : string, c = 123 ) => int { return 456; }

Dao supports first-order functions. The definition of such functions is identical to that of normal function definition, with the following differences:
* there is no need for a function name, but the created function must be assigned to a variable;
* the default value expressions do not need to be constant expressions, as they are evaluated at run time when the function is created;
* the function body may contain variables defined in the "upper" function that creates it.

a = "ABC"; rout = routine( x, y : string, z = a+a ){ a += "_abc"; stdio.println( "lambda ", a ) stdio.println( "lambda ", y ) stdio.println( "lambda ", z ) } rout( 1, "XXX" );

Classes

class MyNumber( value = 0 ) { private my Value = 0; # default value is zero Value = value; public routine setValue( value : int ){ Value = value } routine getValue(){ return Value } }

Macros

Dao macros are defined in the following way:

syntax{ source_syntax_pattern }as{ target_syntax_pattern }

This example enables "while-do-end" without brackets:

syntax{ while $EXP do [ $BL ] end }as{ while( $EXP ){ [ $BL ] } }

Concurrent and Distributed Programming

Asynchronous Function Call

Probably the simplest way to create multi-threaded programs in Dao is to use asynchronous function calls (AFC). The way of using AFC is almost identical to that of normal function calls, with the exception that the keyword async must follow the call.

myfunc( myparams ) async; myobj.mymeth( myparams ) async; Any functions or methods can be invoked in such an asynchronous way.

Normally AFC is executed in a separated native thread, which can be either an idle thread available from the thread pool, or a new thread created on the fly.

Message Passing Interface

With Message Passing Interface APIs provided in library mpi, one can easily do concurrent and distributed programming in Dao. In the MPI library, there are three principal functions: spawn(), send() and receive(). With spawn(), one can create lightweight virtual machine processes or real operation system processes, in the local or remote computers; and with send() and receive(), a process can send messages to or receive messages from other processes.

The process names are of the following form:

virtual_process@real_process@@hostname

"@real_process@@hostname" identifies an operating system process on host "@@hostname", and "virtual_process@real_process@@hostname" identifies a virtual process within "@real_process@@hostname". Message passing can only happen among virtual processes. Each real process has a main virtual process named "self". Any part can be omitted. For example, when "virtual_process" is omitted, it means the "self" virtual process, and "@@hostname" alone identifies the "self" within the operating system process that binds to port 4115 ( D : 4, A : 1, O : 15 ).

# spawn a real process to run script "mpi_script.dao" mpi.spawn( "@pid", "mpi_script.dao" ); # spawn a virtual process to run function "test" mpi.spawn( "vmp@pid", "test" );

# send message to a real process mpi.send( "@pid", "TO MAIN" );

# print a received message stdio.println( mpi.receive() );

# spawn a real process on "@@localhost" to run script "mpi_script.dao" mpi.spawn( "@pid2@@localhost", "mpi_script.dao" ); # spawn a virtual process on "@pid2@@localhost" to run function "test" mpi.spawn( "vmp@pid2@@localhost", "test" ); # send message to the virtual process "vmp@pid2@@localhost" mpi.send( "vmp@pid2@@localhost", "ANOTHER", 123.456 );b

External links

* [http://www.xdao.org Dao Language]
* [http://sourceforge.net/projects/daoscript Daoscript]


Wikimedia Foundation. 2010.

Игры ⚽ Нужно решить контрольную?

Look at other dictionaries:

  • Lua (programming language) — Infobox programming language name = Lua paradigm = Multi paradigm: scripting, imperative, functional year = 1993 designer = Roberto Ierusalimschy Waldemar Celes Luiz Henrique de Figueiredo developer = latest release version = 5.1.4 latest release …   Wikipedia

  • List of Microsoft Windows application programming interfaces and frameworks — The following is a list of Microsoft APIs and frameworks. Contents 1 APIs 1.1 Current 1.2 Deprecated 2 Frameworks 2.1 …   Wikipedia

  • Microsoft Access — Microsoft Office Access 2010 running on Windows 7 Developer(s) Microsoft Corporation …   Wikipedia

  • List of computing and IT abbreviations — This is a list of computing and IT acronyms and abbreviations. Contents: 0–9 A B C D E F G H I J K L M N O P Q R S T U V W X Y …   Wikipedia

  • Microsoft Data Access Components — MDAC redirects here. For other uses, see MDAC (disambiguation). MDAC (Microsoft Data Access Components) Microsoft Corporation s MDAC provides a uniform framework for accessing a variety of data sources on their Windows platform. Developer(s)… …   Wikipedia

  • Visual Basic for Applications — (VBA) Paradigm(s) Multi paradigm Appeared in 1993 Developer Microsoft …   Wikipedia

  • Liste De Sigles — {{{image}}} Sigles d une seule lettre Sigles de deux lettres Sigles de trois lettres AAA à DZZ EAA à HZZ IAA à LZZ MAA à PZZ QAA à TZZ UAA à XZZ YAA à ZZZ …   Wikipédia en Français

  • Liste de sigles — Sigles d’une seule lettre Sigles de deux lettres Sigles de trois lettres Sigles de quatre lettres Sigles de cinq lettres Sigles de six lettres Sigles de sept lettres Sigles de huit lettres Voici une liste des sigles ou acronymes courants. La… …   Wikipédia en Français

  • Liste des sigles — Liste de sigles {{{image}}} Sigles d une seule lettre Sigles de deux lettres Sigles de trois lettres AAA à DZZ EAA à HZZ IAA à LZZ MAA à PZZ QAA à TZZ UAA à XZZ YAA à ZZZ …   Wikipédia en Français

  • Sigle de 7 caractères — Liste de sigles {{{image}}} Sigles d une seule lettre Sigles de deux lettres Sigles de trois lettres AAA à DZZ EAA à HZZ IAA à LZZ MAA à PZZ QAA à TZZ UAA à XZZ YAA à ZZZ …   Wikipédia en Français

Share the article and excerpts

Direct link
Do a right-click on the link above
and select “Copy Link”