如何在Oz中将整数转换为列表,反之亦然?

如何将整数转换为列表并返回Oz?我需要取一个像
321
这样的数字并将其反转为
123
。 Oz中的Reverse函数仅适用于列表,因此我想将321转换为[3 2 1],将其反转,然后将[1 2 3]转换回123.可以在Oz中完成吗?     
已邀请:
免责声明:直到5分钟前我才真正了解Oz并且只阅读维基百科上的示例,因此以下内容可能存在错误。但是,它应该为您提供如何解决问题的好主意。 (使函数tail-recursive留给读者练习)。 更新:以下版本已经过测试并可以使用。
local
  % turns 123 into [3,2,1]
  fun {Listify N}
    if N == 0 then nil
    else (N mod 10) | {Listify (N div 10)}
    end
  end

  % turns [1,2,3] into 321
  fun {Unlistify L}
    case
      L of nil then 0
      [] H|T then H + 10 * {Unlistify T}
    end
  end
in
  % Turns 123 into 321
  {Browse {Unlistify {Reverse {Listify 123}}}}
end
    
这应该更加简洁:
{Show {StringToInt {Reverse {IntToString 123}}}}
干杯     

要回复问题请先登录注册