Go to the first, previous, next, last section, table of contents.

## Syntax -- Difference from C language

The syntax of Asir is based on C language. Main differences are as follows. In this section, a variable does not mean an indeterminate, but a program variable which is written by a string which begins with a capital alphabetical letter in Asir.

- No types for variables.
  As is already mentioned, any object in Asir has their respective types. A program variable, however, is type-less, that is, any typed object can be assigned to it.

      [0] A = 1;
      1
      [1] type(A);
      1
      [2] A = [1,2,3];
      [1,2,3]
      [3] type(A);
      4

- Variables, together with formal parameters, in a function (procedure) are all local to the function by default.
  Variables can be global at the top level, if they are declared with the key word `extern`. Thus, the scope rule of Asir is very simple. There are only two types of variables: global variables and local variables. A name that is input to the Asir's prompt at the top level is denotes a global variable commonly accessed at the top level. In a function (procedure) the following rules are applied.
  1. If a variable is declared as global by an `extern` statement in a function, the variable used in that function denotes a global variable at the top level. Furthermore, if a variable in a function is preceded by an `extern` declaration outside the function but in a file where the function is defined, all the appearance of that variable in the same file denote commonly a global variable at the top level.
  2. A variable in a function is local to that function, if it is not declared as global by an `extern` declaration.

      % cat afo
      def afo() { return A;}
      extern A$
      def bfo() { return A;}
      end$
      % asir
      [0] load("afo")$
      [5] A = 1;
      1
      [6] afo();
      0
      [7] bfo();
      1

- Program variables and algebraic indeterminates are distinguished in Asir.
  The names of program variables must begin with a capital letter; while the names of indeterminates and functions must begin with a small letter. This is an unique point that differs from almost all other existing computer algebra systems. The distinction between program variables and indeterminates is adopted to avoid the possible and usual confusion that may arise in a situation where a name is used as an indeterminate but, as it was, the name has been already assigned some value. To use different type of letters, capital and small, was a matter of syntactical convention like Prolog, but it is convenient to distinguish variables and indeterminates in a program.
- No `switch` statements, and `goto` statements.
  Lack of `goto` statement makes it rather bothering to exit from within multiple loops.
- Comma expressions are allowed only in `A`, `B` and `C` of the constructs `for (A;B;C)` or `while(A)`.
  This limitation came from adopting lists as legal data objects for Asir.

The above are limitations; extensions are listed as follows.

- Arithmetic for rational expressions can be done in the same manner as is done for numbers in C language.
- Lists are available for data objects. Lists are conveniently used to represent a certain collection of objects. Use of lists enables to write programs more easily, shorter and more comprehensible than use of structure like C programs.
- Options can be specified in calling user defined functions. See section option.

Go to the first, previous, next, last section, table of contents.