在 Maxima 中将数字转换为单词

Convert numerals to words in Maxima

我正在尝试将数字转换为对应的英文。例如,字符串 '15' 将被转换为 'fifteen'.

我发现这段代码片段似乎在 Maxima 手册中有效,但它使用了文件处理函数:

(%i1) s: openw("E:/file.txt");
(%o1)                     #<output stream E:/file.txt>
(%i2) control: 
 "~2tAn atom: ~20t~a~%~2tand a list: ~20t~{~r ~}~%~2t\
and an integer: ~20t~d~%"$
(%i3) printf( s,control, 'true,[1,2,3],42 )$
(%o3)                                false
(%i4) close(s);
(%o4)                                true
(%i5) s: openr("E:/file.txt");
(%o5)                     #<input stream E:/file.txt>
(%i6) while stringp( tmp:readline(s) ) do print(tmp)$
  An atom:          true 
  and a list:       one two three  
  and an integer:   42 
 (%i7) close(s)$

一定有一种不使用文件的更简单直接的方法。

printf 使用 ~r 格式指令将数字拼写为单词。您可以从 printf(false, ...) 获取字符串,或者您可以使用 printf(true, ...) 打印到控制台。有关详细信息,请参阅 ? printf

(%i1) printf (true, "~r~%", 15);
fifteen
(%o1)                                false
(%i2) my_string : printf (false, "~r", 15);
(%o2)                               fifteen
(%i3) my_string;
(%o3)                               fifteen