comp.lang.ada
 help / color / mirror / Atom feed
* questions on input/output
@ 2021-02-05 22:50 Mehdi Saada
  2021-02-05 23:36 ` Jeffrey R. Carter
  2021-02-06  9:36 ` Dmitry A. Kazakov
  0 siblings, 2 replies; 18+ messages in thread
From: Mehdi Saada @ 2021-02-05 22:50 UTC (permalink / raw)


I can't understand how input/output works.
1) on text files - not keyboard input - what's the difference between get_immediate and get ?
2) what means "consumming" characters, if indices don't change ?
3) can set_col be used or not, to go back in a line in an IN_FILE file ?
I get a good "END_ERROR" when I try that. what's the trick then ?

I did read the rm or whatnot, or other resources, but language doesn't help me... or I guess I do things the wrong way.

I need: to read a character, until some marker, then go back (set_col(stored_position)) and read again but store it like Get(variable, FILE); then go past the marker (set_col(FILE,col(file)+1)).

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-05 22:50 questions on input/output Mehdi Saada
@ 2021-02-05 23:36 ` Jeffrey R. Carter
  2021-02-06  0:59   ` Mehdi Saada
  2021-02-06  9:36 ` Dmitry A. Kazakov
  1 sibling, 1 reply; 18+ messages in thread
From: Jeffrey R. Carter @ 2021-02-05 23:36 UTC (permalink / raw)


On 2/5/21 11:50 PM, Mehdi Saada wrote:
> I can't understand how input/output works.
> 1) on text files - not keyboard input - what's the difference between get_immediate and get ?

Get_Immediate might behave differently at a line terminator.

> 2) what means "consumming" characters, if indices don't change ?

It is usually best to only use Get_Immediate with Standard_Input, and to ignore 
the column, line, and page counting and setting operations.

> 3) can set_col be used or not, to go back in a line in an IN_FILE file ?

You cannot go back in a text file. Only Direct_IO and Stream_IO support this.

> I need: to read a character, until some marker, then go back (set_col(stored_position)) and read again but store it like Get(variable, FILE); then go past the marker (set_col(FILE,col(file)+1)).

You will probably want to store the characters that you read in a string and 
obtain the value from it.

-- 
Jeff Carter
"I wave my private parts at your aunties."
Monty Python & the Holy Grail
13

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-05 23:36 ` Jeffrey R. Carter
@ 2021-02-06  0:59   ` Mehdi Saada
  2021-02-06  1:34     ` Mehdi Saada
  2021-02-06  7:21     ` J-P. Rosen
  0 siblings, 2 replies; 18+ messages in thread
From: Mehdi Saada @ 2021-02-06  0:59 UTC (permalink / raw)


storing characters in a string I don't know what size it will be is unsightly. I could set length = 10 but oh God that's ugly.
I had no idea input/output was that cumbersome !
what about reset followed by set_col(saved_column) ?
I have to tweak one thing at a time so it ain't working perfectly either, but still... can't that work ?

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06  0:59   ` Mehdi Saada
@ 2021-02-06  1:34     ` Mehdi Saada
  2021-02-06  2:13       ` Paul Rubin
  2021-02-06  7:21     ` J-P. Rosen
  1 sibling, 1 reply; 18+ messages in thread
From: Mehdi Saada @ 2021-02-06  1:34 UTC (permalink / raw)


I took me HOURS to finally  understand where my mistake was.
In the end, it's most always our inability to visualize what the computer does exactly !
my reset + set_col works... More elegant that temporary strings.
Ada is my bitch.
... sorry. I'm just overjoyed because finally I do stuff that works and progress.
I'll get some help in math, and I think I'll start the knuth books... or the cormen ?
what do you think, now that I'm positive I could any I choose. Not like years ago.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06  1:34     ` Mehdi Saada
@ 2021-02-06  2:13       ` Paul Rubin
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Rubin @ 2021-02-06  2:13 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:
> I'll get some help in math, and I think I'll start the knuth
> books... or the cormen ?

Maybe start with Knuth, Graham, and Patashnik's "Concrete Mathematics".
It's sort of an easier going version of vol. 1 of TAOCP.  

https://www.powells.com/book/concrete-mathematics-9780201558029

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06  0:59   ` Mehdi Saada
  2021-02-06  1:34     ` Mehdi Saada
@ 2021-02-06  7:21     ` J-P. Rosen
  1 sibling, 0 replies; 18+ messages in thread
From: J-P. Rosen @ 2021-02-06  7:21 UTC (permalink / raw)


Le 06/02/2021 à 01:59, Mehdi Saada a écrit :
> I had no idea input/output was that cumbersome !
It is not, but you have to understand the logic behind it, which might 
be different from what you know from other languages.

For example, Text_IO is compatible with keyboards, async lines, etc. 
What would backspacing mean on these?

And Ada has nice features to make your life easier, especially the 
ability to have dynamically size arrays. If you want a full line and 
don't want to care with the length, just do the following:

declare
    Line : String := Get_Line;
begin
    -- do what you need to do
end;

This will reserve exactly the right size for Line, no possibility of 
buffer overflow, and no wasted space.

-- 
J-P. Rosen
Adalog
2 rue du Docteur Lombard, 92441 Issy-les-Moulineaux CEDEX
Tel: +33 1 45 29 21 52, Fax: +33 1 45 29 25 00
http://www.adalog.fr

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-05 22:50 questions on input/output Mehdi Saada
  2021-02-05 23:36 ` Jeffrey R. Carter
@ 2021-02-06  9:36 ` Dmitry A. Kazakov
  2021-02-06 10:38   ` AdaMagica
  1 sibling, 1 reply; 18+ messages in thread
From: Dmitry A. Kazakov @ 2021-02-06  9:36 UTC (permalink / raw)


On 2021-02-05 23:50, Mehdi Saada wrote:

> I need: to read a character, until some marker, then go back (set_col(stored_position)) and read again but store it like Get(variable, FILE); then go past the marker (set_col(FILE,col(file)+1)).

Do not do it, bad idea anyway. The esoteric features of Text_IO like 
columns etc are not portable. Use Stream_IO instead.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06  9:36 ` Dmitry A. Kazakov
@ 2021-02-06 10:38   ` AdaMagica
  2021-02-06 11:37     ` Mehdi Saada
  2021-02-06 11:47     ` Dmitry A. Kazakov
  0 siblings, 2 replies; 18+ messages in thread
From: AdaMagica @ 2021-02-06 10:38 UTC (permalink / raw)


Dmitry A. Kazakov schrieb am Samstag, 6. Februar 2021 um 10:36:08 UTC+1:
> On 2021-02-05 23:50, Mehdi Saada wrote: 
> 
> > I need: to read a character, until some marker, then go back (set_col(stored_position)) and read again but store it like Get(variable, FILE); then go past the marker (set_col(FILE,col(file)+1)).
> Do not do it, bad idea anyway. The esoteric features of Text_IO like 
> columns etc are not portable. Use Stream_IO instead.

What do you mean by "not portable"?

See:
A.10.5 Operations on Columns, Lines, and Pages

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 10:38   ` AdaMagica
@ 2021-02-06 11:37     ` Mehdi Saada
  2021-02-06 11:51       ` Mehdi Saada
  2021-02-06 11:47     ` Dmitry A. Kazakov
  1 sibling, 1 reply; 18+ messages in thread
From: Mehdi Saada @ 2021-02-06 11:37 UTC (permalink / raw)


Mouahahahahah
I made my task incommensurately more complicated.
I use := Get_line all the time but couldn't think of it, what the hell.
Well in term of algorithmic (and work in tight memory space environment...) it taught me a lot, I value the experience.
Indeed limitations make sense for typewriter, silly me.
Indeed I thought of direct or stream_IO, rather than reset-ing the file again and again. But it's not part of the exo so not now ;-)

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 10:38   ` AdaMagica
  2021-02-06 11:37     ` Mehdi Saada
@ 2021-02-06 11:47     ` Dmitry A. Kazakov
  1 sibling, 0 replies; 18+ messages in thread
From: Dmitry A. Kazakov @ 2021-02-06 11:47 UTC (permalink / raw)


On 2021-02-06 11:38, AdaMagica wrote:
> Dmitry A. Kazakov schrieb am Samstag, 6. Februar 2021 um 10:36:08 UTC+1:
>> On 2021-02-05 23:50, Mehdi Saada wrote:
>>
>>> I need: to read a character, until some marker, then go back (set_col(stored_position)) and read again but store it like Get(variable, FILE); then go past the marker (set_col(FILE,col(file)+1)).
>> Do not do it, bad idea anyway. The esoteric features of Text_IO like
>> columns etc are not portable. Use Stream_IO instead.
> 
> What do you mean by "not portable"?

Because it is unlikely that things would work same for same files on 
different OSes. It was OK in 1983 when you never moved files from OS to 
OS and if you did, you always converted text files. These days text 
files are never converted. So the safe way is to ignore whatever 
conventions which are never enforced anyway and do raw Stream_IO 
handling occasional vertical formatting ASCII characters manually, 
better removing or ignoring them and never rely on their semantics.

-- 
Regards,
Dmitry A. Kazakov
http://www.dmitry-kazakov.de

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 11:37     ` Mehdi Saada
@ 2021-02-06 11:51       ` Mehdi Saada
  2021-02-06 18:10         ` Paul Rubin
  0 siblings, 1 reply; 18+ messages in thread
From: Mehdi Saada @ 2021-02-06 11:51 UTC (permalink / raw)


Okay here's what I've got, excluding, the RM, Barne's, and another book on high-risk/ultra-advanced Ada that I uselessly bought but feel no remorse because I'm a fetishist.
Concrete Mathematics
Daniel J. Velleman-How to prove it_ a structured approach
Introduction to Algorithms Third Edition.pdf
John_W._McCormick,_Frank_Singhoff,_Jérôme_Hugue(b-ok.xyz).pdf
the-science-of-programming-gries
Programming and Problem Solving with Ada 95, Second Edition.pdf
The_Art_of_Computer_Programming - Vol 1.pdf
the Craft of Programming, Reynolds.pdf
thinkcomplexity.pdf

Proving things should come at last. I'm not averse to math but the difficulty isn't absent and I fear losing motivation if I stumble again like before... So my confidence isn't that high. Well, just give your opinion regardless. I want to get sound programming reasoning and understand algos of others, enough to implement them. I don't mind spending hours if it's step by step and high reward... so no unnecessary gimmicks. More theoretical/philosophical stuff, why not, eventually in parallel, if it's enjoyable. Tell which ones and which order.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 11:51       ` Mehdi Saada
@ 2021-02-06 18:10         ` Paul Rubin
  2021-02-06 18:55           ` Mehdi Saada
  0 siblings, 1 reply; 18+ messages in thread
From: Paul Rubin @ 2021-02-06 18:10 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:
> Proving things should come at last.

Why do you want to use Ada (instead of, say, Python) if you don't like
proving things?

It seems to me, you might add a book about logic (proof systems etc.) to
your reading.  I don't know what to recommend.  I used "A Mathematical
Introduction to Logic" by H. B. Enderton and I liked it, but I think it
is not ideal for your purposes.  Maybe someone else has a suggestion.

If nothing else, understanding what proofs really are might make you
more comfortable with them.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 18:10         ` Paul Rubin
@ 2021-02-06 18:55           ` Mehdi Saada
  2021-02-06 20:26             ` Paul Rubin
  2021-02-07  9:55             ` Gautier write-only address
  0 siblings, 2 replies; 18+ messages in thread
From: Mehdi Saada @ 2021-02-06 18:55 UTC (permalink / raw)


> Why do you want to use Ada (instead of, say, Python) if you don't like 
> proving things? 
> If nothing else, understanding what proofs really are might make you 
> more comfortable with them.

Come on... I don't "dislike" them, it's just that focusing on formalism right now isn't very EFFICIENT, pedagogy-wise !
Or I would have started right away with effin' SPARK and proof theory. Would you suggest that to beginners :-D ?
I have the enderton, it's on my mind.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 18:55           ` Mehdi Saada
@ 2021-02-06 20:26             ` Paul Rubin
  2021-02-07  8:52               ` Mehdi Saada
  2021-02-07  9:55             ` Gautier write-only address
  1 sibling, 1 reply; 18+ messages in thread
From: Paul Rubin @ 2021-02-06 20:26 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:
> Or I would have started right away with effin' SPARK and proof
> theory. Would you suggest that to beginners :-D ?

I don't know.  To a pure beginner, probably not, but I wouldn't have
suggested Ada either.

SPARK isn't that connected to proof theory--it's just a program that
verifies contracts on Ada functions.  Proof theory as a topic in logic
is quite a bit different.  There's a book I like called "An Introduction
to Proof Theory" or something close to that, by Herman Ruge Jervell.
You might look for it.  But, I think you have to have already studied
some logic to make much sense of it.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 20:26             ` Paul Rubin
@ 2021-02-07  8:52               ` Mehdi Saada
  2021-02-07 20:38                 ` Paul Rubin
  0 siblings, 1 reply; 18+ messages in thread
From: Mehdi Saada @ 2021-02-07  8:52 UTC (permalink / raw)


Le samedi 6 février 2021 à 20:26:21 UTC, Paul Rubin a écrit :
> I don't know. To a pure beginner, probably not, but I wouldn't have 
> suggested Ada either. 
What is this heresy ?! Personally I never had an issue with the rigor, as a beginner I'm pretty happy the compiler is fø©kîng with my life constantly  ;-)
> SPARK isn't that connected to proof theory--it's just a program that 
> verifies contracts on Ada functions.
Of course but it makes no sense if you're not going to investigate proof making using these, so it is connected... in practice.

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-06 18:55           ` Mehdi Saada
  2021-02-06 20:26             ` Paul Rubin
@ 2021-02-07  9:55             ` Gautier write-only address
  2021-02-07 22:54               ` Mehdi Saada
  1 sibling, 1 reply; 18+ messages in thread
From: Gautier write-only address @ 2021-02-07  9:55 UTC (permalink / raw)


Did you try HAC ?
Some say it's beginner-friendly. You run it like a scripting tool, but it's Ada.
https://hacadacompiler.sourceforge.io/

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-07  8:52               ` Mehdi Saada
@ 2021-02-07 20:38                 ` Paul Rubin
  0 siblings, 0 replies; 18+ messages in thread
From: Paul Rubin @ 2021-02-07 20:38 UTC (permalink / raw)


Mehdi Saada <00120260a@gmail.com> writes:
> What is this heresy ?! Personally I never had an issue with the rigor,
> as a beginner I'm pretty happy the compiler is fø©kîng with my life
> constantly ;-)

You should try Haskell too then ;-).  http://learnyouahaskell.com 

^ permalink raw reply	[flat|nested] 18+ messages in thread

* Re: questions on input/output
  2021-02-07  9:55             ` Gautier write-only address
@ 2021-02-07 22:54               ` Mehdi Saada
  0 siblings, 0 replies; 18+ messages in thread
From: Mehdi Saada @ 2021-02-07 22:54 UTC (permalink / raw)


.> Did you try HAC ? 
> Some say it's beginner-friendly. You run it like a scripting tool, but it's Ada. 
> https://hacadacompiler.sourceforge.io/

"HAC is perhaps the first open-source (albeit partial) Ada compiler fully programmed in Ada itself."
Grrrrr I have an intellectual boner. Thanks. In my to_read list, like, in .. 3 years or so I might be able to understand something !
I'll think of a use for HAC, but it seems neat. Typically the kind of thing I would love to cooperate to. the third best, since no OS is really in the making, and no browser either.

^ permalink raw reply	[flat|nested] 18+ messages in thread

end of thread, other threads:[~2021-02-07 22:54 UTC | newest]

Thread overview: 18+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-02-05 22:50 questions on input/output Mehdi Saada
2021-02-05 23:36 ` Jeffrey R. Carter
2021-02-06  0:59   ` Mehdi Saada
2021-02-06  1:34     ` Mehdi Saada
2021-02-06  2:13       ` Paul Rubin
2021-02-06  7:21     ` J-P. Rosen
2021-02-06  9:36 ` Dmitry A. Kazakov
2021-02-06 10:38   ` AdaMagica
2021-02-06 11:37     ` Mehdi Saada
2021-02-06 11:51       ` Mehdi Saada
2021-02-06 18:10         ` Paul Rubin
2021-02-06 18:55           ` Mehdi Saada
2021-02-06 20:26             ` Paul Rubin
2021-02-07  8:52               ` Mehdi Saada
2021-02-07 20:38                 ` Paul Rubin
2021-02-07  9:55             ` Gautier write-only address
2021-02-07 22:54               ` Mehdi Saada
2021-02-06 11:47     ` Dmitry A. Kazakov

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox