The Museum of HP Calculators

HP Forum Archive 21

[ Return to Index | Top of Index ]

Programming workaround for "prepend" HP PRIME
Message #1 Posted by Marek Russ on 28 Nov 2013, 3:43 a.m.

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"
Message #2 Posted by Marek Russ on 28 Nov 2013, 4:12 a.m.,
in response to message #1 by Marek Russ

short after posting, i found this solution:

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

but maybe exists better solution...

            
Re: Programming workaround for "prepend"
Message #3 Posted by Patrice on 28 Nov 2013, 5:45 a.m.,
in response to message #2 by Marek Russ

Try CONCAT

CONCAT({"a","b"},{"c"}) => {"a","b","c"}
CONCAT({"c"},{"a","b"}) => {"c","a","b"}
      
Re: Programming workaround for "prepend" HP PRIME
Message #4 Posted by cyrille de Brébisson on 29 Nov 2013, 3:23 a.m.,
in response to message #1 by Marek Russ

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
Message #5 Posted by Marek Russ on 29 Nov 2013, 5:46 a.m.,
in response to message #4 by cyrille de Brébisson

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


[ Return to Index | Top of Index ]

Go back to the main exhibit hall