为什么 Parenscript 在此数组创建中插入左括号和右括号?
Why Parenscript is inserting an opening and closing parenthesis in this array creation?
我在 Common Lisp (SBCL) 中使用 Paresncript。在调用一个名为 (write-input-data)
的辅助函数后,REPL returns 一个字符串列表:
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 做些什么来修复它吗?
显然,我可以解析字符串并删除括号a posteriori,但我想这个问题有更好的方法.
====
已更新
伟大的用户@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');"
您的 ps:lisp
表单需要构建 ps:ps
应该翻译的表单。所以:
CL-USER> (ps:ps (ps:lisp (cons 'ps:array (example))))
"[1, 2, 3];"
我在 Common Lisp (SBCL) 中使用 Paresncript。在调用一个名为 (write-input-data)
的辅助函数后,REPL returns 一个字符串列表:
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 做些什么来修复它吗?
显然,我可以解析字符串并删除括号a posteriori,但我想这个问题有更好的方法.
==== 已更新
伟大的用户@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');"
您的 ps:lisp
表单需要构建 ps:ps
应该翻译的表单。所以:
CL-USER> (ps:ps (ps:lisp (cons 'ps:array (example))))
"[1, 2, 3];"