Reverse a String without using reverse function

Certified Associate Developer

I'm unable to find where the mistake is in below code Reverse a string without reverse function: 

a!localVariables(
  local!result: ri!result,
  local!index: if(
    a!isNullOrEmpty(ri!index),
    length(ri!Input),
    ri!index
  ),
  if(
    ri!index < 1,
   ri!result,
    rule!T_Reversestring(
      ri!Input,
      local!index - 1,
      concat(
        local!result,
        index(ri!Input, local!index)
      )
    )
  )


  Discussion posts and replies are publicly visible