# eval / toliteral safety question

Kipp the Kidd (mcmudge@mailbox.syr.edu)
Tue, 11 Jun 1996 20:00:41 PDT

- Messages sorted by:[ date ][ thread ][ subject ][ author ]

    At 02:17 PM 6/11/96 PDT, Don Schwarz wrote:
    >> For example, say you want to change "Xythian" to "HunkaHunkaBurningLove"
    within
    >> a string or a list of strings, or basically anywhere it exists within a
    >> variable.  I could do some awkward recursive thing, or just:
    >>   return eval("return " + strsub(toliteral(args[1]),
    >>     "Xythian", "HunkaHunkaBurningLove", 1) + ";")[2];
    >
    >  {start, search, replace} = args;
    >  return eval(tostr("return ", strsub(toliteral(start), toliteral(search),
    >         toliteral(replace)), ";"))[2];

    How about something a little more... umm... usual:

    someobject:someverb this none this rx
    "Usage:  $thisthing:thisverb(inputstuff, stuff-to-be-replaced,
    stuff-to-be-replaced-with) => outputstuff";
    if ((v = args[1]) == (o=args[2]))
      return args[3];
    elseif (typeof(v) == LIST)
      n = args[3];
      for x in [1..length(v)]
        v[x] = this:(verb)(v[x], o, n);
      endfor
      return v;
    else
      return v;
    endif

    - Kipp
    http://radioactivo.com.mx/~paradigm