Karim.Belabas on Fri, 2 Feb 2001 16:28:48 +0100 (MET)


[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]

Re: gp and strings


On Thu, 1 Feb 2001, Nils-Peter Skoruppa wrote:

> does anybody know of a method to
> convert the string "pari" into ["p", "a", "r", "i"]
> (from within gp, of course).

You can apply the attached patch, then use

(16:26) gp > Vec("pari")
%1 = ["p", "a", "r", "i"]

Note that the reverse operation is already there:

(16:26) gp > concat(%)
%2 = "pari"

I'll probably make it the default behaviour. I can't see any use for the
former one (returned ["pari"]), and this one is quite fun (besides giving
access to substrings of PARI strings which wasn't possible without invoking
external programs).

    Karim.

-- 
Karim Belabas                    email: Karim.Belabas@math.u-psud.fr
Dep. de Mathematiques, Bat. 425
Universite Paris-Sud             Tel: (00 33) 1 69 15 57 48
F-91405 Orsay (France)           Fax: (00 33) 1 69 15 60 19
--
PARI/GP Home Page: http://www.parigp-home.de/
Index: src/basemath/gen3.c
===================================================================
RCS file: /home/megrez/cvsroot/pari/src/basemath/gen3.c,v
retrieving revision 1.22
diff -c -r1.22 gen3.c
*** src/basemath/gen3.c	2000/11/03 21:00:22	1.22
--- src/basemath/gen3.c	2001/02/02 15:22:32
***************
*** 1962,1970 ****
  
    if (!x) return cgetg(1,t_VEC);
    tx = typ(x);
!   if (is_scalar_t(tx) || is_rfrac_t(tx) || tx==t_STR)
    {
      y=cgetg(2,t_VEC); y[1]=lcopy(x);
      return y;
    }
    if (is_graphicvec_t(tx))
--- 1962,1983 ----
  
    if (!x) return cgetg(1,t_VEC);
    tx = typ(x);
!   if (is_scalar_t(tx) || is_rfrac_t(tx))
    {
      y=cgetg(2,t_VEC); y[1]=lcopy(x);
+     return y;
+   }
+   if (tx == t_STR)
+   {
+     char *s = GSTR(x);
+     char t[2];
+     lx = strlen(s); t[1] = 0;
+     y = cgetg(lx+1, t_VEC);
+     for (i=0; i<lx; i++)
+     {
+       t[0] = s[i];
+       y[i+1] = (long)strtoGENstr(t,0);
+     }
      return y;
    }
    if (is_graphicvec_t(tx))