我在 Common Lisp (SBCL) 中使用 Paresncript。在调用一个名为 的辅助函数后(write-input-data)
,REPL 返回一个字符串列表:
CL-USER> (write-input-data)
("2937" "AVpKuU6t_T0" "Joe" "Bush" "random@globo.com" "random@globo.com"
"WHTpassword" "NIL" "NIL" "1" "2" "-1" "NIL" "NIL" "0" "NIL" "on" "0"
"b4acdb97-6f1b-4a15-984a-c33c7448032f" "NIL" "NIL" "NIL" "NIL" "pt_BR" "NIL"
"NIL" "NIL" "NIL" "NIL" "NIL" "yjcIYTMI-bJuQg7nz3hes-qm" "NIL" "NIL" "NIL"
"NIL" "NIL" "NIL" "NIL" "NIL" "NIL" "reg_email_confirmation__"
"AZnc92iq5Xddjxw0eRPfTh1JH2sQg3gEZ3JDOYp5EQXQZwPSMJ3pAmJnQhH0wtgMb8mq7UxPNiOZIiuxUXpo9ZUwyQZh_Zvh3T_aJcVLBNCZ7Mc7CXfzH4QRKzxfVHXFTI8nR_MlnBWCx0cdAARjUAPGiaQxJJWnkZdS3pQGFiH5ZX83x7r2rFcYI0vmtrRNM50fplxK0ynsMVBYqLBPt-Vqlpf3YmEwGmAoV0FLinVgQ3Yg9WWO0vzLHqrnf3Tq2xVdEHnjHhcsC_RMB_w2CKh9jQlX5llIFVmID62pkCDPHE-aTx7BNsHkcLgaNgTLSWxjCoyEFpKN_Y0xUoSaU6YZAmKu1kaToSreyEWNXR7tyO3-237mOkl72Z3PhtrcI"
"NIL")
然后,我尝试将其转换为用 javascript 语法填充的字符串数组:
CL-USER> (ps:ps (array (ps:lisp (write-input-data))))
"['2937'('AVpKuU6t_T0', 'Joe', 'Bush', 'random@globo.com', 'random@globo.com', 'WHTpassword', 'NIL', 'NIL', '1', '2', '-1', 'NIL', 'NIL', '0', 'NIL', 'on', '0', 'b4acdb97-6f1b-4a15-984a-c33c7448032f', 'NIL', 'NIL', 'NIL', 'NIL', 'pt_BR', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'yjcIYTMI-bJuQg7nz3hes-qm', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'reg_email_confirmation__', 'AZnc92iq5Xddjxw0eRPfTh1JH2sQg3gEZ3JDOYp5EQXQZwPSMJ3pAmJnQhH0wtgMb8mq7UxPNiOZIiuxUXpo9ZUwyQZh_Zvh3T_aJcVLBNCZ7Mc7CXfzH4QRKzxfVHXFTI8nR_MlnBWCx0cdAARjUAPGiaQxJJWnkZdS3pQGFiH5ZX83x7r2rFcYI0vmtrRNM50fplxK0ynsMVBYqLBPt-Vqlpf3YmEwGmAoV0FLinVgQ3Yg9WWO0vzLHqrnf3Tq2xVdEHnjHhcsC_RMB_w2CKh9jQlX5llIFVmID62pkCDPHE-aTx7BNsHkcLgaNgTLSWxjCoyEFpKN_Y0xUoSaU6YZAmKu1kaToSreyEWNXR7tyO3-237mOkl72Z3PhtrcI', 'NIL')];"
结果几乎是完美的。不幸的是,有两个问题。首先,在开头,有一个左括号:
'2937'('AVpKuU6t_T0'
它应该是一个逗号:
'2937' , 'AVpKuU6t_T0'
.
第二个错误在最后。有一个右括号:
'NIL')];"
预计什么都没有,只是:
'NIL' ];"
为什么会这样?我可以用 parenscript 做些什么来修复它吗?
显然,我可以解析字符串并删除括号后验,但我想这个问题有更好的方法。
==== 已更新
伟大的用户@Barmar,建议不使用任何东西来解决这个问题。我们就快到了。如果我做:
CL-USER> (ps:ps '("2937" "AVpKuU6t_T0" "Joe" "Bush" "random@globo.com" "random@globo.com"
"WHTpassword" "NIL" "NIL" "1" "2" "-1" "NIL" "NIL" "0" "NIL" "on" "0"
"b4acdb97-6f1b-4a15-984a-c33c7448032f" "NIL" "NIL" "NIL" "NIL" "pt_BR" "NIL"
"NIL" "NIL" "NIL" "NIL" "NIL" "yjcIYTMI-bJuQg7nz3hes-qm" "NIL" "NIL" "NIL"
"NIL" "NIL" "NIL" "NIL" "NIL" "NIL" "reg_email_confirmation__"
"AZnc92iq5Xddjxw0eRPfTh1JH2sQg3gEZ3JDOYp5EQXQZwPSMJ3pAmJnQhH0wtgMb8mq7UxPNiOZIiuxUXpo9ZUwyQZh_Zvh3T_aJcVLBNCZ7Mc7CXfzH4QRKzxfVHXFTI8nR_MlnBWCx0cdAARjUAPGiaQxJJWnkZdS3pQGFiH5ZX83x7r2rFcYI0vmtrRNM50fplxK0ynsMVBYqLBPt-Vqlpf3YmEwGmAoV0FLinVgQ3Yg9WWO0vzLHqrnf3Tq2xVdEHnjHhcsC_RMB_w2CKh9jQlX5llIFVmID62pkCDPHE-aTx7BNsHkcLgaNgTLSWxjCoyEFpKN_Y0xUoSaU6YZAmKu1kaToSreyEWNXR7tyO3-237mOkl72Z3PhtrcI"
"NIL"))
我得到了我想要的:
"['2937', 'AVpKuU6t_T0', 'Joe', 'Bush', 'random@globo.com', 'random@globo.com', 'WHTpassword', 'NIL', 'NIL', '1', '2', '-1', 'NIL', 'NIL', '0', 'NIL', 'on', '0', 'b4acdb97-6f1b-4a15-984a-c33c7448032f', 'NIL', 'NIL', 'NIL', 'NIL', 'pt_BR', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'yjcIYTMI-bJuQg7nz3hes-qm', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'reg_email_confirmation__', 'AZnc92iq5Xddjxw0eRPfTh1JH2sQg3gEZ3JDOYp5EQXQZwPSMJ3pAmJnQhH0wtgMb8mq7UxPNiOZIiuxUXpo9ZUwyQZh_Zvh3T_aJcVLBNCZ7Mc7CXfzH4QRKzxfVHXFTI8nR_MlnBWCx0cdAARjUAPGiaQxJJWnkZdS3pQGFiH5ZX83x7r2rFcYI0vmtrRNM50fplxK0ynsMVBYqLBPt-Vqlpf3YmEwGmAoV0FLinVgQ3Yg9WWO0vzLHqrnf3Tq2xVdEHnjHhcsC_RMB_w2CKh9jQlX5llIFVmID62pkCDPHE-aTx7BNsHkcLgaNgTLSWxjCoyEFpKN_Y0xUoSaU6YZAmKu1kaToSreyEWNXR7tyO3-237mOkl72Z3PhtrcI', 'NIL'];"
唯一的问题是我直接插入了列表。我需要通过. (write-data)
如果我尝试只插入函数调用它不起作用:
CL-USER> (ps:ps (write-input-data))
"writeInputData();"
如果我尝试使用该(ps:lisp
技巧进行类似的操作,则括号会发生完全相同的问题,并且不会创建数组:
> (ps:ps (ps:lisp (write-input-data)))
"'2937'('AVpKuU6t_T0', 'Joe', 'Bush', 'random@globo.com', 'random@globo.com', 'WHTpassword', 'NIL', 'NIL', '1', '2', '-1', 'NIL', 'NIL', '0', 'NIL', 'on', '0', 'b4acdb97-6f1b-4a15-984a-c33c7448032f', 'NIL', 'NIL', 'NIL', 'NIL', 'pt_BR', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'yjcIYTMI-bJuQg7nz3hes-qm', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'NIL', 'reg_email_confirmation__', 'AZnc92iq5Xddjxw0eRPfTh1JH2sQg3gEZ3JDOYp5EQXQZwPSMJ3pAmJnQhH0wtgMb8mq7UxPNiOZIiuxUXpo9ZUwyQZh_Zvh3T_aJcVLBNCZ7Mc7CXfzH4QRKzxfVHXFTI8nR_MlnBWCx0cdAARjUAPGiaQxJJWnkZdS3pQGFiH5ZX83x7r2rFcYI0vmtrRNM50fplxK0ynsMVBYqLBPt-Vqlpf3YmEwGmAoV0FLinVgQ3Yg9WWO0vzLHqrnf3Tq2xVdEHnjHhcsC_RMB_w2CKh9jQlX5llIFVmID62pkCDPHE-aTx7BNsHkcLgaNgTLSWxjCoyEFpKN_Y0xUoSaU6YZAmKu1kaToSreyEWNXR7tyO3-237mOkl72Z3PhtrcI', 'NIL');"