why format procedure produce error?

View: New views
4 Messages — Rating Filter:   Alert me  

why format procedure produce error?

by Changying Li :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

in the guile manual:
 -- Scheme Procedure: format dest fmt [args...]
     Write output specified by the FMT string to DEST.  DEST can be an
     output port, `#t' for `current-output-port' (*note Default
     Ports::), a number for `current-error-port', or `#f' to return the
     output as a string.

what's the meaning of NUMBER?
I want to write things to error port, so I write
(format 1 "hello")

standard input:5:1: In procedure simple-format in expression (format 1 "hello"):
standard input:5:1: Wrong type argument in position 1: 1
ABORT: (wrong-type-arg)


it work when I use (format (current-error-port) "hello")

Is there something wrong in the guile manual ?


--

Thanks & Regards

Changying Li




Re: why format procedure produce error?

by Linas Vepstas-3 :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

2009/11/11 Changying Li <lchangying@...>:

> in the guile manual:
>  -- Scheme Procedure: format dest fmt [args...]
>     Write output specified by the FMT string to DEST.  DEST can be an
>     output port, `#t' for `current-output-port' (*note Default
>     Ports::), a number for `current-error-port', or `#f' to return the
>     output as a string.
>
> what's the meaning of NUMBER?
> I want to write things to error port, so I write
> (format 1 "hello")
>
> standard input:5:1: In procedure simple-format in expression (format 1 "hello"):
> standard input:5:1: Wrong type argument in position 1: 1
> ABORT: (wrong-type-arg)
>
>
> it work when I use (format (current-error-port) "hello")
>
> Is there something wrong in the guile manual ?


That would be my guess.  I assume that once upon a time,
an integer was interpreted as a file or socket number, but
that this code was later disabled, and the documentation
was not changed.  I guess that supporting fileno would have
made an mswindows version difficult -- besides, raw fileno
numbers are kind of a bad idea in this day and age.

--linas



Re: why format procedure produce error?

by Changying Li :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message


I can't agree you more...

Linas Vepstas <linasvepstas@...> writes:

> 2009/11/11 Changying Li <lchangying@...>:
>> in the guile manual:
>>  -- Scheme Procedure: format dest fmt [args...]
>>     Write output specified by the FMT string to DEST.  DEST can be an
>>     output port, `#t' for `current-output-port' (*note Default
>>     Ports::), a number for `current-error-port', or `#f' to return the
>>     output as a string.
>>
>> what's the meaning of NUMBER?
>> I want to write things to error port, so I write
>> (format 1 "hello")
>>
>> standard input:5:1: In procedure simple-format in expression (format 1 "hello"):
>> standard input:5:1: Wrong type argument in position 1: 1
>> ABORT: (wrong-type-arg)
>>
>>
>> it work when I use (format (current-error-port) "hello")
>>
>> Is there something wrong in the guile manual ?
>
>
> That would be my guess.  I assume that once upon a time,
> an integer was interpreted as a file or socket number, but
> that this code was later disabled, and the documentation
> was not changed.  I guess that supporting fileno would have
> made an mswindows version difficult -- besides, raw fileno
> numbers are kind of a bad idea in this day and age.
>
> --linas
>
>
>

--

Thanks & Regards

Changying Li




Re: why format procedure produce error?

by Neil Jerram :: Rate this Message:

Reply to Author | View Threaded | Show Only this Message

Changying Li <lchangying@...> writes:

> in the guile manual:
>  -- Scheme Procedure: format dest fmt [args...]
>      Write output specified by the FMT string to DEST.  DEST can be an
>      output port, `#t' for `current-output-port' (*note Default
>      Ports::), a number for `current-error-port', or `#f' to return the
>      output as a string.
>
> what's the meaning of NUMBER?
> I want to write things to error port, so I write
> (format 1 "hello")
>
> standard input:5:1: In procedure simple-format in expression (format 1 "hello"):
> standard input:5:1: Wrong type argument in position 1: 1
> ABORT: (wrong-type-arg)

You need to add (use-modules (ice-9 format)) to your code, to get the
full implementation of `format'.  Then the "number means
current-error-port" thing should work.

At the moment, you're actually using `simple-format'.

> Is there something wrong in the guile manual ?

I don't think so, because the documentation that you cited comes from a
section that begins by saying that

   "This function is available from

     (use-modules (ice-9 format))"

Regards,
        Neil