* * *

Author Topic: writeln function signature  (Read 1797 times)

rgh

  • New member
  • *
  • Posts: 40
writeln function signature
« on: May 18, 2017, 08:31:20 pm »
I seem to be baffled by even the simplest of things.

Code: Pascal  [Select]
  1. Program test_writeln;
  2. begin
  3.   writeln('a ',123,' b');
  4. end.

compiles ok, and looks like writeln takes any number of arguments that get somehow converted to Strings, concatenated & printed.

Looking at the documentation for writeln

https://www.freepascal.org/docs-html/rtl/system/writeln.html

Code: Pascal  [Select]
  1. procedure Writeln(
  2.   Args: Arguments
  3. );
  4.  

it seems to take an argument of type Arguments.

So, what sort of thing is an Arguments instance? It's not an object pascal keyword and using a web search for it's definition, as far as I can see, turns up nothing.

Looking in my old Delphi 6 documentation reveals no such type.

Could anyone shed light?

 
« Last Edit: May 18, 2017, 08:37:28 pm by rgh »

Leledumbo

  • Hero Member
  • *****
  • Posts: 7649
  • Programming + Glam Metal + Tae Kwon Do = Me

rgh

  • New member
  • *
  • Posts: 40
Re: writeln function signature
« Reply #2 on: May 18, 2017, 09:58:21 pm »
Thanks Leledumbo.

I've since looked at the Delphi 6 documentation for

Code: Pascal  [Select]
  1. procedure Write( [var F: Text; ] P1 [ , P2,..., Pn] );

which seems equally incapable of being cleanly expressed in terms of Object Pascal datatypes, although there is a full description of how it works.

In java, which I've been using for a while, the signatures for the various overloads of, for example, PrintStream.printf() seem, in comparison, very easy to describe.

Code: Java  [Select]
  1. public PrintStream printf(String format, Object... args)

I guess I just used to use write() in Pascal without worrying that I didn't understand it.
 

marcov

  • Global Moderator
  • Hero Member
  • *****
  • Posts: 5644
Re: writeln function signature
« Reply #3 on: May 18, 2017, 10:00:18 pm »
In java, which I've been using for a while, the signatures for the various overloads of, for example, PrintStream.printf() seem, in comparison, very easy to describe.

Code: Java  [Select]
  1. public PrintStream printf(String format, Object... args)

I guess I just used to use write() in Pascal without worrying that I didn't understand it.

Yes, Java is a bit terse on IO, and only has library functions. Pascal has builtin ones like write(str)(ln) that allow to specify precision directly on the variable without formatstring encryption
« Last Edit: May 19, 2017, 09:44:47 am by marcov »

Eugene Loza

  • Sr. Member
  • ****
  • Posts: 449
    • My "almost daily" development blog
Re: writeln function signature
« Reply #4 on: May 18, 2017, 10:04:14 pm »
You might want to check 2.8 and 2.9 here https://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_output_logging
In short, yes, you cannot create your own function, which operates similarly to write/writeln.

You can still create some function like:
Code: Pascal  [Select]
  1. Procedure MyProcedure(MyInput: array of string);
  2. ...
  3. MyProcedure(['Hello','World']);
to accept multiple strings.

You might even try something like:
Code: Pascal  [Select]
  1. Procedure MyProcedure(MyInput: array of variant);
to handle mix of different types.
« Last Edit: May 18, 2017, 10:09:33 pm by Eugene Loza »
My Free and Open Source games in Lazarus/FreePascal/CastleGameEngine:
https://decoherence.itch.io/
(and some ancient games in Turbo Pascal too)
Sources are here: https://github.com/eugeneloza?tab=repositories

Cyrax

  • Hero Member
  • *****
  • Posts: 537
Re: writeln function signature
« Reply #5 on: May 18, 2017, 10:05:52 pm »
You might want to check 2.8 and 2.9 here https://michalis.ii.uni.wroc.pl/~michalis/modern_pascal_introduction/modern_pascal_introduction.html#_output_logging
In short, yes, you cannot create your own function, which operates similarly to write/writeln.

Actually, you can but it requires some changes in the compiler sources.

molly

  • Hero Member
  • *****
  • Posts: 1806
Re: writeln function signature
« Reply #6 on: May 19, 2017, 12:00:36 am »
You might even try something like:
Code: Pascal  [Select]
  1. Procedure MyProcedure(MyInput: array of variant);
to handle mix of different types.
or array of const or pass a record/object/class.
« Last Edit: May 19, 2017, 12:02:50 am by molly »

rgh

  • New member
  • *
  • Posts: 40
Re: writeln function signature
« Reply #7 on: May 19, 2017, 12:35:12 am »
I can see there are various ways of writing methods in Pascal that take an arbitrary number of arguments.

However, I think the important issue is that the function, as at

https://www.freepascal.org/docs-html/rtl/system/writeln.html

is undocumented. Were it not for the fact that I happen to have an old Delphi installation, I'd still have no idea what parameters I'd be allowed to supply and would be dependent on fellow users here answering my enquiry. Assuming, that is, that write does indeed behave identically to that in Delphi or Turbo Pascal.

Not every new user coming to fpc is going to have Delphi documentation to fall back on.

ok, so I realize that the documentation is a community effort and I'm free to pitch in myself, but I don't understand the language well enough to do so, as my various questions here probably illustrate.

molly

  • Hero Member
  • *****
  • Posts: 1806
Re: writeln function signature
« Reply #8 on: May 19, 2017, 12:59:56 am »
is undocumented. Were it not for the fact that I happen to have an old Delphi installation, I'd still have no idea what parameters I'd be allowed to supply and would be dependent on fellow users here answering my enquiry. Assuming, that is, that write does indeed behave identically to that in Delphi or Turbo Pascal.
I think the 'problem' there is that the link you provided is documentation that is auto-generated from source-code.

Write, WriteLn and WriteStr use 'special' constructs that can't be easily 'captured' in the context of the documentation engine.

Leledumbo

  • Hero Member
  • *****
  • Posts: 7649
  • Programming + Glam Metal + Tae Kwon Do = Me
Re: writeln function signature
« Reply #9 on: May 19, 2017, 08:00:18 am »
Compiler built-in procs (I prefer call it command instead) documentation is generated from rtl/inc/system.fpd in the source directory, this is because they don't have any actual declaration.

Thaddy

  • Hero Member
  • *****
  • Posts: 4439
Re: writeln function signature
« Reply #10 on: May 19, 2017, 09:37:14 am »
Write and writeln and its formatting options seems to be a kind of lost art, but the manual entry for write is pretty decent:
https://www.freepascal.org/docs-html/rtl/system/write.html

It also explains the format specifiers.

Note we have also writestr which takes the same format specifiers and can be used in a similar fashion as the format function.

Indeed, it is achieved through compiler magic.
Note that this family of commands pre-dates object oriented pascal by at least a decade and as such there isn't much "object" in it.
Although now most simple types have their own formatting options build in, so you can use that in a similar fashion to Java formatting. (Needs sysutils)

write(ln) is part of the original input/output functionality as defined for the Pascal language.

« Last Edit: May 19, 2017, 10:00:25 am by Thaddy »
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Zoran

  • Hero Member
  • *****
  • Posts: 1148
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: writeln function signature
« Reply #11 on: May 19, 2017, 10:10:52 am »
However, I think the important issue is that the function, as at

https://www.freepascal.org/docs-html/rtl/system/writeln.html

is undocumented.

What is undocumented? It gives link to "write" where you can find more details.

Not every new user coming to fpc is going to have Delphi documentation to fall back on.

Delphi docs are available online:
http://docwiki.embarcadero.com/Libraries/en/System.Writeln
http://docwiki.embarcadero.com/Libraries/en/System.Write

You can see that Delphi's writeln documentation also does not contain formatting details, but it also links to "write". I admit, though, that delphi's "write" documentation is more detailed than fpc's.

Thaddy

  • Hero Member
  • *****
  • Posts: 4439
Re: writeln function signature
« Reply #12 on: May 19, 2017, 10:24:03 am »
You can see that Delphi's writeln documentation also does not contain formatting details, but it also links to "write". I admit, though, that delphi's "write" documentation is more detailed than fpc's.
Well, I wouldn't say more detailed, but less terse. The details are there but in less prosaic description. If you think it needs improvement, we know that Michael usually takes over any valid suggestions for improvement.
"Logically, no number of positive outcomes at the level of experimental testing can confirm a scientific theory, but a single counterexample is logically decisive."

Zoran

  • Hero Member
  • *****
  • Posts: 1148
    • http://wiki.lazarus.freepascal.org/User:Zoran
Re: writeln function signature
« Reply #13 on: May 19, 2017, 11:58:05 am »
Well, I wouldn't say more detailed, but less terse. The details are there but in less prosaic description.

I agree. And my point was that it IS documented well.

If you think it needs improvement, we know that Michael usually takes over any valid suggestions for improvement.

I don't think that it needs improvement (except in sense that everything can be improved).

rgh

  • New member
  • *
  • Posts: 40
Re: writeln function signature
« Reply #14 on: May 20, 2017, 11:41:54 am »
And my point was that it IS documented well.
Looking through the fp documentation  now, after this discussion, I can see that my claim that writeln is undocumented was incorrect. I do think however that my old Delphi documentation is easier to understand in two respects.

Firstly, from the fp docs:

Code: Pascal  [Select]
  1. procedure Write(
  2.   Args: Arguments
  3. );

made me start looking for an Arguments class or interface, of which Args would be required to be an instance.

Secondly, the fp documentation continues:
Quote
Write writes the contents of the variables V1, V2 etc. to the file F.
where did V1, V2 come from?

The Delphi documentation has signature
Code: Pascal  [Select]
  1. procedure Write( [var F: Text; ] P1 [ , P2,..., Pn] );
and then goes on describe that each P is
Quote
Each P is a write parameter. Each write parameter....

Anyway, it's no big deal & thanks to posters on this thread who have helped me understand the situation.

 

Recent

Get Lazarus at SourceForge.net. Fast, secure and Free Open Source software downloads Open Hub project report for Lazarus