Commands - Untitled
Description: Untitled

Next: Organization of Functions, Previous: Function Handles Inline Functions and Anonymous Functions, Up: Functions and Scripts

### 11.10 Commands

Commands are a special class of functions that only accept string input arguments. A command can be called as an ordinary function, but it can also be called without the parentheses like the following example shows

         my_command hello world

which is the same as

         my_command("hello", "world")

The general form of a command call is

         name arg1 arg2 ...

which translates directly to

         name ("arg1", "arg2", ...)

A function can be used as a command if it accept string input arguments. To do this, the function must be marked as a command, which can be done with the `mark_as_command` command like this

         mark_as_command name

where `name` is the function to be marked as a command.

One difficulty of commands occurs when one of the string input arguments are stored in a variable. Since Octave can't tell the difference between a variable name, and an ordinary string, it is not possible to pass a variable as input to a command. In such a situation a command must be called as a function.

— Built-in Function: mark_as_command (name)

> Enter name into the list of commands.

> See also: unmark_command, iscommand.

— Built-in Function: unmark_command (name)

> Remove name from the list of commands.

> See also: mark_as_command, iscommand.

— Built-in Function: iscommand (name)

> Return true if name is a command style function. If name is omitted, return a list of identifiers which are marked as commands with `mark_as_command`.

> See also: mark_as_command, unmark_command.

— Built-in Function: mark_as_rawcommand (name)

> Enter name into the list of raw input commands and to the list of command style functions. Raw input commands are like normal command style functions, but they receive their input unprocessed (ie. strings still contain the quotes and escapes they had when input). However, comments and continuations are handled as usual, you cannot pass a token starting with a comment character ('#' or '%') to your function, and the last token cannot be a continuation token ('\' or '...').

> See also: unmark_rawcommand, israwcommand, iscommand, mark_as_command.

— Built-in Function: unmark_rawcommand (name)

> Remove name from the list of raw input commands. Note that this does not remove name from the list of command style functions.

> See also: mark_as_rawcommand, israwcommand, iscommand, unmark_command.

— Built-in Function: israwcommand (name)

> Return true if name is a raw input command function. If name is omitted, return a list of identifiers which are marked as raw input commands with mark_as_rawcommand.

> See also: mark_as_rawcommand, unmark_rawcommand.