String + 1

You have problems, and we're glad to hear them. Explain the problem, what you have tried, and where you got stuck.
Feel free to share a little info on yourself and the course.
Forum rules
Please respect your teacher's guidelines. Homework is a learning tool. If we just post answers, we aren't actually helping. When you post questions, be sure to show what you have tried or what you don't understand.

String + 1

Postby Ehsan » Sat Jul 14, 2012 2:16 am

Hi everyone . i need to write a function in lisp that receive string and then add 1 to each characters. for example "2a6c12" and then return "3b7d23".

i write this function

(defun my-list(f)
(loop for x across f collect(code-char(+ 1 (char-code x)))))

but my output like this (#\3 #\b #\7 #\d #\2 #\3) . how can i change this output to normal form ("3b7d23")

tnx a lot
Posts: 8
Joined: Thu Jul 12, 2012 7:39 am

Re: String + 1

Postby Goheeca » Sat Jul 14, 2012 2:52 am

Try this:
Code: Select all
(concatenate 'string '(#\a #\b))

or ugglier:
Code: Select all
(coerce '(#\a #\b) 'string)
cl-2dsyntax is my attempt to create a Python-like reader. My mirror of CLHS (and the dark themed version). Temporary mirrors of aferomentioned: CLHS and a dark version.
User avatar
Posts: 267
Joined: Thu May 10, 2012 12:54 pm

Return to Homework

Who is online

Users browsing this forum: Yahoo [Bot] and 1 guest