2016-11-07 9 views
1

를 문자열 구분 기호를 유지하면서 나는과 같이 라켓의 목록을 가지고 :인쇄 원시 제어 문자 출력 (라켓)

'(some-symbol 
    "some\ntext\ngoes in\nhere") 

내가 \n 같은 제어 문자는 그 값으로 변환되도록 그것을 밖으로 인쇄 할 ,이 경우 줄 바꿈. 그러나 출력 문자열에 write 또는 print의 문자열에 따옴표 (예 : 구분 기호)를 보존하기를 원합니다. display 함수는 이미 내가 원하는 첫 번째 부분을 수행하지만, \"처럼 이스케이프 처리되지 않은 따옴표는 제거합니다. 예컨대 :

[email protected]> (displayln '(some-symbol "some\ntext\ngoes in\nhere")) ;; I want the linefeeds as produced here 
(some-symbol some 
text 
goes in 
here) 
[email protected]> (println '(some-symbol "some\ntext\ngoes in\nhere")) ;; But I also want the quotation marks as preserved here 
'(some-symbol "some\ntext\ngoes in\nhere") 
[email protected]> 

\" 같은 문자열 구분 기호를 탈출하지 않고 라켓 출력 효과의 종류를 얻을 수있는 몇 가지 방법이 있나요? 또한 출력에서리스트 앞에있는 ' 문자를 원하지 않습니다.

답변

1

그것은, 그래서 거기에 당신이 주변에 강타 할 수있는 허수아비를 만들어 보자 정확히 당신이 원하는 분명하지 않다 : 당신이 원하는 무엇을

#lang racket 

(require rackunit) 

;; find every string in an s-expression, add quotes to it: 
(define (add-quotes s) 
    (cond [(list? s) 
     (map add-quotes s)] 
     [(string? s) 
     (string-append "\"" s "\"")] 
     [else s])) 

(check-equal? (add-quotes '((a b "cde") (("g") f))) 
       '((a b "\"cde\"") (("\"g\"") f))) 

;; display s with quotes around strings: 
(define (funny-display s) 
    (display (add-quotes s))) 

하지?

+0

이것은 내가 원하는 것을 수행합니다. 고맙습니다. 미안하지만 질문이 명확하지 않은 경우. – GDP2