Rocksolid Light

Welcome to RetroBBS

mail  files  register  newsreader  groups  login

Message-ID:  

Real Programmers don't eat quiche. They eat Twinkies and Szechwan food.


devel / comp.lang.ada / wait does not perform as expected

SubjectAuthor
* wait does not perform as expectedDaniel Gaudry
+* Re: wait does not perform as expectedNiklas Holsti
|`* Re: wait does not perform as expectedAdaMagica
| +- Re: wait does not perform as expectedAdaMagica
| +* Re: wait does not perform as expectedDaniel Gaudry
| |+- Re: wait does not perform as expectedAdaMagica
| |`- Re: wait does not perform as expectedNiklas Holsti
| `* Re: wait does not perform as expectedNiklas Holsti
|  +- Re: wait does not perform as expectedNiklas Holsti
|  `* Re: wait does not perform as expectedDmitry A. Kazakov
|   `* Re: wait does not perform as expectedNiklas Holsti
|    +* Re: wait does not perform as expectedDaniel Gaudry
|    |+- Re: wait does not perform as expectedNiklas Holsti
|    |`- Re: wait does not perform as expectedNiklas Holsti
|    `* Re: wait does not perform as expectedDmitry A. Kazakov
|     `* Re: wait does not perform as expectedAdaMagica
|      `- Re: wait does not perform as expectedNiklas Holsti
`- Re: wait does not perform as expectedJeffrey R.Carter

1
wait does not perform as expected

<ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9362&group=comp.lang.ada#9362

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a0c:f387:0:b0:572:1044:dafe with SMTP id i7-20020a0cf387000000b005721044dafemr362606qvk.55.1677083658370;
Wed, 22 Feb 2023 08:34:18 -0800 (PST)
X-Received: by 2002:a05:6870:2e0d:b0:16d:8e4a:fe38 with SMTP id
oi13-20020a0568702e0d00b0016d8e4afe38mr1117417oab.291.1677083658069; Wed, 22
Feb 2023 08:34:18 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Wed, 22 Feb 2023 08:34:17 -0800 (PST)
Injection-Info: google-groups.googlegroups.com; posting-host=2001:861:3006:e580:fb20:5e3c:f153:3003;
posting-account=I_eLtQoAAAA-qV4zTYNhsy2EmfPsGcSc
NNTP-Posting-Host: 2001:861:3006:e580:fb20:5e3c:f153:3003
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
Subject: wait does not perform as expected
From: gaudry.dg@gmail.com (Daniel Gaudry)
Injection-Date: Wed, 22 Feb 2023 16:34:18 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3128
 by: Daniel Gaudry - Wed, 22 Feb 2023 16:34 UTC

hi
the following code :

with Gnat.Os_Lib;
with Ada.Strings;
with Ada.Strings.Fixed;
with Ada.Strings.Maps;
with Ada.Strings.Maps.Constants;
with ada.text_io;
with Ada.Strings;

procedure Hit_Return_To_Continue(Header : in String := "HIT RETURN TO CONTINUE";
Mandatory : in Boolean := False;
Skip_After : in Duration := 0.0)
is

Char : Character := ' ';
Hit : Boolean := True;
Timer : Duration := 0.0;

begin

-- ANYTHING TO DO ?
if Mandatory
then
ada.text_io.Put(Header);

-- ANY WAITING PERIOD TO DISPLAY ?
if Skip_After > 0.0
then

-- KEEP THE USER'S ATTENTION
while Timer < Skip_After loop
Timer := 1.0 + @;
delay 1.0;
ada.text_io.Put(Natural(Skip_After - Timer)'Img);

--USER ENDS THE WAITING PERIOD BEFORE IT'S END ?

TIO.LOOK_AHEAD(ITEM => CHAR,
END_OF_LINE => HIT);

ada.text_io.GET_IMMEDIATE(ITEM => CHAR,
AVAILABLE => HIT);
IF HIT THEN
RETURN;
END IF;

end loop;

-- USER WAITED FOR THE WHOLE WAITING PERIOD
-- LET HIM READ THE ZERO ON THE SCREEN

delay 1.0;
return;
end if;

Atio.Get_Immediate(Item => Char,
Available => Hit);

Atio.New_Line(Spacing => 1);

end if;

end Hit_Return_To_Continue;

the following call:

Hit_Return_To_Continue(Header => "HIT RETURN TO CONTINUE",
Mandatory => true,
Skip_After => 5.0);

does not return if the user hits a key before the end of the countdown.

Can anybody help
Best regards

Re: wait does not perform as expected

<k5n243Fe43nU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9363&group=comp.lang.ada#9363

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Wed, 22 Feb 2023 19:36:03 +0200
Organization: Tidorum Ltd
Lines: 68
Message-ID: <k5n243Fe43nU1@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net Fslr1YHdmY+E91kMY9cW3wX/feawH6UzCicQCoDspTFRVX3dDJ
Cancel-Lock: sha1:FIghmg6YqxgiClZFQMZ9kfBMzhg=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
 by: Niklas Holsti - Wed, 22 Feb 2023 17:36 UTC

On 2023-02-22 18:34, Daniel Gaudry wrote:
> hi
> the following code :

(I include only the relevant parts:)

> while Timer < Skip_After loop
> Timer := 1.0 + @;
> delay 1.0;
> ada.text_io.Put(Natural(Skip_After - Timer)'Img);
>
> --USER ENDS THE WAITING PERIOD BEFORE IT'S END ?
>
>
> TIO.LOOK_AHEAD(ITEM => CHAR,
> END_OF_LINE => HIT); >
>
> ada.text_io.GET_IMMEDIATE(ITEM => CHAR,
> AVAILABLE => HIT);
> IF HIT THEN
> RETURN;
> END IF;
>
> end loop;

Why do you call both Look_Ahead and Get_Immediate, but throw away the
result of Look_Ahead?

The behaviour may depend on how you configure (via OS calls) the
behaviour of your terminal emulator (the "shell window"), but for me, on
Mac OS/X with the default configuration, it behaves as follows.

The first time Look_Ahead is called (first loop iteration) it waits for
the user to press Return (Enter) before it delivers the look-ahead
character to the program. It must do so because it must see if the next
input is an end-of-line (Return/Enter) or a character (assuming there is
no "unconsumed" input when the loop starts).

The program is therefore suspended in the first Look_Ahead call, and the
timer loop and remaining-time output are also suspended, until you at
least press Return/Enter.

If you do press Return/Enter, perhaps after pressing some other keys,
the waiting Look_Ahead call returns either the (first) character you
pressed before Return/Enter, or End_Of_Line (Hit is True). However, your
code then throws those results away, and instead calls Get_Immediate.

On my system, Get_Immediate does /not/ use the inputs collected (but not
"consumed") by Look_Ahead, but instead checks if there are _new_ input
keystrokes. If there are none, Get_Immediate returns "not Available"
(Hit is False) and so the loop continues.

When Look_Ahead is called again, in the further loop iterations, it sees
that there now is unconsumed input (from the first call of Look_Ahead)
so it returns immediately (with the same results as on the first call).
Therefore the loop now works are you intend: if the user presses any key
before the Skip_After time is exhausted, the subprogram returns when
Get_Immediate sees that keystroke.

To fix the problem, remove the Look_Ahead call from the loop.

(For goodness sake, also clean up your "with" clauses -- only
Ada.Text_IO is relevant for your code -- and remove the multiple renames
of Ada.Text_IO. You seem to have at least "Atio" and "TIO" as renames
for Ada.Text_IO. One would be plenty.)

Re: wait does not perform as expected

<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9369&group=comp.lang.ada#9369

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:15ed:b0:71f:b908:7b74 with SMTP id p13-20020a05620a15ed00b0071fb9087b74mr1771986qkm.0.1677162367751;
Thu, 23 Feb 2023 06:26:07 -0800 (PST)
X-Received: by 2002:a05:6870:cc89:b0:172:473d:25a with SMTP id
ot9-20020a056870cc8900b00172473d025amr1141751oab.151.1677162367440; Thu, 23
Feb 2023 06:26:07 -0800 (PST)
Path: i2pn2.org!i2pn.org!weretis.net!feeder6.news.weretis.net!news.misty.com!border-2.nntp.ord.giganews.com!nntp.giganews.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 23 Feb 2023 06:26:07 -0800 (PST)
In-Reply-To: <k5n243Fe43nU1@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=3.70.231.225; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.70.231.225
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com> <k5n243Fe43nU1@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
Subject: Re: wait does not perform as expected
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Thu, 23 Feb 2023 14:26:07 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
Lines: 38
 by: AdaMagica - Thu, 23 Feb 2023 14:26 UTC

Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
> On my system, Get_Immediate does /not/ use the inputs collected (but not
> "consumed") by Look_Ahead, but instead checks if there are _new_ input
> keystrokes. If there are none, Get_Immediate returns "not Available"
> (Hit is False) and so the loop continues.

Are you sure? With GNAT Community 2021 (20210519-103) targeting x86_64-w64-mingw32,

loop
Look_Ahead (Char, EoL); Put ("Look_Ahead: '" & Char & "', End_of_Line => " & EoL'Image); New_Line;
Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
end loop;

I get:

ab x<RETRUN>
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: 'a', Available => TRUE
Look_Ahead: 'b', End_of_Line => FALSE
Get_Immediate: 'b', Available => TRUE
Look_Ahead: ' ', End_of_Line => FALSE
Get_Immediate: ' ', Available => TRUE
Look_Ahead: 'x', End_of_Line => FALSE
Get_Immediate: 'x', Available => TRUE
Look_Ahead: '0', End_of_Line => TRUE
Get_Immediate: ' <- This is the EoL
', Available => TRUE

So Get_Immediate returns the next not yet consumed character. This is inline with A.10.7(12/3):
If a character, either control or graphic, is available from the specified File or the default input file, then the character is read; Available is True and Item contains the value of this character. If a character is not available, then Available is False and the value of Item is not specified.

Re: wait does not perform as expected

<04265775-fe9f-4166-b0eb-a292ab917099n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9370&group=comp.lang.ada#9370

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:620a:11ad:b0:73b:a6e7:f505 with SMTP id c13-20020a05620a11ad00b0073ba6e7f505mr1925962qkk.1.1677162728308;
Thu, 23 Feb 2023 06:32:08 -0800 (PST)
X-Received: by 2002:a05:6808:128f:b0:383:caec:c459 with SMTP id
a15-20020a056808128f00b00383caecc459mr273242oiw.5.1677162728004; Thu, 23 Feb
2023 06:32:08 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 23 Feb 2023 06:32:07 -0800 (PST)
In-Reply-To: <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=3.70.231.225; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.70.231.225
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net> <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <04265775-fe9f-4166-b0eb-a292ab917099n@googlegroups.com>
Subject: Re: wait does not perform as expected
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Thu, 23 Feb 2023 14:32:08 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 1739
 by: AdaMagica - Thu, 23 Feb 2023 14:32 UTC

Also A.10.7(23):
The Get_Immediate procedures should be implemented with unbuffered input. For a device such as a keyboard, input should be “available” if a key has already been typed, whereas for a disk file, input should always be available except at end of file. For a file associated with a keyboard-like device, any line-editing features of the underlying operating system should be disabled during the execution of Get_Immediate.

Re: wait does not perform as expected

<6eacc599-b9a9-4c89-9122-862825d23423n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9371&group=comp.lang.ada#9371

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:4118:0:b0:3bf:b828:ab0d with SMTP id q24-20020ac84118000000b003bfb828ab0dmr34181qtl.11.1677162814090;
Thu, 23 Feb 2023 06:33:34 -0800 (PST)
X-Received: by 2002:a05:6820:1389:b0:524:f77c:5443 with SMTP id
i9-20020a056820138900b00524f77c5443mr1035484oow.1.1677162813514; Thu, 23 Feb
2023 06:33:33 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 23 Feb 2023 06:33:33 -0800 (PST)
In-Reply-To: <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:861:3006:e580:fb20:5e3c:f153:3003;
posting-account=I_eLtQoAAAA-qV4zTYNhsy2EmfPsGcSc
NNTP-Posting-Host: 2001:861:3006:e580:fb20:5e3c:f153:3003
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net> <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <6eacc599-b9a9-4c89-9122-862825d23423n@googlegroups.com>
Subject: Re: wait does not perform as expected
From: gaudry.dg@gmail.com (Daniel Gaudry)
Injection-Date: Thu, 23 Feb 2023 14:33:34 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3360
 by: Daniel Gaudry - Thu, 23 Feb 2023 14:33 UTC

On Thursday, February 23, 2023 at 3:26:09 PM UTC+1, AdaMagica wrote:
> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
> > On my system, Get_Immediate does /not/ use the inputs collected (but not
> > "consumed") by Look_Ahead, but instead checks if there are _new_ input
> > keystrokes. If there are none, Get_Immediate returns "not Available"
> > (Hit is False) and so the loop continues.
> Are you sure? With GNAT Community 2021 (20210519-103) targeting x86_64-w64-mingw32,
>
> loop
> Look_Ahead (Char, EoL); Put ("Look_Ahead: '" & Char & "', End_of_Line => " & EoL'Image); New_Line;
> Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
> end loop;
>
> I get:
>
> ab x<RETRUN>
> Look_Ahead: 'a', End_of_Line => FALSE
> Get_Immediate: 'a', Available => TRUE
> Look_Ahead: 'b', End_of_Line => FALSE
> Get_Immediate: 'b', Available => TRUE
> Look_Ahead: ' ', End_of_Line => FALSE
> Get_Immediate: ' ', Available => TRUE
> Look_Ahead: 'x', End_of_Line => FALSE
> Get_Immediate: 'x', Available => TRUE
> Look_Ahead: '0', End_of_Line => TRUE
> Get_Immediate: ' <- This is the EoL
> ', Available => TRUE
>
> So Get_Immediate returns the next not yet consumed character. This is inline with A.10.7(12/3):
> If a character, either control or graphic, is available from the specified File or the default input file, then the character is read; Available is True and Item contains the value of this character. If a character is not available, then Available is False and the value of Item is not specified.

Hi,
Many thanks for your time and answers
My problem under ubuntu is that get_immediate pauses the program if no key is hit.
Therefore available is not set and this little routine cannot perform as I want.
Any idea on how i can write such a simple routine that works ??
Best regards

Re: wait does not perform as expected

<21dd6f45-8224-449e-af38-2c1dbcbc59bbn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9372&group=comp.lang.ada#9372

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:a05:622a:64b:b0:3b7:fda4:c86e with SMTP id a11-20020a05622a064b00b003b7fda4c86emr2677914qtb.3.1677163195763;
Thu, 23 Feb 2023 06:39:55 -0800 (PST)
X-Received: by 2002:a05:6870:2195:b0:16e:2bc7:7715 with SMTP id
l21-20020a056870219500b0016e2bc77715mr1430515oae.223.1677163195499; Thu, 23
Feb 2023 06:39:55 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer03.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 23 Feb 2023 06:39:55 -0800 (PST)
In-Reply-To: <6eacc599-b9a9-4c89-9122-862825d23423n@googlegroups.com>
Injection-Info: google-groups.googlegroups.com; posting-host=3.70.231.225; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.70.231.225
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net> <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<6eacc599-b9a9-4c89-9122-862825d23423n@googlegroups.com>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <21dd6f45-8224-449e-af38-2c1dbcbc59bbn@googlegroups.com>
Subject: Re: wait does not perform as expected
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Thu, 23 Feb 2023 14:39:55 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 1706
 by: AdaMagica - Thu, 23 Feb 2023 14:39 UTC

Daniel Gaudry schrieb am Donnerstag, 23. Februar 2023 um 15:33:35 UTC+1:
> My problem under ubuntu is that get_immediate pauses the program if no key is hit.
> Therefore available is not set and this little routine cannot perform as I want.

There are essentially two different Get_Immediate, one that waits until a key is hit A.10.7(9),
the other does not A.10.7(11), but has a Boolean Available out-parameter.

Re: wait does not perform as expected

<k5pladFqm4tU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9373&group=comp.lang.ada#9373

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 19:15:57 +0200
Organization: Tidorum Ltd
Lines: 25
Message-ID: <k5pladFqm4tU1@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<6eacc599-b9a9-4c89-9122-862825d23423n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net Y2Yph3wSxwrci8HZ9bsedw3cmWENrh5AqX3eHio+saI8wI/CQl
Cancel-Lock: sha1:QMvhFUKDWNOhu60L0d5oDFBvJlg=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <6eacc599-b9a9-4c89-9122-862825d23423n@googlegroups.com>
 by: Niklas Holsti - Thu, 23 Feb 2023 17:15 UTC

On 2023-02-23 16:33, Daniel Gaudry wrote:
> On Thursday, February 23, 2023 at 3:26:09 PM UTC+1, AdaMagica wrote:
>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:

[skip answers]

> Hi,
> Many thanks for your time and answers
> My problem under ubuntu is that get_immediate pauses the program if no key is hit.
> Therefore available is not set and this little routine cannot perform as I want.
> Any idea on how i can write such a simple routine that works ??

Did you try it /without/ the Look_Ahead, as I suggested?

If you did, please post your new code and explain:

- how you want it to work, and

- how it behaves when you try it, and

- why that is not what you want.

Re: wait does not perform as expected

<k5pmfiFqm4vU1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9374&group=comp.lang.ada#9374

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 19:35:46 +0200
Organization: Tidorum Ltd
Lines: 64
Message-ID: <k5pmfiFqm4vU1@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net znZGIsPHxzIl7hA+WTp94wyiz87UwwOpa8MNB/nKwNQpQiY/co
Cancel-Lock: sha1:u/lNqlSzE6LPOEUfRD/sruXgcRs=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
 by: Niklas Holsti - Thu, 23 Feb 2023 17:35 UTC

On 2023-02-23 16:26, AdaMagica wrote:
> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
>> On my system, Get_Immediate does /not/ use the inputs collected (but not
>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
>> keystrokes. If there are none, Get_Immediate returns "not Available"
>> (Hit is False) and so the loop continues.
>
> Are you sure?

That is what I observe.

> With GNAT Community 2021 (20210519-103) targeting x86_64-w64-mingw32,
>
> loop
> Look_Ahead (Char, EoL); Put ("Look_Ahead: '" & Char & "', End_of_Line => " & EoL'Image); New_Line;
> Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
> end loop;
>
> I get:
>
> ab x<RETRUN>
> Look_Ahead: 'a', End_of_Line => FALSE
> Get_Immediate: 'a', Available => TRUE
> Look_Ahead: 'b', End_of_Line => FALSE
> Get_Immediate: 'b', Available => TRUE
> Look_Ahead: ' ', End_of_Line => FALSE
> Get_Immediate: ' ', Available => TRUE
> Look_Ahead: 'x', End_of_Line => FALSE
> Get_Immediate: 'x', Available => TRUE
> Look_Ahead: '0', End_of_Line => TRUE
> Get_Immediate: ' <- This is the EoL
> ', Available => TRUE
>

On my system:

ab x<RETURN>
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Look_Ahead: 'a', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE

and so on for ever, with Look_Ahead never waiting for new input.

The behaviour on my system is certainly different from yours. I can see
that both behaviours could be useful, depending on the program's needs.
However, I was certainly surprised to see my system's behaviour, and a
priori I expected to get the behaviour you see.

My system is oldish:

GNAT Community 2019 (20190517-83)
macOS 10.14.6 Mojave

This difference appears when mixing Look_Ahead and Get_Immediate, which
seems to make no sense for the original question, and which I advised
the OP not to do. Using just Get_Immediate should give the OP what they
want.

Re: wait does not perform as expected

<k5pn8gFqm4tU2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9375&group=comp.lang.ada#9375

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 19:49:04 +0200
Organization: Tidorum Ltd
Lines: 86
Message-ID: <k5pn8gFqm4tU2@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net ufHwjmKctGLfo/gjpS/weAvg2hLDouHk73u2K0TbkolXcbJ/IM
Cancel-Lock: sha1:a4Vk9UnDu3sq+hbFVqHWIPO00E0=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <k5pmfiFqm4vU1@mid.individual.net>
 by: Niklas Holsti - Thu, 23 Feb 2023 17:49 UTC

On 2023-02-23 19:35, Niklas Holsti wrote:
> On 2023-02-23 16:26, AdaMagica wrote:
>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
>>> On my system, Get_Immediate does /not/ use the inputs collected (but not
>>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
>>> keystrokes. If there are none, Get_Immediate returns "not Available"
>>> (Hit is False) and so the loop continues.
>>
>> Are you sure?
>
>
> That is what I observe.
>
>
>> With GNAT Community 2021 (20210519-103) targeting x86_64-w64-mingw32,
>>
>>    loop
>>      Look_Ahead    (Char, EoL);  Put ("Look_Ahead:    '" & Char & "',
>> End_of_Line => " & EoL'Image);  New_Line;
>>      Get_Immediate (Char, Avl);  Put ("Get_Immediate: '" & Char & "',
>> Available   => " & Avl'Image);  New_Line;
>>    end loop;
>>
>> I get:
>>
>> ab x<RETRUN>
>> Look_Ahead:    'a', End_of_Line => FALSE
>> Get_Immediate: 'a', Available   => TRUE
>> Look_Ahead:    'b', End_of_Line => FALSE
>> Get_Immediate: 'b', Available   => TRUE
>> Look_Ahead:    ' ', End_of_Line => FALSE
>> Get_Immediate: ' ', Available   => TRUE
>> Look_Ahead:    'x', End_of_Line => FALSE
>> Get_Immediate: 'x', Available   => TRUE
>> Look_Ahead:    '0', End_of_Line => TRUE
>> Get_Immediate: '                                          <- This is
>> the EoL
>> ', Available   => TRUE
>>
>
>
> On my system:
>
> ab x<RETURN>
> Look_Ahead:    'a', End_of_Line => FALSE
> Get_Immediate: '', Available   => FALSE
> Look_Ahead:    'a', End_of_Line => FALSE
> Get_Immediate: '', Available   => FALSE
> Look_Ahead:    'a', End_of_Line => FALSE
> Get_Immediate: '', Available   => FALSE
>
> and so on for ever, with Look_Ahead never waiting for new input.
>
> The behaviour on my system is certainly different from yours. I can see
> that both behaviours could be useful, depending on the program's needs.
> However, I was certainly surprised to see my system's behaviour, and a
> priori I expected to get the behaviour you see.
>
> My system is oldish:
>
> GNAT Community 2019 (20190517-83)
> macOS 10.14.6 Mojave
>
> This difference appears when mixing Look_Ahead and Get_Immediate,

Or (on my system) when mixing ordinary Get and Get_Immediate. If I
replace the Look_Ahead call with just a test for End_Of_Line and then
Get (Char), I get a similar effect, showing that on my system
Get_Immediate ignores any previously buffered, unconsumed input line,
whether it results from Look_Ahead or from Get:

ab x
Get : 'a', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Get : 'b', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Get : ' ', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Get : 'x', End_of_Line => FALSE
Get_Immediate: '', Available => FALSE
Get : '', End_of_Line => TRUE
Get_Immediate: '', Available => FALSE

and then the Get call waits for new input (a new input line).

Re: wait does not perform as expected

<tt8aec$1u7lt$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9376&group=comp.lang.ada#9376

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 19:14:38 +0100
Organization: A noiseless patient Spider
Lines: 29
Message-ID: <tt8aec$1u7lt$1@dont-email.me>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Feb 2023 18:14:36 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="5e09243eb177348401e741ec3b255505";
logging-data="2039485"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18w2z2PJTGPK5G+l5w2YGgrp0qudAraDSg="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:DNej4CQ24YWu6gw3Hdj6szc0EIQ=
In-Reply-To: <k5pmfiFqm4vU1@mid.individual.net>
Content-Language: en-US
 by: Dmitry A. Kazakov - Thu, 23 Feb 2023 18:14 UTC

On 2023-02-23 18:35, Niklas Holsti wrote:
> On 2023-02-23 16:26, AdaMagica wrote:
>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
>>> On my system, Get_Immediate does /not/ use the inputs collected (but not
>>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
>>> keystrokes. If there are none, Get_Immediate returns "not Available"
>>> (Hit is False) and so the loop continues.
>>
>> Are you sure?
>
> That is what I observe.

The implementation of Look_Ahead calls getc followed by ungetc. Thus it
blocks until an input if there is no buffered. And not just input, but
for a line or file end.

As for ungetc POSIX layer under Windows, ungetc probably does not work
correctly, I am too lazy to verify. One possibility is that file
positioning (fseek etc) kill unget buffer.

In any case, subprograms like Look_Ahead, End_Of_File etc exit strictly
for decoration, not for any practical reason. As a rule of thumb no
program should ever use them.

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

Re: wait does not perform as expected

<k5ppkcFqm4tU3@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9377&group=comp.lang.ada#9377

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 20:29:32 +0200
Organization: Tidorum Ltd
Lines: 33
Message-ID: <k5ppkcFqm4tU3@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net> <tt8aec$1u7lt$1@dont-email.me>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net YlOxiylQ+fE7qT2KVbHLEwWUftEdxo0EaG6WKF3rvof0HxuE7+
Cancel-Lock: sha1:ghyDZrw4mO1SgCnWP0Xx0ZVB9oE=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <tt8aec$1u7lt$1@dont-email.me>
 by: Niklas Holsti - Thu, 23 Feb 2023 18:29 UTC

On 2023-02-23 20:14, Dmitry A. Kazakov wrote:
> On 2023-02-23 18:35, Niklas Holsti wrote:
>> On 2023-02-23 16:26, AdaMagica wrote:
>>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
>>>> On my system, Get_Immediate does /not/ use the inputs collected (but
>>>> not
>>>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
>>>> keystrokes. If there are none, Get_Immediate returns "not Available"
>>>> (Hit is False) and so the loop continues.
>>>
>>> Are you sure?
>>
>> That is what I observe.
>
> The implementation of Look_Ahead calls getc followed by ungetc. Thus it
> blocks until an input if there is no buffered. And not just input, but
> for a line or file end.

That seems in order.

However, the crux of the question is in Get_Immediate. Do you know how
that is implemented on various systems? It has to disable line buffering
and line editing on the input stream. One question is whether and how
such "tty" configuration changes affect whatever buffers getc/ungetc use.

On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
does not use the same buffers, and has no effect on those buffers. That
could be desirable behaviour in some cases, undesirable in others.

On AdaMagica's system, it seems that Get_Immediate uses the same buffers
as Look_Ahead (getc/ungetc).

Re: wait does not perform as expected

<72723295-3b36-412f-a5fc-f1dd2f5a56edn@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9378&group=comp.lang.ada#9378

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ad4:558e:0:b0:56e:97e6:81e4 with SMTP id f14-20020ad4558e000000b0056e97e681e4mr1998852qvx.4.1677178078581;
Thu, 23 Feb 2023 10:47:58 -0800 (PST)
X-Received: by 2002:a05:6808:f05:b0:37f:83ba:ee74 with SMTP id
m5-20020a0568080f0500b0037f83baee74mr424580oiw.1.1677178078279; Thu, 23 Feb
2023 10:47:58 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer01.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Thu, 23 Feb 2023 10:47:57 -0800 (PST)
In-Reply-To: <k5ppkcFqm4tU3@mid.individual.net>
Injection-Info: google-groups.googlegroups.com; posting-host=2001:861:3006:e580:fb20:5e3c:f153:3003;
posting-account=I_eLtQoAAAA-qV4zTYNhsy2EmfPsGcSc
NNTP-Posting-Host: 2001:861:3006:e580:fb20:5e3c:f153:3003
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net> <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net> <tt8aec$1u7lt$1@dont-email.me> <k5ppkcFqm4tU3@mid.individual.net>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <72723295-3b36-412f-a5fc-f1dd2f5a56edn@googlegroups.com>
Subject: Re: wait does not perform as expected
From: gaudry.dg@gmail.com (Daniel Gaudry)
Injection-Date: Thu, 23 Feb 2023 18:47:58 +0000
Content-Type: text/plain; charset="UTF-8"
Content-Transfer-Encoding: quoted-printable
X-Received-Bytes: 3321
 by: Daniel Gaudry - Thu, 23 Feb 2023 18:47 UTC

On Thursday, February 23, 2023 at 7:29:36 PM UTC+1, Niklas Holsti wrote:
> On 2023-02-23 20:14, Dmitry A. Kazakov wrote:
> > On 2023-02-23 18:35, Niklas Holsti wrote:
> >> On 2023-02-23 16:26, AdaMagica wrote:
> >>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
> >>>> On my system, Get_Immediate does /not/ use the inputs collected (but
> >>>> not
> >>>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
> >>>> keystrokes. If there are none, Get_Immediate returns "not Available"
> >>>> (Hit is False) and so the loop continues.
> >>>
> >>> Are you sure?
> >>
> >> That is what I observe.
> >
> > The implementation of Look_Ahead calls getc followed by ungetc. Thus it
> > blocks until an input if there is no buffered. And not just input, but
> > for a line or file end.
> That seems in order.
>
> However, the crux of the question is in Get_Immediate. Do you know how
> that is implemented on various systems? It has to disable line buffering
> and line editing on the input stream. One question is whether and how
> such "tty" configuration changes affect whatever buffers getc/ungetc use.
>
> On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
> does not use the same buffers, and has no effect on those buffers. That
> could be desirable behaviour in some cases, undesirable in others.
>
> On AdaMagica's system, it seems that Get_Immediate uses the same buffers
> as Look_Ahead (getc/ungetc).

Hi,
On my ubuntu system the
ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
just pause the program regardless of any key being hit.
I just cannot use a wait (several shorts one in a row) interrupted by a key hit.
Any possibility you may know of ??
My Best Regards

Re: wait does not perform as expected

<k5pru4Fqm4vU2@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9379&group=comp.lang.ada#9379

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 21:08:52 +0200
Organization: Tidorum Ltd
Lines: 49
Message-ID: <k5pru4Fqm4vU2@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net> <tt8aec$1u7lt$1@dont-email.me>
<k5ppkcFqm4tU3@mid.individual.net>
<72723295-3b36-412f-a5fc-f1dd2f5a56edn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 8bit
X-Trace: individual.net DqD2JlGM0bvJhsUWJVd2JQv69Vjdv6lxEVZWkjmBNpnUXuI/1/
Cancel-Lock: sha1:vmNYpiCoY3niBh2DT6w8rbwPY3Q=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <72723295-3b36-412f-a5fc-f1dd2f5a56edn@googlegroups.com>
 by: Niklas Holsti - Thu, 23 Feb 2023 19:08 UTC

On 2023-02-23 20:47, Daniel Gaudry wrote:
> On Thursday, February 23, 2023 at 7:29:36 PM UTC+1, Niklas Holsti wrote:
>> On 2023-02-23 20:14, Dmitry A. Kazakov wrote:
>>> On 2023-02-23 18:35, Niklas Holsti wrote:
>>>> On 2023-02-23 16:26, AdaMagica wrote:
>>>>> Niklas Holsti schrieb am Mittwoch, 22. Februar 2023 um 18:36:06 UTC+1:
>>>>>> On my system, Get_Immediate does /not/ use the inputs collected (but
>>>>>> not
>>>>>> "consumed") by Look_Ahead, but instead checks if there are _new_ input
>>>>>> keystrokes. If there are none, Get_Immediate returns "not Available"
>>>>>> (Hit is False) and so the loop continues.
>>>>>
>>>>> Are you sure?
>>>>
>>>> That is what I observe.
>>>
>>> The implementation of Look_Ahead calls getc followed by ungetc. Thus it
>>> blocks until an input if there is no buffered. And not just input, but
>>> for a line or file end.
>> That seems in order.
>>
>> However, the crux of the question is in Get_Immediate. Do you know how
>> that is implemented on various systems? It has to disable line buffering
>> and line editing on the input stream. One question is whether and how
>> such "tty" configuration changes affect whatever buffers getc/ungetc use.
>>
>> On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
>> does not use the same buffers, and has no effect on those buffers. That
>> could be desirable behaviour in some cases, undesirable in others.
>>
>> On AdaMagica's system, it seems that Get_Immediate uses the same buffers
>> as Look_Ahead (getc/ungetc).
>
>
> Hi,
> On my ubuntu system the
> ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
> just pause the program regardless of any key being hit.
> I just cannot use a wait (several shorts one in a row) interrupted by a key hit.
> Any possibility you may know of ??

Please show the Ada code you have now. I assume there is no Look_Ahead
there, right?

Best if you can write, test and post a short, stand-alone program that
just contains the wait-for-keystroke procedure, then we can be sure that
there is nothing else in the program that might interfere.

Re: wait does not perform as expected

<k5pt98Fqm4tU4@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9380&group=comp.lang.ada#9380

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 21:31:52 +0200
Organization: Tidorum Ltd
Lines: 32
Message-ID: <k5pt98Fqm4tU4@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net> <tt8aec$1u7lt$1@dont-email.me>
<k5ppkcFqm4tU3@mid.individual.net>
<72723295-3b36-412f-a5fc-f1dd2f5a56edn@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net E23soGxdzkzghZNmtXvtYwyvVyUSWPbXqf2TF7EDczvv7xHu1G
Cancel-Lock: sha1:/McHiXALuFl1wmsz+6LpZaDfoJA=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <72723295-3b36-412f-a5fc-f1dd2f5a56edn@googlegroups.com>
 by: Niklas Holsti - Thu, 23 Feb 2023 19:31 UTC

On 2023-02-23 20:47, Daniel Gaudry wrote:

> Hi,
> On my ubuntu system the
> ada.text_io.GET_IMMEDIATE(ITEM => CHAR, AVAILABLE => HIT);
> just pause the program regardless of any key being hit.

Hmm... it occurred to me to try to execute the program under GPS, not in
a shell window.

If I run a Get_Immediate loop under GPS, within the input-output window
of GPS, there is /no reaction/ to keystrokes until I press Return/Enter.
Get_Immediate returns Available => False until Return/Enter is pressed,
after which it returns the characters typed before Return/Enter, one by
one in order.

So it seems that, on my system, Get_Immediate cannot disable the
line-buffering of the standard-input "terminal", but must wait for
Return/Enter until it sees any input. And line-editing too is still
active under Get_Immediate, when running within GPS.

I am starting to suspect that the behaviour I see in my shell command
window may be due partly to the terminal emulator that implements such
windows on my system (MacOS "Terminal" app).

Daniel, how are you compiling and running your code? Under GPS, in a
shell window, or in some other way (shell script)?

If you have been running within GPS, try to run your program in a normal
shell command window.

Re: wait does not perform as expected

<tt8j18$1u7lt$2@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9382&group=comp.lang.ada#9382

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: mailbox@dmitry-kazakov.de (Dmitry A. Kazakov)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Thu, 23 Feb 2023 21:41:14 +0100
Organization: A noiseless patient Spider
Lines: 17
Message-ID: <tt8j18$1u7lt$2@dont-email.me>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net> <tt8aec$1u7lt$1@dont-email.me>
<k5ppkcFqm4tU3@mid.individual.net>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Thu, 23 Feb 2023 20:41:12 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="5e09243eb177348401e741ec3b255505";
logging-data="2039485"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX18A8HVXglxQ7wtuza7HUjtK+brOQnRY66g="
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101
Thunderbird/102.8.0
Cancel-Lock: sha1:jc7dCf7RwPKJXUhB0es7o5IEugU=
Content-Language: en-US
In-Reply-To: <k5ppkcFqm4tU3@mid.individual.net>
 by: Dmitry A. Kazakov - Thu, 23 Feb 2023 20:41 UTC

On 2023-02-23 19:29, Niklas Holsti wrote:

> However, the crux of the question is in Get_Immediate. Do you know how
> that is implemented on various systems?

No, but it is clear that Get_Immediate might be unimplementable in the
sense that there may be no way to make it work with all sorts of weird
files, e.g. under GPS console.

It is to expect it to work with the "standard" terminal [emulator].
Anything else is a long shot.

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

Re: wait does not perform as expected

<79efa06f-180f-4b94-ae83-c0b818248340n@googlegroups.com>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9386&group=comp.lang.ada#9386

  copy link   Newsgroups: comp.lang.ada
X-Received: by 2002:ac8:7046:0:b0:3bf:b62a:37f9 with SMTP id y6-20020ac87046000000b003bfb62a37f9mr1228902qtm.11.1677251413681;
Fri, 24 Feb 2023 07:10:13 -0800 (PST)
X-Received: by 2002:a05:6830:2468:b0:690:ef0d:d946 with SMTP id
x40-20020a056830246800b00690ef0dd946mr1681347otr.3.1677251413302; Fri, 24 Feb
2023 07:10:13 -0800 (PST)
Path: i2pn2.org!i2pn.org!usenet.blueworldhosting.com!feed1.usenet.blueworldhosting.com!peer02.iad!feed-me.highwinds-media.com!news.highwinds-media.com!news-out.google.com!nntp.google.com!postnews.google.com!google-groups.googlegroups.com!not-for-mail
Newsgroups: comp.lang.ada
Date: Fri, 24 Feb 2023 07:10:13 -0800 (PST)
In-Reply-To: <tt8j18$1u7lt$2@dont-email.me>
Injection-Info: google-groups.googlegroups.com; posting-host=3.68.230.196; posting-account=rmHyLAoAAADSQmMWJF0a_815Fdd96RDf
NNTP-Posting-Host: 3.68.230.196
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net> <75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net> <tt8aec$1u7lt$1@dont-email.me>
<k5ppkcFqm4tU3@mid.individual.net> <tt8j18$1u7lt$2@dont-email.me>
User-Agent: G2/1.0
MIME-Version: 1.0
Message-ID: <79efa06f-180f-4b94-ae83-c0b818248340n@googlegroups.com>
Subject: Re: wait does not perform as expected
From: christ-usch.grein@t-online.de (AdaMagica)
Injection-Date: Fri, 24 Feb 2023 15:10:13 +0000
Content-Type: text/plain; charset="UTF-8"
X-Received-Bytes: 3526
 by: AdaMagica - Fri, 24 Feb 2023 15:10 UTC

Dmitry A. Kazakov schrieb am Donnerstag, 23. Februar 2023 um 21:41:16 UTC+1:
> It is to expect it to work with the "standard" terminal [emulator].
> Anything else is a long shot.

Right, there may be weird file kinds where Get_Immediate fails.

Niklas Holsti schrieb am Donnerstag, 23. Februar 2023 um 19:29:36 UTC+1:
> On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
> does not use the same buffers, and has no effect on those buffers. That
> could be desirable behaviour in some cases, undesirable in others.
>
> On AdaMagica's system, it seems that Get_Immediate uses the same buffers
> as Look_Ahead (getc/ungetc).

I further experimented.

loop
Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
delay 1.0;
end loop;

Run in GPS, it behaves strangely (seems to be one of Dmitry's weird files)

ab c<return>
Get_Immediate: 'a', Available => TRUE
Get_Immediate: 'b', Available => TRUE
Get_Immediate: ' ', Available => TRUE
Get_Immediate: 'c', Available => TRUE
Get_Immediate: '
', Available => TRUE long pause until:
<return>
Get_Immediate: '
', Available => TRUE

It only reacts after <return> is pressed.

On a terminal window, the same executable reacts as I expect (this is why the delay statement is there).

Get_Immediate: ' ', Available => FALSE
Get_Immediate: ' ', Available => FALSE
Get_Immediate: ' ', Available => FALSE as long as no <return> is pressed
a note: no <return>
Get_Immediate: 'a', Available => TRUE
Get_Immediate: ' ', Available => FALSE and so on.

So bevore discussing how Get_Immediate is implemented on different hardware or different implementations, please read the RM paras I referenced and discuss them. Looks to me like the behaviour shown last is the correct one (let aside weird terminals).

Niklas, your GNAT is two years older than mine. I guess GNAT has been corrected (at least changed) in between.

If we all disagree how it should work, we should post this on Ada Comment.

Re: wait does not perform as expected

<k5sdllF4rr9U1@mid.individual.net>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9387&group=comp.lang.ada#9387

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail
From: niklas.holsti@tidorum.invalid (Niklas Holsti)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Fri, 24 Feb 2023 20:23:49 +0200
Organization: Tidorum Ltd
Lines: 105
Message-ID: <k5sdllF4rr9U1@mid.individual.net>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
<k5n243Fe43nU1@mid.individual.net>
<75c3990e-eaab-47eb-bdba-3827b9fd4751n@googlegroups.com>
<k5pmfiFqm4vU1@mid.individual.net> <tt8aec$1u7lt$1@dont-email.me>
<k5ppkcFqm4tU3@mid.individual.net> <tt8j18$1u7lt$2@dont-email.me>
<79efa06f-180f-4b94-ae83-c0b818248340n@googlegroups.com>
Mime-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: individual.net 4tVu4tAbTzRrHjJHJ9Q8XAuuGYd7Dp4oBbfZ7WyTCTjMP2DJS8
Cancel-Lock: sha1:7JIrMRRWGKIiKQaMsRE+k4qG/s4=
User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:102.0)
Gecko/20100101 Thunderbird/102.6.1
Content-Language: en-US
In-Reply-To: <79efa06f-180f-4b94-ae83-c0b818248340n@googlegroups.com>
 by: Niklas Holsti - Fri, 24 Feb 2023 18:23 UTC

On 2023-02-24 17:10, AdaMagica wrote:
> Dmitry A. Kazakov schrieb am Donnerstag, 23. Februar 2023 um 21:41:16 UTC+1:
>> It is to expect it to work with the "standard" terminal [emulator].
>> Anything else is a long shot.
>
> Right, there may be weird file kinds where Get_Immediate fails.

I would expect Get_Immediate to work on any kind of "file" for which
isatty() returns 1, meanng "it is a tty".

Interestingly, this is the case for the execution input/output window
under my GPS: isatty() returns 1, and ttyname() is
"/dev/tty<something>", but still Get_Immediate requires a <return>
keystroke before it sees anything as Available.

It seems to me that the natural implementation (on Unix-like systems) of
Get_Immediate is for it to use isatty() to check if the input file is a
"tty", and if so to call ioctl() to disable line buffering so that every
keystroke is delivered immediately. Why that does not work under GPS
(mine and yours) is not clear to me.

> Niklas Holsti schrieb am Donnerstag, 23. Februar 2023 um 19:29:36 UTC+1:
>> On my system, if Look_Ahead uses getc and ungetc, it seems Get_Immediate
>> does not use the same buffers, and has no effect on those buffers. That
>> could be desirable behaviour in some cases, undesirable in others.
>>
>> On AdaMagica's system, it seems that Get_Immediate uses the same buffers
>> as Look_Ahead (getc/ungetc).
>
> I further experimented.
>
> loop
> Get_Immediate (Char, Avl); Put ("Get_Immediate: '" & Char & "', Available => " & Avl'Image); New_Line;
> delay 1.0;
> end loop;
>
> Run in GPS, it behaves strangely (seems to be one of Dmitry's weird files)
>
> ab c<return>
> Get_Immediate: 'a', Available => TRUE
> Get_Immediate: 'b', Available => TRUE
> Get_Immediate: ' ', Available => TRUE
> Get_Immediate: 'c', Available => TRUE
> Get_Immediate: '
> ', Available => TRUE long pause until:
> <return>
> Get_Immediate: '
> ', Available => TRUE
>
> It only reacts after <return> is pressed.

Under my GPS, it returns Available => False until <return> is pressed,
and then it returns the characters typed before the <return>, as for
you. An interesting difference, and somehow it seems to me consistent
with the difference between our systems in the interaction of
Get_Immediate and Look_Ahead.

> On a terminal window, the same executable reacts as I expect
> (this is why the delay statement is there).
>
> Get_Immediate: ' ', Available => FALSE
> Get_Immediate: ' ', Available => FALSE
> Get_Immediate: ' ', Available => FALSE as long as no <return> is pressed
> a note: no <return>
> Get_Immediate: 'a', Available => TRUE
> Get_Immediate: ' ', Available => FALSE and so on.

I see the same behaviour in my terminal window, and this is the
behaviour I would expect (for Get_Immediate alone, without any
Look_Ahead calls). It seems that this is also what the OP wants and
should get, if the OP calls only Get_Immediate and runs in a terminal
window (and not under GPS).

> Looks to me like the behaviour shown last is the correct one (let
> aside weird terminals).

I agree.

> Niklas, your GNAT is two years older than mine. I guess GNAT has been
> corrected (at least changed) in between.

Quite possible. But the behaviour differences (assuming a terminal
window) concern only the interaction between normal input (including
Look_Ahead) and Get_Immediate, which I think is very rarely important.
However, the behaviour you see, where Get_Immediate inspects the normal,
as-yet unconsumed input stream, is more in-line with the Ada RM text.

> If we all disagree how it should work, we should post this on Ada
> Comment.

I don't think we disagree: Get_Immediate should return each keystroke
ASAP, without waiting for a <return>. And the RM text is good, IMO.

However, an enhancement request / minor bug report to AdaCore re the
<return> dependency of Get_Immediate under GPS could be in order.

Re: wait does not perform as expected

<ttb9g0$2a2c1$1@dont-email.me>

  copy mid

https://www.rocksolidbbs.com/devel/article-flat.php?id=9389&group=comp.lang.ada#9389

  copy link   Newsgroups: comp.lang.ada
Path: i2pn2.org!i2pn.org!eternal-september.org!reader01.eternal-september.org!.POSTED!not-for-mail
From: spam.jrcarter.not@spam.acm.org.not (Jeffrey R.Carter)
Newsgroups: comp.lang.ada
Subject: Re: wait does not perform as expected
Date: Fri, 24 Feb 2023 22:16:48 +0100
Organization: A noiseless patient Spider
Lines: 94
Message-ID: <ttb9g0$2a2c1$1@dont-email.me>
References: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8; format=flowed
Content-Transfer-Encoding: 7bit
Injection-Date: Fri, 24 Feb 2023 21:16:48 -0000 (UTC)
Injection-Info: reader01.eternal-september.org; posting-host="2652e59ce035a88971ee0ef0561ab440";
logging-data="2427265"; mail-complaints-to="abuse@eternal-september.org"; posting-account="U2FsdGVkX1/l2s8050m4kMI+CmrHQCtlQ5vqoru+4x4="
User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101
Thunderbird/102.7.1
Cancel-Lock: sha1:49fXgkPi8SsoW2hDtYUu5IVCpnI=
In-Reply-To: <ac87b5c5-7c01-4af9-b9bf-8c3ffc3fe74dn@googlegroups.com>
Content-Language: en-US
 by: Jeffrey R.Carter - Fri, 24 Feb 2023 21:16 UTC

On 2023-02-22 17:34, Daniel Gaudry wrote:
> the following code :

Atio and Tio are undefined. Clearly this code is not what you are running.

The important bit:

> if Skip_After > 0.0
> then
>
> -- KEEP THE USER'S ATTENTION
> while Timer < Skip_After loop
> Timer := 1.0 + @;
> delay 1.0;
> ada.text_io.Put(Natural(Skip_After - Timer)'Img);
>
> --USER ENDS THE WAITING PERIOD BEFORE IT'S END ?
>
>
> TIO.LOOK_AHEAD(ITEM => CHAR,
> END_OF_LINE => HIT);
>
> ada.text_io.GET_IMMEDIATE(ITEM => CHAR,
> AVAILABLE => HIT);
> IF HIT THEN
> RETURN;
> END IF;
>
> end loop;
>
> -- USER WAITED FOR THE WHOLE WAITING PERIOD
> -- LET HIM READ THE ZERO ON THE SCREEN
>
> delay 1.0;
> return;
> end if;

Let's simplify this. Without the countdown, this can be rewritten using ATC

Timed_Out : Boolean := False;
....
select
delay Skip_After;

Timed_Out := True;
then abort
Ada.Text_IO.Get_Immediate (Item => Char);
end select;

if Timed_Out then
delay 1.0;
end if;

return;

This should be simple enough to get right. If ATC doesn't work well with this,
it should still be simple enough to get right without it.

To add the countdown, let's split that out into a task:

declare
task Timer is
entry Stop;
end Timer;

task body Timer is ...
-- Does the countdown immediately (uses the global constant Skip_After)
-- Stops the countdown if Stop is called
begin
select
delay Skip_After;

Timed_Out := True;
then abort
Ada.Text_IO.Get_Immediate (Item => Char);
Timer.Stop;
end select;
end;

if Timed_Out then
delay 1.0;
end if;

return;

The task should be simple enough to get right, too.

--
Jeff Carter
"Saving keystrokes is the job of the text editor,
not the programming language."
Preben Randhol
64


devel / comp.lang.ada / wait does not perform as expected

1
server_pubkey.txt

rocksolid light 0.9.81
clearnet tor