# New language feature "arguments" introduced in Scilab 2024.0.0

**URL:** <https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367>\
**Category:** General usage\
**Created:** [January 25, 2024, 10:22am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367 "2024-01-25T10:22:03Z")\
**Posts on this page:** 10\
**Page:** 1

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [January 25, 2024, 10:22am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/1 "2024-01-25T10:22:03Z")

</div>

**Do you know the new language feature [arguments](https://help.scilab.org/arguments) introduced in Scilab 2024.0.0?**

The aim is to simplify the writing of input arguments validation, standardize messages and add readability of code by avoid blocks of checkers like:

```scilab
if type(a) <> 1 | size(a) <> [2 3] then error("...");end

```

and potential speedup for function with lot of checks.

This new block takes this generic form

 ![image](https://global.discourse-cdn.com/free1/uploads/utc/original/1X/46b9776817d0a61304043ba2a709664f464871aa.png)

and previous example can be replaced by:

```scilab
function test(a)
    arguments
        a (2, 3) {mustBeA(a, "double")}
    end
endfunction

```

For each input parameter, Scilab will be check dimensions compatibility, conversion capability and each validator (all must be verified) and if the input parameter is missing it will assign to default value.

All input parameters must be defined in the arguments block. And no check is mandatory, so if you want to check nothing, just let a line with the variable name

```scilab
function test(a)
    arguments
        a
    end

    //algorithm
endfunction

test(1);

```

## Dimensions

Here are a examples of dimension validation:

```scilab
function test(a, b)
    arguments
        a (2, 3)
        b (1, 3)
    end

    //algorithm
endfunction

test(rand(2, 3), rand(1, 3)); //works
test(rand(2, 3), rand(3, 1)); //works, b will be transpose to match expected dimensions
test(0, 1); //works, a and b will be expanded to match expected dimensions
test(rand(3, 3), rand(2, 2)); //fails

```

```scilab
function test(a)
    arguments
        //waits a 2 or 4 columns matrix
        a (:, [2 4])
    end

    //algorithm
endfunction

test(rand(1024, 2)); //works
test(rand(256, 3)); //fails
test(rand(512, 4)); //works

```

## Conversions

Argument checking also manages automatic type conversion as follows:

```scilab
function test(a)
    arguments
        a double
    end

    disp(type(a))
    //algorithm
endfunction

test(1); // a is a double
test(uint8(42)); // a will be converted to a double

```

## Validators

And here is how to force type checking:

```scilab
function test(a)
    arguments
        a {mustBeA(a, "double")}
    end

    //algorithm
endfunction

test(1); // works
test(uint8(42)); // fails

```

See the list of all [**validators**](https://help.scilab.org/arguments_validators)

## Default Value

If you want to set a default value for input argument, just use the following:

```scilab
function test(a)
    arguments
        a = 12
    end

    //algorithm
endfunction

test(1); // a == 1
test(); // a == 12

```

Since Scilab 2024.0.0, this new feature is already used in `time` module ([see related merge request](https://gitlab.com/scilab/scilab/-/merge_requests/584/)) and other modules will be updated in next versions…

_As usual, don’t hesitate to share with us your use cases and issues._

---

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [January 26, 2024, 8:21am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/6 "2024-01-26T08:21:16Z")

</div>



---

<div class="post-metadata">

**Author:** ![vincent.couvert](https://avatars.discourse-cdn.com/v4/letter/v/f4b2a3/32.png) [@vincent.couvert](https://scilab.discourse.group/u/vincent.couvert)\
**Post date:** [January 26, 2024, 8:23am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/7 "2024-01-26T08:23:28Z")

</div>



---

<div class="post-metadata">

**Author:** ![mottelet](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/mottelet/32/13_2.png) [@mottelet](https://scilab.discourse.group/u/mottelet)\
**Post date:** [January 26, 2024, 8:23am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/8 "2024-01-26T08:23:29Z")

</div>



---

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [February 6, 2024, 11:00am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/9 "2024-02-06T11:00:17Z")

</div>



---

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [May 24, 2024, 9:46am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/10 "2024-05-24T09:46:52Z")

</div>



---

<div class="post-metadata">

**Author:** ![davcheze](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@davcheze](https://scilab.discourse.group/u/davcheze)\
**Post date:** [May 30, 2024, 7:33am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/11 "2024-05-30T07:33:42Z")

</div>

Hi Antoine,  
thank you for this nice new feature that I’m introducing in some developments. Would you give some hints, recommendations and examples how to deal with `varargin` argument ?

David

---

<div class="post-metadata">

**Author:** ![philippeb](https://avatars.discourse-cdn.com/v4/letter/p/dfb087/32.png) [@philippeb](https://scilab.discourse.group/u/philippeb)\
**Post date:** [May 31, 2024, 12:39pm UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/12 "2024-05-31T12:39:33Z")

</div>

Hello,  
I have a function that take a matrix of the form ( : , : ) or ( : , : ,3). It’s representing a grayscale image or a RGB image. How can I make the “arguments” check this type of argument ?

---

<div class="post-metadata">

**Author:** ![davcheze](https://avatars.discourse-cdn.com/v4/letter/d/90db22/32.png) [@davcheze](https://scilab.discourse.group/u/davcheze)\
**Post date:** [June 13, 2024, 7:52am UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/13 "2024-06-13T07:52:29Z")

</div>

Hi all,

while working with experimental data in real-time applications, I often need to check the validity range of the input arguments values to detect random measurement errors, either yielding %nan or valid numerical but extrem values,etc… which I need to manage following use-case specific rules/functions to avoid stopping the real-time application : e.g. some default values to be taken instead and yielding a message to record the issue , not necessarily breaking the execution of the program : Do you have an suggestion how I could use the new arguments function to handle smarter such situations ?  
Thank you,

David

---

<div class="post-metadata">

**Author:** ![antoine.elias](https://yyz2.discourse-cdn.com/free1/user_avatar/scilab.discourse.group/antoine.elias/32/16_2.png) [@antoine.elias](https://scilab.discourse.group/u/antoine.elias)\
**Post date:** [June 13, 2024, 1:06pm UTC](https://scilab.discourse.group/t/new-language-feature-arguments-introduced-in-scilab-2024-0-0/367/14 "2024-06-13T13:06:38Z")

</div>

Hello,

Welcome on Scilab Community !

Normally, using `(:, :, [1 3])` for dimensions should work.  
But I just checked and that’s not the case.  
So I opened the issue [#17269](https://gitlab.com/scilab/scilab/-/issues/17269) (and proposed a patch for 2025.0)
