From mboxrd@z Thu Jan 1 00:00:00 1970 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on polar.synack.me X-Spam-Level: X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00 autolearn=unavailable autolearn_force=no version=3.4.4 Path: eternal-september.org!reader01.eternal-september.org!reader02.eternal-september.org!news.eternal-september.org!news.eternal-september.org!feeder.eternal-september.org!news.swapon.de!fu-berlin.de!uni-berlin.de!individual.net!not-for-mail From: Niklas Holsti Newsgroups: comp.lang.ada Subject: Re: Select + Accept syntax question Date: Sun, 28 Aug 2016 09:52:53 +0300 Organization: Tidorum Ltd Message-ID: References: <60637c3a-c699-4e4c-9fd3-1a081cb6152c@googlegroups.com> <79a47c37-90e6-440f-8b40-cdb525758d8b@googlegroups.com> Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 7bit X-Trace: individual.net jfUhkD7eK/TjOX/3OCoPRgYvNqZHgmLGv83OP1o6+rJYM1L/+f Cancel-Lock: sha1:ycUe3T3A4yD4urGLH6P8lUgBsRU= User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:45.0) Gecko/20100101 Thunderbird/45.2.0 In-Reply-To: <79a47c37-90e6-440f-8b40-cdb525758d8b@googlegroups.com> Xref: news.eternal-september.org comp.lang.ada:31622 Date: 2016-08-28T09:52:53+03:00 List-Id: On 16-08-27 22:47 , Andrew Shvets wrote: > On Saturday, August 27, 2016 at 3:20:16 PM UTC-4, Niklas Holsti wrote: >> On 16-08-27 21:26 , Andrew Shvets wrote: >> >>> The one thing that threw me for a loop was when I put any type of code right before the above two accept keywords, like so: >>> while Go_Loop LOOP >>> select >>> when Internal_Value = 0 => >>> Ada.Text_IO.Put_Line("hello world"); >>> accept Input(Value : in Integer) do >>> Internal_Value := Value; >>> end Input; >>> or >>> when Internal_Value /= 0 => >>> Ada.Text_IO.Put_Line("hello world"); >>> accept Retrieve(Value : out Integer) do >>> Value := Internal_Value; >>> end Retrieve; >>> >>> And I get the following output from the compiler: >>> >>>> gnatmake -g .\task_demo_11.adb >>> gcc -c -I.\ -g -I- .\task_demo_11.adb >>> task_demo_11.adb:25:16: missing "END SELECT;" for "SELECT" at line 18 >>> task_demo_11.adb:25:17: select alternative ("ACCEPT", "ABORT", "DELAY") expected >>> task_demo_11.adb:38:07: "OR" not allowed here >>> task_demo_11.adb:42:07: no "SELECT" for this "END SELECT" >>> gnatmake: ".\task_demo_11.adb" compilation error >>> >>> Why does this happen? Why can't I have code right before the accept? >> >> Before I try to answer that question, I would like to know what >> behaviour you expect from such code. In particular, exactly when would >> that code be executed? >> >> -- >> Niklas Holsti >> Tidorum Ltd >> niklas holsti tidorum fi >> . @ . > > To print something out and then wait for a message to arrive. So the statement between the guard and the "accept" would be executed before the rendez-vous at the "accept"? And if several "or" alternatives are open (with True guards), all of their statements in this position would be executed before it is known which "accept" is selected for execution? That would be against the intent of the "select"-"or" construct, where the point is to select and execute _one_ of the alternatives. And that is why the syntax insists that the conditions for choosing a particular alternative (the guard and the "accept" or other select-alternative) must appear together, with no statements in between. -- Niklas Holsti Tidorum Ltd niklas holsti tidorum fi . @ .