guile-user
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: perpetual newbie asks a question...


From: Eric E Moore
Subject: Re: perpetual newbie asks a question...
Date: 30 Jun 2001 22:00:45 +0100
User-agent: Gnus/5.0808 (Gnus v5.8.8) Emacs/20.7

>>>>> "Tom" == Tom Foster <address@hidden> writes:

Tom> howdy guys, This is ever so easy, I'm sure, but why does this not
Tom> behave the way I want it to?

Tom> (begin 
Tom>  (display "file name?")  
Tom>  (newline) 
Tom>  (define file-name (read)) 
Tom>  (open-output-file file-name) 
Tom>  (display "hello there" file-name) 
Tom>  (close-output-port file-name))

1) read does not read into a string, which is what open-output-file
   expects.  instead, read returns a single scheme object, which
   probably in this case would be a symbol.  

2) that's not how open-output-file works.  it takes a string, returns
   a port.  

3) using define in a begin like that is nonstandard, if legal at all
   and liable to cause flamewars on the list

A correct version would be closer to:

(begin
  (display "file-name?")
  (newline)
  (let* ((file-name (read-line))
         (f (open-output-file file-name)))
    (display "hello there" f)
    (newline f)
    (close-output-port f)))

  -Eric




reply via email to

[Prev in Thread] Current Thread [Next in Thread]