lisp function to concatenate a list of strings -


I have to type a function that will add a list to a string. Example:

(concatString (quote ("Hello" "World"))) ==> "Hello World" Here is what I have done so far:

  (defun concatString (list) "is a non-recursive function that combines a list of strings . "Check that the parameter is a list (if (tap (list)), check which list is in the list tap (no (result (car list) (Dolist (item (CDR list)) (if ( String item) (set result (insert result item)))))))   

me "error": "hello" and invalid type specifier "I'm getting the message when I try to run it. I have tried several ways to modify this function and I am able to understand it. Anyone have any ideas?

add requires sequence type specifier as your second argument To add strings, you should call concatenate :

  (concatenate 'string' hello "" world ")   < P> your Another bug in the code you are not sure whether the list of  car  is a string before specifying the code on the  Result . Correcting my code, I came up with the following implementation:  
  (defun concatString (list) "is a non-recursive function that combines the list of strings." (If (listp list) (Result "")) (Doctor (item list) (if (string item) (setq result (insert 'string result items))))));) ;; Test & gt; (Cockat String (List "Hello" "World")) "Hello World" & gt; (Cockat String (List "Hello" 1 2 3 "World")) "Hello World" & gt; (Cockat String (List "Hello" 1 2 "3" "World")) "Hello 3 World" & gt; The following reddition of Concatstring (list 1 2 3 "Hello" "World")) "Hello World"   

concatString is more efficient because it does not produce Many intermediate string objects:

  (defun concatString (list) "A non-recursive function that combines a list of strings." (If (listp list) (output-to-string (S ) (Dollist (item list) (if (string item) (format "~ A" items)))))    

Comments