func()

Read(2693) Label: func,

Here’s how to use func() function.

func fn(arg,…) … {return x i }

Description:

Define a subroutine block.

Syntax:

func  fn(arg,...)

{return xi}

Note:

The function defines a subroutine block, which may or may not return a result after computation.

 

The subroutine name is fn. The subroutine begins with the starting characters func fn(arg,...) and covers a cell range where the master cell is the one holding the func fn(arg,...). The return statement is used to return the function’s result and terminate the execution of the function block. The subroutine will by default return the value of the last calculation cell if no return statement appears during execution.

Parameter:

fn

Subroutine name.

arg,…

Defined parameters.

Option:

@i

Use this option to increase performance when the subroutine does not contain a recursive operation.

@m

Use this option to increase performance when the subroutine consists of one expression only.

@o

Use this option to define a subroutine. In the invocation expression fn@o, o is the first (string) parameter value. If no option is specified in the invocation expression, the first (string) parameter value passed is regarded as null.

Return value:

Result of the function block

Example:

 

A

B

 

1

func ft(arg1)

 

Define a subroutine named ft, where arg1 is the parameter it uses, and return B2’s value after the computation is finished.

2

 

=arg1*10

3

 

return B2

 

4

=ft(2)

 

Call subroutine ft, pass 2 to it as the parameter value and return 20.

 

When @o option is present:

 

A

B

 

1

func ft@o(s,n)

 

Use @o method to define a subroutine named ft, where both s and n are parameters it uses, and return B2’s value after the computation is finished.

2

 

=left(s,n)

3

 

return B2

 

4

=ft@Hello(3)

 

When subroutine ft@o is called, pass Hello to it as the first string value and return "Hel".