0

Please help me to do define a string like this..

I have a list which has the values (define temp-list (list '398 '150 '1.15 '2875 '-900 '1565 '800 '230 '200 '0 '0 '0))

I Should declare this as.. (define b "398 150 1.15 2875 -900 1565 800 230 200 0 0 0")

How can i do this in scheme?

2
  • 1
    Looks like homework... if so, be sure to cite the helpful fellow who provided you with the answer! Commented Oct 13, 2011 at 7:24
  • 1
    There's no reason to quote numbers. Commented Oct 13, 2011 at 12:28

2 Answers 2

2

If you have SRFI 13 loaded, you can use string-join like so:

(define b (string-join (map number->string temp-list)))
Sign up to request clarification or add additional context in comments.

Comments

1

See http://codepad.org/8DH8mCTQ:

(define temp-list (list '398 '150 '1.15 '2875 '-900 '1565 '800 '230 '200 '0 '0 '0))

(define b
    (let loop ((xs temp-list) (zs '()))
      (if (null? (cdr xs))
          (apply string-append (reverse (cons (number->string (car xs)) zs)))
          (loop (cdr xs) (cons " " (cons (number->string (car xs)) zs))))))

(write b)

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.