POV-Ray : Newsgroups : povray.general : An string macro that returns the input inverted. : Re: An string macro that returns the input inverted. Server Time
23 Apr 2024 17:28:28 EDT (-0400)
  Re: An string macro that returns the input inverted.  
From: jr
Date: 18 Jun 2020 16:15:00
Message: <web.5eebca1f3fadb0934d00143e0@news.povray.org>
hi,

"B. Gimeno" <nomail@nomail> wrote:
> "jr" <cre### [at] gmailcom> wrote:
> > ...
> > which version are you using?  tried with alpha.10064268, but got no output.
> > ...
> Im sorry, it's my fault for going from a while-loop to a for-loop and pretending
> leaving it that nice. The first three exorcisms will not be charged to your
> monthly subscription account.

</grin>

(just as well, because I'm going to use up another.  :-))

> ...
> FIXED:
>  #macro Inv_String (S)
>   #local C = strlen (S) ;
>   #local I_S = concat ( #for(C,C,0) substr(S,C,1) #end )
>   I_S
>  #end

still does not work for me, sorry.  afaict, without a (negative) step-size, the
'#for' won't decrement, as shown below.  fwiw, I've included an
almost-variable-free version of the macro.

Script started on Thu 18 Jun 2020 20:58:36 BST

jr@swift:35:BGimeno$ c### [at] 200617pov
#version 3.8;

global_settings {assumed_gamma 1}

#declare sentence = "the quick brown fox jumped over the dog.";

// as posted.
#macro Inv_String(S)
  #local C = strlen(S);
  #local I_S = concat( #for(C,C,0) substr(S,C,1) #end )
  I_S
#end

#debug concat("original: ", sentence, "\n",
              "reversed: ", Inv_String(sentence), "\n")

#macro reverse_string(s_)
  concat(#for(i_,strlen(s_),0,-1) substr(s_,i_,1) #end)
#end

#debug concat("original: ", sentence, "\n",
              "reversed: ", reverse_string(sentence), "\n")


jr@swift:36:BGimeno$ povparse 200617.pov
Persistence of Vision(tm) Ray Tracer Version 3.8.0-alpha.10064268.unofficial
....
==== [Parsing...] ==========================================================
original: the quick brown fox jumped over the dog.
reversed:
original: the quick brown fox jumped over the dog.
reversed: .god eht revo depmuj xof nworb kciuq eht
File '200617-bg.pov' line 22: Parse Warning: No objects in scene.
==== [Rendering...] ========================================================
Rendered 1024 of 1024 pixels (100%)
POV-Ray finished


regards, jr.


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.