I am using Paresncript in Common Lisp (SBCL). After invoking an auxiliary function called (write-input-data)
, the REPL returns a list of strings:
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")
Then, I try to convert it to an array filled with strings in javascript syntax:
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')];"
The result is almost perfect. Unfortunately, there are 2 problems. First, on the beginning, there is a left parenthesis as:
'2937'('AVpKuU6t_T0'
And it should be a comma:
'2937' , 'AVpKuU6t_T0'
.
The second error is in the end. There is a right parenthesis:
'NIL')];"
It was expected to have nothing, just:
'NIL' ];"
Why is this happening? Is there something I could do with parenscript to fix it?
Obviously, I can parse the string and remove the parenthesis a posteriori, but I guess there is a better approach for this problem.
==== UPDATED
Great user @Barmar, suggested using nothing to fix this. We are almost there. If I do:
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"))
I get exactly what I want:
"['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'];"
The only problem is that I inserted the list directly. And I need to insert it indirectly through a function call of (write-data)
. If I try just inserting the function call it does not work:
CL-USER> (ps:ps (write-input-data))
"writeInputData();"
If I try something similar using the (ps:lisp
trick, exactly the same problem happens with the parenthesis and no array is created:
> (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');"
Your ps:lisp
form needs to construct the form that ps:ps
should translate. So:
CL-USER> (ps:ps (ps:lisp (cons 'ps:array (example))))
"[1, 2, 3];"