[TOC]

Precedence

The MATLAB interpreter of SIMO considers a sequence of characters as a variable name or a function name, when the sequence satisfies the following requirements:

When such a sequence of characters is found, the interpreter attempts to look for a variable or a function with the name equal to the sequence of characters. It is possible that a variable and a function have identical names. In this case, instead of throwing an error immediately, the interpreter decides which one, the function or the variable, to execute. The following two flow charts show how such a decision is made.

For the first flow chart below, a name is entered with neither parentheses nor input arguments.

precedence_no_input

The above flow chart is explained in the following.

  1. Attempt to run an expression, say, fun. No input argument is given. fun can be

  2. Check if fun is a built-in function. If it is, it attempts to run the function.

  3. Check if fun matches any of the variables in the current workspace.

  4. If the variable fun is found in Step 3 above, return the variable.

  5. If the variable fun is not found in Step 3 above, search for the file fun.m in the work folder.

  6. If fun.m exists in the work folder mentioned in Step 5 above, check if a main function is defined in fun.m. If yes, run fun as a main function. Otherwise, run run as a script.

  7. If the expression run in Step 1 was i or j, it returns a unit imaginary number. Otherwise, an error is throw.

For the flow chart below, a name is entered with

precedence_with_input

  1. Attempt to run fun(a1,a2,...) or fun(). Here, a1, a2, ... are input arguments. The expression can be

  2. Check if fun is a built-in function. If it is, it attempts to run the function.

  3. Check if fun matches any of the variables in the current workspace.

  4. The variable fun found in Step 3 above could be a function handle or local function. In both cases, run the corresponding function. But, if it is an array, return its value.

  5. If the variable fun is not found in Step 3 above, search for the file fun.m in the work folder.

  6. If fun.m exists in the work folder mentioned in Step 5 above, check if a main function is defined in fun.m. If yes, run fun as a function. Otherwise, throw an error since a script should not be run with input arguments or parentheses.