is_array? command

Messages in english

Modérateur : xcasadmin

XcasEngGuy
Messages : 146
Inscription : mer. janv. 13, 2010 3:20 pm

is_array? command

Message par XcasEngGuy » jeu. nov. 29, 2018 7:09 pm

Is there a command in xcas programming to test if a variable contains an array or a single value? I would like to write functions that can operate on a single equation or multiple equations in an array. For example:

function(z=x+y)
or
function([z=x+y,z=3*x+4*y])

I would like to be able to determine inside the function whether there is one equation or an array of equations.

Thank you
Matt

lukamar
Messages : 331
Inscription : ven. juin 30, 2017 9:55 am
Localisation : Zagreb, Croatia

Re: is_array? command

Message par lukamar » ven. nov. 30, 2018 9:20 am

Hi,
perhaps you can use type command. If the argument for your function is arg, then type(arg) should return the integer 7 (meaning 'vector') only when arg is a vector. Hence you can use the following conditional switch:

Code : Tout sélectionner

if type(arg)==7 then
  \\ arg is a vector
else
  \\ arg is not a vector
fi;

XcasEngGuy
Messages : 146
Inscription : mer. janv. 13, 2010 3:20 pm

Re: is_array? command

Message par XcasEngGuy » dim. déc. 02, 2018 9:25 pm

Thank you very much.

Matt

Répondre