Page 1 sur 1
(expr)[-1]
Publié : jeu. févr. 22, 2018 12:52 pm
par compsystems
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
Re: (expr)[-1]
Publié : jeu. févr. 22, 2018 3:10 pm
par parisse
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.
Re: (expr)[-1]
Publié : jeu. févr. 22, 2018 4:23 pm
par compsystems
ok, (expr)[-1] as last argument (tail)
(expr)[] =>number of arguments
(8+d^4)[] => 2
Re: (expr)[-1]
Publié : jeu. févr. 22, 2018 6:37 pm
par parisse
But why do you want me to make changes when there are already instructions that return the number of arguments like size?
Re: (expr)[-1]
Publié : dim. févr. 25, 2018 12:14 pm
par compsystems
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
Re: (expr)[-1]
Publié : ven. mars 16, 2018 1:35 pm
par compsystems
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