the point was that the problem with the OP's code is that $mid evaluates to a literal space, which is infact why it is not functioning as they expected.
If that is the case, then why does the following code work just fine?
//var %t = GA is Ga ,%b = $len(%t) ,%a 1 | while (%b >= %a) { var -s %r = $+($mid(%t,%b,1),%r) | dec %b }