lisp - How to write to a file in tinyscheme? -


scheme implementation : tinyscheme

here try:

(with-output-to-file "biophilia.c"   (lambda (output-port)     (write "hello" output-port))) 

ceates biophilia.c following content:

error: ( : 26) not enough arguments

what doing wrong here? how repair it?

(define (with-output-to-file s p)      (let ((outport (open-output-file s)))           (if (eq? outport #f)                #f                (let ((prev-outport (current-output-port)))                     (set-output-port outport)                     (let ((res (p)))                          (close-output-port outport)                          (set-output-port prev-outport)                          res))))) 

you calling with-output-to-file incorrectly.

the second argument thunk, , not procedure expecting port argument.

so call like:

(with-output-to-file "biophilia.c"   (lambda ()     (write "hello"))) 

with-output-to-file re-binding of current-port (as tried in reconstruction).

see racket docs here.


Comments

Popular posts from this blog

django - How can I change user group without delete record -

java - Need to add SOAP security token -

java - EclipseLink JPA Object is not a known entity type -