Programming workaround for "prepend" HP PRIME



Post: #2

Hi I have this issue:

L1:={"A","B"};

append (L1,1) //works fine

append (L1,"C") //does not work (bad argument type)

//seems like this inserts value of variable C instead of char "C"

//same behaviour is if I use variable that contains this string

known workaround in program is

L1(0):="C" //works fine

but if I need insert "C" to the beginning of my list,

I need to find similiar workaround for prepend function...

I need that output is exactly:

{"C","A","B"}

not like

{""C"","A","B"} or {{"C"},"A","B"}

Edited: 28 Nov 2013, 5:26 a.m. after one or more responses were posted


Post: #3

short after posting, i found this solution:

REVERSE(L1);
L1(0):="C";
REVERSE(L1);

but maybe exists better solution...


Post: #4

Try CONCAT

CONCAT({"a","b"},{"c"}) => {"a","b","c"}
CONCAT({"c"},{"a","b"}) => {"c","a","b"}
Post: #5

hello,


append (L1,"C") //does not work (bad argument type)
it does not work because append is a CAS funcion. string type arguements to a CAS function are assumed to be CAS commands that can not be parsed by the numeric parser and which are parsed by the CAS at execution of the command. This is most likely the issue there...

as much as possible, try to stay in 1 system.

L1(0):= "C" in this cas.
to do the 'prepend', use CONCAT... sorry, there is no quick trick there... unless I create a syntax with negative numbers for 'inserting'... which might be an idea...

cyrille


Post: #6

Thanks for explanation.
There is always something new to learn :-)


Forum Jump: