HP Forums
Programming workaround for "prepend" HP PRIME - Printable Version

+- HP Forums (https://archived.hpcalc.org/museumforum)
+-- Forum: HP Museum Forums (https://archived.hpcalc.org/museumforum/forum-1.html)
+--- Forum: Old HP Forum Archives (https://archived.hpcalc.org/museumforum/forum-2.html)
+--- Thread: Programming workaround for "prepend" HP PRIME (/thread-257244.html)



Programming workaround for "prepend" HP PRIME - Marek Russ - 11-28-2013

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


Re: Programming workaround for "prepend" - Marek Russ - 11-28-2013

short after posting, i found this solution:

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

but maybe exists better solution...


Re: Programming workaround for "prepend" - Patrice - 11-28-2013

Try CONCAT

CONCAT({"a","b"},{"c"}) => {"a","b","c"}
CONCAT({"c"},{"a","b"}) => {"c","a","b"}



Re: Programming workaround for "prepend" HP PRIME - cyrille de Brébisson - 11-29-2013

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


Re: Programming workaround for "prepend" HP PRIME - Marek Russ - 11-29-2013

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