Programming workaround for "prepend" HP PRIME



#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


#3

short after posting, i found this solution:

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

but maybe exists better solution...


#4

Try CONCAT

CONCAT({"a","b"},{"c"}) => {"a","b","c"}
CONCAT({"c"},{"a","b"}) => {"c","a","b"}
#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


#6

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


Possibly Related Threads…
Thread Author Replies Views Last Post
  hp prime - programming with lists giancarlo 3 1,936 11-10-2013, 02:13 AM
Last Post: Giancarlo
  HP Prime Programming Tutorial #3: WHILE, INPUT, KILL, REPEAT, GETKEY Eddie W. Shore 5 2,458 11-07-2013, 12:25 AM
Last Post: Han
  HP Prime - programming bluesun08 2 1,497 11-04-2013, 04:31 PM
Last Post: bluesun08
  More undocumented programming limitations in the HP Prime Michael de Estrada 3 1,942 11-03-2013, 08:22 PM
Last Post: Michael de Estrada
  HP Prime questions: I/O and Meta programming Andy Gryc 2 1,547 10-31-2013, 11:22 PM
Last Post: Andy Gryc
  HP Prime Programming Tutorial #1: LOCAL, RETURN Eddie W. Shore 6 3,076 10-26-2013, 08:42 PM
Last Post: Miguel Toro
  HP Prime Programming Tutorial #2: MSGBOX, IF-THEN-ELSE, PRINT, FOR Eddie W. Shore 0 1,277 10-26-2013, 03:51 PM
Last Post: Eddie W. Shore
  HP Prime : Programming and the Comma Miguel Toro 7 2,877 10-25-2013, 12:18 PM
Last Post: Miguel Toro
  HP Prime Programming: LOCAL Alberto Candel 3 1,583 10-07-2013, 01:31 AM
Last Post: cyrille de Brébisson
  HP Prime Programming options Egan Ford 8 2,608 10-06-2013, 10:44 AM
Last Post: Eddie W. Shore

Forum Jump: