I am using a Windows 11 computer, running Steel Bank Common Lisp (version 2.0.0) in PowerShell by inputting functions directly into the SBCL.exe REPL to see if they work. In the process, I have hit upon a problem with the following code.
The point of this function is to take the string passed into it and trim off excess spaces (for example, "This is a string" becomes "This is a string")
(defun trim-spaces (str)
(let*
((len (length(str)))
(i 1)
(last-char (char str (- 1 i)))
(curr-char (char str i)) )
(dotimes (i len)
(cond
((eql last-char #\Space)
(cond
((eql curr-char #\Space)
(setq str (remove curr-char str)))))))))
(trim-spaces "This is a string")
I have made similar functions before (such as one function to remove parentheses from a string) and they have worked fine. In this case, however, if I run the above code, I get the following message. This message is the same if I input a string variable instead of a string literal:
debugger invoked on a UNDEFINED-FUNCTION @1000000C2C in thread #<THREAD tid=19952 "main thread" RUNNING {1100BC8003}>: The function COMMON-LISP-USER::STR is undefined.
I would like to know how this problem is coming about, and how to fix/sidestep it. Thank you for your time.
(length(str))count as a typo?(str)should be juststr. - I don't underestand why you guys closed this question. It contained all information necessary and needed. The code shows everything and he told what is the interpreter and his OS - and the error which makes clear what the problem was. No need to close it.dotimesdoes not depend oni