0

使用 TinyScheme。

我正在将我的代码写入文件(在这里解决了 50%:如何在 tinyscheme 中写入文件?):

(with-output-to-file "biophilia.c"
  (lambda ()
    (write code)
    ))
; and segmentation fault comes here

但它用 "" qotes 和 \n\r 编写我的代码,因此它不会将其转换为换行符。

我需要编写看起来像的代码(display code)

球拍文档中的示例中有 printf,但似乎 TinyScheme 实现没有 printf,也许我需要发现(添加它的代码)printf?

4

2 回答 2

1

你可以试试:

(call-with-output-file "biophilia.c" 
    (lambda (port) 
        (write-string code port)))

提供的“代码”是一个字符串。它将删除任何转义,并将其写入纯文本。

于 2015-05-10T23:39:38.280 回答
0

找到解决方案,唯一的解决方法是将前挂 put-char 改为 write-char

  (define assert
    (lambda (aa msg)
      (if (null? aa)
    #t
    (if (not (car aa))
      (error msg)
      (assert (cdr aa) msg))))) 

 (display "define fprintf\n\r")
(define (fprintf port f . args)
   (let ((len (string-length f)))
     (let loop ((i 0) (args args))
       (cond ((= i len) (assert (null? args)))
         ((and (char=? (string-ref f i) #\~)
           (< (+ i 1) len))
          (dispatch-format (string-ref f (+ i 1)) port (car args))
          (loop (+ i 2) (cdr args)))
         (else
          (write-char (string-ref f i) port)
          (loop (+ i 1) args))))))

(display "define printf\n\r")
(define (printf f . args)
   (let ((port (current-output-port)))
     (apply fprintf port f args)
     (flush-output-port port)))

    (display "writing to output file biophilia.c\n\r")
    (with-output-to-file "biophilia.c"
      (lambda ()
        (printf code)
        ))

代码不再出现段错误

但在文件末尾:错误:(:25)没有足够的参数

于 2012-06-06T07:08:11.770 回答