commit a904609b64f118c08ea9dd9f76fe1812f7cb0f9d
parent ee0e5218a4589d7a7bdb363c20c851988dbf50ca
Author: Yuval Langer <yuval.langer@gmail.com>
Date: Fri, 7 Jul 2023 14:42:02 +0300
We are safe after all.
Diffstat:
1 file changed, 26 insertions(+), 8 deletions(-)
diff --git a/kaka.farm/call-process-chatgpt.org b/kaka.farm/call-process-chatgpt.org
@@ -119,16 +119,21 @@ We are safe...
for now.
-** I spoke too soon.
+** Yes, we are safe.
https://chat.openai.com/share/08cc30e5-21ce-4549-9f3b-7de82d40f9b9
+Copying it here:
+
+#+begin_quote
Shared Chat•
Model: Default
Improve Lisp program.
July 7, 2023
can you improve this program please?
+#+end_quote
+#+begin_src elisp
(progn
(defun kakafarm/call-process-with-string-as-input (program &optional input-string &rest args)
(with-temp-buffer
@@ -161,12 +166,17 @@ can you improve this program please?
nil
"-n"
"echo echo echo")))
+#+end_src
+
+#+begin_quote
ChatGPT
Certainly! Here's an improved version of the program:
lisp
+#+end_quote
+#+begin_src elisp
(defun kakafarm/call-process-with-string-as-input (program &optional input-string &rest args)
(if input-string
(with-temp-buffer
@@ -176,7 +186,9 @@ lisp
(list (kakafarm/call-process-with-string-as-input "cat" "cat says moo")
(kakafarm/call-process-with-string-as-input "echo" nil "-n" "echo echo echo")))
+#+end_src
+#+begin_quote
Improvements:
Removed unnecessary progn wrapper around the defun.
@@ -193,16 +205,21 @@ ChatGPT
Apologies for the misunderstanding. If you would like the whole progn expression to return a string instead of inserting it into a buffer, you can use the with-output-to-string macro. Here's the updated code:
lisp
+#+end_quote
-(defun kakafarm/call-process-with-string-as-input (program &optional input-string &rest args)
- (with-output-to-string
- (if input-string
- (with-input-from-string input-string
- (apply 'call-process-region program nil standard-output nil args))
- (apply 'call-process program nil standard-output nil args))))
+#+begin_src elisp
+ (progn
+ (defun kakafarm/call-process-with-string-as-input (program &optional input-string &rest args)
+ (with-output-to-string
+ (if input-string
+ (with-input-from-string input-string
+ (apply 'call-process-region program nil standard-output nil args))
+ (apply 'call-process program nil standard-output nil args))))
-(kakafarm/call-process-with-string-as-input "cat" "cat says moo")
+ (kakafarm/call-process-with-string-as-input "cat" "cat says moo"))
+#+end_src
+#+begin_quote
In this version, the with-output-to-string macro captures the output of the progn expression and returns it as a string. The standard-output stream is used as the output destination for the call-process-region or call-process functions, depending on whether an input string is provided.
Please note that the (kakafarm/call-process-with-string-as-input "echo" nil "-n" "echo echo echo") part from your original code has been removed since it wasn't necessary for demonstrating the changes. Feel free to add it back if needed.
@@ -213,3 +230,4 @@ Terms of use
Privacy policy
Improve Lisp program.
+#+end_quote