• Re: Printing beyond printf

    From James Harris@james.harris.1@gmail.com to comp.lang.misc on Tue Dec 12 16:10:29 2023
    From Newsgroup: comp.lang.misc

    On 09/01/2022 22:05, Andy Walker wrote:
    On 08/01/2022 17:15, James Harris wrote:
    If you are not convinced by formatted io then what kind of io do
    you prefer?
         Unformatted transput, of course.  Eg,
       print this, that, these, those and the many other things
    OK. I would say that that has /default/ formatting but is still
    formatted.

        You can say that if you insist, but ISTM to be an abuse of language.  The point about /formatted/ transput is that the user
    prescribes some "mould" into which objects such as integers [for
    output] or strings [for input] are "poured" for conversion.  So
    we get calls like "printf (some_mould, some_value)".  It's a
    useful distinction from unformatted transput, where the user does
    not specify any mould.

    You seem to be thinking about printing a number using some character set
    - perhaps even some particular base, such as decimal. All of those are, surely, kinds of formatting. If the default formatting is decimal, with
    no leading zeroes and left justified then that's still a way to format a number.
    --
    James Harris


    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Andy Walker@anw@cuboid.co.uk to comp.lang.misc on Wed Dec 13 16:39:10 2023
    From Newsgroup: comp.lang.misc

    On 12/12/2023 16:10, James Harris wrote:
    On 09/01/2022 22:05, I wrote:
    [...] The point about /formatted/ transput is that the user
    prescribes some "mould" into which objects such as integers [for
    output] or strings [for input] are "poured" for conversion.  So
    we get calls like "printf (some_mould, some_value)".  It's a
    useful distinction from unformatted transput, where the user does
    not specify any mould.
    You seem to be thinking about printing a number using some character
    set - perhaps even some particular base, such as decimal. All of
    those are, surely, kinds of formatting. If the default formatting is
    decimal, with no leading zeroes and left justified then that's still
    a way to format a number.

    Yes, of course it is, but you have [again] lost the distinction
    between a format specified by the programmer and a default. Sometimes
    you just want to see the numbers [or whatever]; other times, it matters
    to you how they are formatted. In the one case, you don't want to have
    to spend time thinking about what format to use [esp while debugging];
    in the other, the layout of the output is important. It's more stark on
    input; a default read should be able to read what's there if /you/ can, whereas a formatted read can [eg] split up "123abc0456hello" into a
    6-digit hex integer, a 4-digit decimal integer and a 5-char string.
    OTOH, an unformatted read could split "123abc 456 hello" into a hex
    integer, a decimal integer and a string without having to be told how
    many characters to allow for each. It's not an /essential/ difference,
    just a convenience for real-life users. So it's a reason for a language
    to provide both.
    --
    Andy Walker, Nottingham.
    Andy's music pages: www.cuboid.me.uk/andy/Music
    Composer of the day: www.cuboid.me.uk/andy/Music/Composers/Mendelssohn
    --- Synchronet 3.20a-Linux NewsLink 1.114
  • From Thomas Koenig@tkoenig@netcologne.de to comp.lang.misc on Sat Dec 16 13:07:30 2023
    From Newsgroup: comp.lang.misc

    Andy Walker <anw@cuboid.co.uk> schrieb:
    Sometimes
    you just want to see the numbers [or whatever]; other times, it matters
    to you how they are formatted. In the one case, you don't want to have
    to spend time thinking about what format to use [esp while debugging];
    in the other, the layout of the output is important.

    In Fortran, the former is list-formatted output. Using

    write (10,*) asdf

    will write the value of the expression asdf to unit 10 in a format
    of the compiler's choosing, terminating that record (i.e. writing
    a newline).

    write (10,'(I4)') asdf

    will write the value of asdf, if asdf is an integer, to
    unit 10 with a width of four characters, right-justified
    and filled up with spaces. If the value does not fit, four
    asterisks are written instead. This statement will also terminate

    If asdf is not an integer, then this is an error, which is usually
    caught by the compiler at either compile or run-time.
    --- Synchronet 3.20a-Linux NewsLink 1.114