Operator'ler ve Expression'larOperators and Expressions

This page is part of an incremental translation project. Body text not yet translated to Turkish falls back to English even in TR mode.

OperatorsOperators

Operator'ler, TROIA interpreter'a operand'larını kullanarak bazı mathematical, relational ve logical operation'lar yapmasını söyleyen komutlardır.Operators are the commands which tells the TROIA interpreter to do some mathematical,relational and logical operations using their operands.

Arithmetic Operator'lerArithmetic Operators

OperatorMeaning
+add, string concatenate
-subtract
*multiply
/divide
%module
^power

Relational Operator'lerRelational Operators

OperatorMeaning
==is equal to
!=is not equal to
>is greater than
>=is greater than or equal to
<is less than
<=is less than or equal to

Logical Operator'lerLogical Operators

TROIA code'larında iki logical operator seti vardır. İlk set, if, where, loop vb. condition'larda kullanılan TROIA expression'larıyla ilgilidir.In TROIA codes, there are two set of logical operators. The first set is about TROIA expressions that is used on if, where, loop etc. conditions.

OperatorMeaning
!not
&&and
||or

İkinci logical operator setinin elemanları OR, AND ve NOT'tur. Bu operator'ler TROIA dilinin elemanları değildir, sadece TROIA code'ları içinde yazılan SQL komutlarında kullanılırlar. Bu operator'ler if, where veya loop statement condition'larında vb. desteklenmez. Logical operator olarak kullanılmasalar da, bu isimlerle variable tanımlamak önerilmez.Elements of second logical operator set are OR, AND and NOT. This operators are not elements of TROIA language, they are just used in SQL commands that written inside TROIA codes. This operators are not supported on if, where or loop statement conditions etc. Although these are not used as logical operators, it is not recommended to define variables with this names.

AssignmentAssignment

TROIA'da iki assignment yöntemi vardır. İlk yöntem, source value için expression desteklemeyen MOVE komutunu kullanmaktır.There are two assignment methods in TROIA. First method is using MOVE command, which does not support expressions for source value.

MOVE 'Hello World' TO STRINGVAR1;
MOVE STRINGVAR1 TO STRINGVAR2;
MOVE 3 TO INTEGERVAR1;

MOVE 3 + 1 TO INTEGERVAR1;     /* not valid, no expression support*/
MOVE THIS.F1() TO INTEGERVAR1; /* not valid, no expression support*/

İkinci assignment yöntemi = operatörünü kullanmaktır. Bu yöntem sağ tarafta expression'ları da destekler.Second assignment method is using = operator. This method also supports expressions in right hand side.

STRINGVAR1 = 'Hello World';
STRINGVAR1 = STRINGVAR1 + 'Hello World';
INTEGERVAR1 = 3 * (5 + INTEGERVAR1);

INTEGERVAR1 = ABS(5 - 10);

ExpressionsExpressions

Basitçe bir expression, = operatörünün sağ tarafıdır ve tek bir variable'dan veya birden fazla operator ve function çağrısının kombinasyonundan oluşabilir. Expression'lar yalnızca assignment operation'ları için kullanılmaz. Ayrıca function çağrılarında bir parameter olarak veya bir expression'ın sonucunu döndürmeniz gerektiğinde RETURN komutunda da kullanılırlar. İşte expression destekleyen en çok kullanılan komutların basit bir listesi; bu komutların detayları ilerleyen bölümlerde ele alınacaktır.Simply an expression is right hand side of = operator and it can be consisted of even a single variable or combinations of multiple operators and function calls. Expressions are not for only using assignment operations. They are also used on function calls as a parameter or on RETURN command when you need to return result of an expression. Here is a simple list of mostly used commands that support expressions, details of this commands discussed in next sections.

on function call as function parameter
on IF command condition
on WHILE command condition
on LOOP command condition
on RETURN command
. . .
INTEGERVAR1 = THIS.F1(4+INTEGERVAR2, 'parameter value', P3);

RETURN INTEGERVAR1 + 5;

THIS KeywordTHIS Keyword

Expression'ların en çok kullanılan elemanlarından biri function çağrısıdır. TROIA dilinde, class/dialog'un instance ismini belirtmek zorunludur. Aynı instance'ı belirtmek için THIS keyword'ü kullanılır. Başka bir deyişle, bir method içinde class/dialog'un başka bir method'unu çağırmak istiyorsanız THIS keyword'ünü kullanmalısınız.One of the most used elements of expressions is function call. In TROIA language, specifying instance name of class/dialog is a must. THIS keyword is used for indicating same instance. In other words, if you want to call another method of the class/dialog in its method you must use THIS keyword.

Instance ismi içermeyen bir function çağrısı system function olarak kabul edilir. System function'lar, mathematical operation'lar, string operation'ları gibi en çok kullanılan bazı işlemleri kolaylaştırmak için önceden tanımlanmış function'lardır.A function calls which does not include instance name is considered as a system function. System functions are predefined functions to ease some mostly used operations like mathematical operations, string operations etc.

En çok kullanılan system function'lar ilgili bölümlerde ele alınacaktır, tüm system function'lar için lütfen TROIA Help'e bakınız.Most used system functions will be discussed in related sections, for all system functions please see TROIA Help.

CUSTREC.CALCULATE(P1);   /* call CALCULATE method of CUSTREC object */
THIS.SEARCH(P1);         /* call SEARCH method of same class/dialog */
RESULT = ABS(5 - 10);    /* call a system function                  */

Function/method çağırma hakkında bazı gerçeklerSome facts about calling functions/methods

Çağrılan method'un istediğinden daha fazla parameter göndermek TROIA programming hatası sayılmaz. Sistem sadece fazla parametreleri yok sayar. Daha az parameter gönderirseniz, sistem eksik parametrelere default değerlerini atar.Sending more parameters than called method requests is not considered a TROIA programming error. System just ignores extra parameters. If you send less parameters, system assigns default values to missing parameters.

Son parameter hariç parametreler için default değerleri geçirmek istiyorsanız, parameter'ı boş bırakmalısınız.If you want to pass default values for parameters except last parameter, you must leave parameter empty.

RESULT = MYINS1.CALCULATE(P1,,,P4);

/* send default values to P2 and P3 */

System function çağrılarında, function help'inde belgelenmemişse daha az veya daha fazla parameter göndermek önerilmez.In system function calls, sending less or more parameters is not recommended, if it is not documented in function help.

Type Conversion ve CastingType Conversion and Casting

TROIA'da, simple type variable'lar otomatik olarak cast edilir, bu yüzden type casting için ekstra bir operator veya method yoktur. Örneğin, bir double'ı doğrudan string'e veya bir string'i double bir symbol'e atayabilirsiniz. Sistem type'ları dönüştüremezse, destination symbol'ün default değerini atar.In TROIA, simple typed variables are casted automatically, so there is not an extra operator or method for type casting. For example, you can directly assign an double to string, or a string to a double symbol. If system fails to convert types assigns default value of destination symbol.

TABLE, VECTOR veya class instance'ı gibi complex type'lar için type casting desteklenmez. Aslında, bu complex type'ları atamak olağan bir yöntem değildir, çünkü TROIA'nın özellikle table'lar için complex type'lar arasında data transfer için özel komutları vardır.Type casting is not supported for complex types such as TABLE, VECTOR or class instance. Actually, assigning this complex types is not a usual method, because TROIA has special commands for data transfer between complex types, especially for tables.

OBJECT:
        STRING SOURCESTR,
        DOUBLE DESTDOUBLE,
        INTEGER DESTINT,
        DATE DESTDATE,
        LONG DESTLONG,
        DATETIME DESTDATETIME;

        SOURCESTR = '6.0';

        DESTDOUBLE = SOURCESTR;   /* double is now 6.0 */
        DESTINT = DESTDOUBLE;     /* integet is now 6  */

        SOURCESTR = '25.11.1984';

        DESTDATE = SOURCESTR;     /* date is now 25.11.1984 */
        DESTLONG = DESTDATE;      /* long is now long value of given date */
        DESTDATETIME = DESTLONG;  /* datetime is now 25.11.1984 00:00:00 */
        SOURCESTR = DESTDATETIME; /* string is now '25.11.1984 00:00:00' */

İşte source ve destination simple type'ları arasındaki casting operation'ını gösteren basit bir tablo. Bu tabloda x-ekseni destination variable type'ını, y-ekseni source variable type'ını gösterir. Bu conversion tablosu hem MOVE hem de assignment operatörü için geçerlidir.Here is as simple table that shows casting operation between source and destination simple types. In this table x-axis shows destination variable type and y-axis shows source variable type.This conversion table is valid for both of MOVE and assignment operator.

DESTINATION TYPEDESTINATION TYPEDESTINATION TYPEDESTINATION TYPEDESTINATION TYPEDESTINATION TYPE
STRINGINTEGERLONGDECIMALDATEDATETIME
STRINGparse,if fails-> 0parse,if fails-> 0parse,use . as sep. if fails-> 0.0parse, if fails set NULLDATE(1)parse, if fails set NULLDATE(2)
INTEGERconvert to stringno extra operation, just assignassign int val, use .0 as fractional partadd value as ms. to 01.01.1970add value as ms. to 01.01.1970 00:00:00
LONGconvert to stringassign, if exceeds set->0 (??)assign long val use .0 as fractional partadd value as ms. to 01.01.1970add value as ms. to 01.01.1970 00:00:00
DECIMALconvert to stringassign only whole partassign only whole partadd whole part as ms. to 01.01.1970add whole part as ms. 01.01.1970 00:00:00
DATEconvert to string with dd.MM.YYYY patternassign long value from 01.01.1970 00:00:00assign long value from 01.01.1970 00:00:00not allowed assigns 0uses 00:00:00 as hour part
DATETIMEconvert to string with dd.MM.YYYY
HH:mm:ss
assign long value from 01.01.1970 00:00:00assign long value from 01.01.1970 00:00:00not allowed assigns 0assign only date part

(?) NULLDATE : .(?) NULLDATE : .

(??) Integer'ın Limitleri : .(??) Limits of Integer : .

Alıştırma 1: Integer AritmetiğiExercise 1: Integer Arithmetic

İşte basit bir arithmetic örneği. Lütfen bu örnek üzerinde düşünün ve divide operation'ı aynı olsa bile DECIMALVAR1 ve DECIMALVAR2 değerlerinin neden farklı olduğunu bulmaya çalışın.Here is a simple arithmetic example. Please think on this example and try to find why DECIMALVAR1 and DECIMALVAR2 values are different even if divide operation is same.

OBJECT:
        INTEGER INTEGERVAR1,
        DECIMAL DECIMALVAR1,
        DECIMAL DECIMALVAR2;

INTEGERVAR1 = 3;
INTEGERVAR1 = INTEGERVAR1 * (1 + 2);
INTEGERVAR1 = INTEGERVAR1 ^ 2 + 4;
INTEGERVAR1 = INTEGERVAR1 % 60;

DECIMALVAR1 = INTEGERVAR1 / 6.0;
DECIMALVAR2 = INTEGERVAR1 / 6;