(expr)[-1]

Messages in english

Modérateur : xcasadmin

compsystems
Messages : 603
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

(expr)[-1]

Message par compsystems » jeu. févr. 22, 2018 12:52 pm

Hi BP, the postfix operator ()[] works the same as part() function

but the number of parts does not return, I suggest that ()[-1] return the number of parts

part(8+d^4) 2
part(8+d^4,0) '+'
part(8+d^4,1) 8
part(8+d^4,2) d^4
(8+d^4)[0] '+'
(8+d^4)[1] 8
(8+d^4)[2] d^4

(8+d^4)[-1] "Error: Invalid dimension"
(8+d^4)[-1] 2

Thanks

parisse
Messages : 5882
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: (expr)[-1]

Message par parisse » jeu. févr. 22, 2018 3:10 pm

I don't think it's a good idea, if I make a change for -1 index, I think it would be better to return the last argument.

compsystems
Messages : 603
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: (expr)[-1]

Message par compsystems » jeu. févr. 22, 2018 4:23 pm

ok, (expr)[-1] as last argument (tail)

(expr)[] =>number of arguments

(8+d^4)[] => 2

parisse
Messages : 5882
Inscription : mar. déc. 20, 2005 4:02 pm
Contact :

Re: (expr)[-1]

Message par parisse » jeu. févr. 22, 2018 6:37 pm

But why do you want me to make changes when there are already instructions that return the number of arguments like size?

compsystems
Messages : 603
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: (expr)[-1]

Message par compsystems » dim. févr. 25, 2018 12:14 pm

Some CAS, have "redundant" commands, I can use only the function 'part ()' or 'size ()', but it is better to use multi-paradigm programming, function-type or function-prefix commands functionName(args) and postfix as (9*x^4)[-1], is more intuitive to extract with symbols [] than with a function name

oper:=(9*x^4)[0]; // '*', operator
n:=size(9*x^4); 2 // parts
n:=part(9*x^4); 2
=>

oper:=(9*x^4)[0]; '*'
n:=(9*x^4)[]; // 2, number of arguments
la:=(9*x^4)[-1]; // x^4, last arg

compsystems
Messages : 603
Inscription : sam. févr. 04, 2017 11:34 pm
Localisation : Colombia
Contact :

Re: (expr)[-1]

Message par compsystems » ven. mars 16, 2018 1:35 pm

With the keyword 'parts' may be a better option, instead of an empty field

n:=(9*x^4)[]; => n:=(9*x^4)['parts'];

oper:=(9*x^4)[0]; '*'
n:=(9*x^4)['parts']; // 2, number of arguments
la:=(9*x^4)[-1]; // x^4, last arg

Répondre