POV-Ray : Newsgroups : povray.general : An string macro that returns the input inverted. Server Time: 14 Jul 2020 04:08:27 GMT
  An string macro that returns the input inverted. (Message 1 to 4 of 4)  
From: B  Gimeno
Subject: An string macro that returns the input inverted.
Date: 17 Jun 2020 17:20:00
Message: <web.5eea4d13c8dfe7dba723b8610@news.povray.org>
/* --------------------------------------------------------------------------
When a S1 string is entered, it returns a S2 string reordered from the end to
the beginning."

Usage: [limit: up to a 256 character long string]
Inv_String("gninnigeb eht ot dne eht morf deredroer gnirts 2S a snruter ti,
deretne si gnirts 1S a nehW")

Disclaimer: Use this code only under your own discernment. The author declines
all responsibility in the event that tentacular entities of a remote underworld
possess the user for trying to decipher "modern" music lyrics by reading it
backwards (or forward).

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

B Gimeno
Departamento de Cosas Raras


Post a reply to this message

From: jr
Subject: Re: An string macro that returns the input inverted.
Date: 17 Jun 2020 21:20:09
Message: <web.5eea875a3fadb0934d00143e0@news.povray.org>
hi,

"B. Gimeno" <nomail@nomail> wrote:
> /* --------------------------------------------------------------------------
> When a S1 string is entered, it returns a S2 string reordered from the end to
> the beginning."
>
> Usage: [limit: up to a 256 character long string]
> Inv_String("gninnigeb eht ot dne eht morf deredroer gnirts 2S a snruter ti,
> deretne si gnirts 1S a nehW")
>
> Disclaimer: Use this code only under your own discernment. The author declines
> all responsibility in the event that tentacular entities of a remote underworld
> possess the user for trying to decipher "modern" music lyrics by reading it
> backwards (or forward).
>
> --------------------------------------------------------------------------- */
> #macro Inv_String (S)
>  #local C = strlen (S) ;
>  #local I_S = concat ( #for(C,C,0) substr(S,C,1); #end )
>  I_S
> #end
> // ---------------------------------------------------------------------------

which version are you using?  tried with alpha.10064268, but got no output.
have to use "concat ( #for(J,C,0,-1) substr(S,J,1) #end )" to get it to work;
with semicolon I get a "Parse Error: Expected 'string expression', ; found".
still, neat!


regards, jr.


Post a reply to this message

From: B  Gimeno
Subject: Re: An string macro that returns the input inverted.
Date: 17 Jun 2020 22:40:00
Message: <web.5eea9b323fadb093a723b8610@news.povray.org>
"jr" <cre### [at] gmailcom> wrote:
> hi,
>
> "B. Gimeno" <nomail@nomail> wrote:
> > /* --------------------------------------------------------------------------
> > When a S1 string is entered, it returns a S2 string reordered from the end to
> > the beginning."
> >
> > Usage: [limit: up to a 256 character long string]
> > Inv_String("gninnigeb eht ot dne eht morf deredroer gnirts 2S a snruter ti,
> > deretne si gnirts 1S a nehW")
> >
> > Disclaimer: Use this code only under your own discernment. The author declines
> > all responsibility in the event that tentacular entities of a remote underworld
> > possess the user for trying to decipher "modern" music lyrics by reading it
> > backwards (or forward).
> >
> > --------------------------------------------------------------------------- */
> > #macro Inv_String (S)
> >  #local C = strlen (S) ;
> >  #local I_S = concat ( #for(C,C,0) substr(S,C,1); #end )
> >  I_S
> > #end
> > // ---------------------------------------------------------------------------
>
> which version are you using?  tried with alpha.10064268, but got no output.
> have to use "concat ( #for(J,C,0,-1) substr(S,J,1) #end )" to get it to work;
> with semicolon I get a "Parse Error: Expected 'string expression', ; found".
> still, neat!
>
>
> regards, jr.

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.

ORIGINAL:
#macro Inv_String (S)
 #local C = strlen (S) ;
 #local Inv = concat ( #while(C>0) substr(S,C,1) #local C=C-1; #end )
  Inv
#end

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


B. Gimeno


Post a reply to this message

From: jr
Subject: Re: An string macro that returns the input inverted.
Date: 18 Jun 2020 20: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-2008 Persistence of Vision Raytracer Pty. Ltd.