Norwegian University of Science and Technology

Global navigation


Differences

This shows you the differences between the selected revision and the current version of the page.

research:diamodl:graphical-editor:user-guide:properties-view 2007/11/07 01:11 research:diamodl:graphical-editor:user-guide:properties-view 2007/11/07 18:03 current
Line 11: Line 11:
=== Functions === === Functions ===
-Functions are used for many purposes, and is the most important property of connections, computations and gates. There are many kinds of functions, e.g. type checking and conversion, getting and setting properties, transforming and filtering lists and more generic script functions.+Functions are used for many purposes, and is the most important property of connections, computations and gates. There are many kinds of functions, e.g. type checking and conversion, getting and setting properties, transforming and filtering lists and more generic script functions.  
 + 
 +The simplest function is the //property getter//. A property getter is defined by means of a property name. The property getter accepts one argument and returns the corresponding property value. Property getters work with both standard Java objects and Ecore instances. 
 + 
 +A related function is the //property setter//. A property setter is defined by means of a property name. The property setter accepts two arguments, an object and a value and sets the corresponding property of the object to the provided value. 
 + 
 +Types (see above) may be used to define type checking and conversion functions. A //type checking// function is defined by means of a single type. Such a function takes one argument and return this argument if it is of the appropriate type. Otherwise it returns null. A //type conversion// function is defined by means of source and target types. Such a function takes one argument and converts and returns this argument to the target type, if it is of the source type. Otherwise it returns null. The type checking function may be thought of as a type converting function with equal source and target types. 
 + 
 +A //mapping function// transforms (maps across) a value of a List type, by calling an element function for each element of the given list and assembling them into a new list. In addition, an element type may be used to filter out values that should not be included. A mapping function is written as '['<element function>':'<element type>']'. The colon and the element type may be omitted. E.g. [propertyName] maps the property getter for 'propertyName' across the list argument. The return value will be a new list with the property value in the same place as the corresponding object in the argument. The Behavior tab provides a special form for the case where the mapping function is a script function. 
 + 
 +A //(Java)script function// is the most complex and generic function type, as it supports using Javascript to implement 'any' computation. Such a function is defined by a set of argument types, the return type and the body code. The body code can either be a simple expression, the value of which is implicitly return, or a full body with braces and containing an explicit return statement. Since the argument list is defined implicitly by the argument types, but no names, the notation $n must be used to refer to argument (value) nr. n (counting from 1). The generic syntax is 'js:'<argtype 1>,<argtype 2,...,<argtype N>'->'<result type>|<body>. E.g. js:String->Integer|$.length() defines a function from String to Integer, that returns the length (number of characters) in the argument string. ('js' stands for Javascript, and is included in the syntax to enable support of several scripting languages. E.g. at some time Diamodl included support for a language named 'pnuts').



2007/11/07 18:03, Hallvard Trætteberg
NTNU, NO-7491 Trondheim. Telephone: +47 73 59 50 00. Contact us
Editorial responsibility: hal@idi.ntnu.no