comp.lang.ada
 help / color / mirror / Atom feed
* alternative elsif branch not tested
@ 2018-02-22 22:54 Mehdi Saada
  2018-02-22 23:09 ` Mehdi Saada
  0 siblings, 1 reply; 11+ messages in thread
From: Mehdi Saada @ 2018-02-22 22:54 UTC (permalink / raw)


This piece shall verify the program's arguments. I don't understand why whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.
Except that, everything worked just fine. Almost at the first attempt !

      if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre d'arguments."); raise Exc_Commande;
      elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' | 'C' then
	 PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) charactère entre n, c, N et C."); raise Exc_Commande;
      elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, Outside) /= 0 then
	 PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de chiffres !"); raise Exc_Commande;
      end if;


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

* Re: alternative elsif branch not tested
  2018-02-22 22:54 alternative elsif branch not tested Mehdi Saada
@ 2018-02-22 23:09 ` Mehdi Saada
  2018-02-22 23:29   ` Anh Vo
                     ` (2 more replies)
  0 siblings, 3 replies; 11+ messages in thread
From: Mehdi Saada @ 2018-02-22 23:09 UTC (permalink / raw)


This piece shall verify the program's arguments. I don't understand why whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.
 
      if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre d'arguments."); raise Exc_Commande;
      elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' | 'C' then
        PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) charactère entre n, c, N et C."); raise Exc_Commande;
      elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, Outside) /= 0 then
 	PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de chiffres !"); raise Exc_Commande;
      end if;

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

* Re: alternative elsif branch not tested
  2018-02-22 23:09 ` Mehdi Saada
@ 2018-02-22 23:29   ` Anh Vo
  2018-02-22 23:54   ` Randy Brukardt
  2018-02-23 19:39   ` Mehdi Saada
  2 siblings, 0 replies; 11+ messages in thread
From: Anh Vo @ 2018-02-22 23:29 UTC (permalink / raw)


On Thursday, February 22, 2018 at 3:09:17 PM UTC-8, Mehdi Saada wrote:
> This piece shall verify the program's arguments. I don't understand why whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
> It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.
>  
>       if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre d'arguments."); raise Exc_Commande;
>       elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' | 'C' then
>         PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) charactère entre n, c, N et C."); raise Exc_Commande;
>       elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, Outside) /= 0 then
>  	PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de chiffres !"); raise Exc_Commande;
>       end if;

It falls outside of your if check. That means it must be in the else part.

Anh Vo


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

* Re: alternative elsif branch not tested
  2018-02-22 23:09 ` Mehdi Saada
  2018-02-22 23:29   ` Anh Vo
@ 2018-02-22 23:54   ` Randy Brukardt
  2018-02-23 10:51     ` Mehdi Saada
  2018-02-23 19:39   ` Mehdi Saada
  2 siblings, 1 reply; 11+ messages in thread
From: Randy Brukardt @ 2018-02-22 23:54 UTC (permalink / raw)


[-- Warning: decoded text below may be mangled, UTF-8 assumed --]
[-- Attachment #1: Type: text/plain, Size: 1023 bytes --]

I'd suggest looking again at DeMorgan's Law of boolean expressions. I've 
made this mistake dozens of times over the years.

                                 Randy.

"Mehdi Saada" <00120260a@gmail.com> wrote in message 
news:fd7c28a6-5605-4521-b9e9-f88b47b9714d@googlegroups.com...
This piece shall verify the program's arguments. I don't understand why 
whatever the first argument is, it doesn't raise EXC_COMMANDE as expected.
It should do it if ARGUMENT(1)(1) isn't 'n','c','N','C'.

      if Argument_Count /= 2 then PUT_LINE ("Pas le bon nombre 
d'arguments."); raise Exc_Commande;
      elsif Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'| 'c'| 'N' 
| 'C' then
        PUT_LINE ("Première argument incorrect: veuillez mettre un (seul) 
charactère entre n, c, N et C."); raise Exc_Commande;
      elsif ADA.Strings.Fixed.Index (Argument (2), Alphanumeric_Set, 
Outside) /= 0 then
  PUT_LINE ("Deuxième argument incorrect: l'acronyme ne peut pas contenir de 
chiffres !"); raise Exc_Commande;
      end if; 


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

* Re: alternative elsif branch not tested
  2018-02-22 23:54   ` Randy Brukardt
@ 2018-02-23 10:51     ` Mehdi Saada
  2018-02-23 11:04       ` briot.emmanuel
  2018-02-23 17:34       ` Jeffrey R. Carter
  0 siblings, 2 replies; 11+ messages in thread
From: Mehdi Saada @ 2018-02-23 10:51 UTC (permalink / raw)


got it ! in "Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'|'c'|'N'|'C'"
"and" must be "or" or else it complains only if when the TWO error cases are present... Funny.
As for boolean logic... when I'll have time learning Chinese. Just looking at it gives me headaches. I think sometime I'm more of a lawyer than a logician... Complicate English is still natural language, albeit convoluted, logical schema not so much. I'll still think about it when I'll encounter situation too hard to be solved in a glance.


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

* Re: alternative elsif branch not tested
  2018-02-23 10:51     ` Mehdi Saada
@ 2018-02-23 11:04       ` briot.emmanuel
  2018-02-23 17:34       ` Jeffrey R. Carter
  1 sibling, 0 replies; 11+ messages in thread
From: briot.emmanuel @ 2018-02-23 11:04 UTC (permalink / raw)


On Friday, February 23, 2018 at 11:51:55 AM UTC+1, Mehdi Saada wrote:
> got it ! in "Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'|'c'|'N'|'C'"


Also the use of "(1)" is kind of suspicious, generally speaking.
Use "Argument (Argument'First)" instead. The second "(1)" is also suspicious
and should be replaced similarly.

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

* Re: alternative elsif branch not tested
  2018-02-23 10:51     ` Mehdi Saada
  2018-02-23 11:04       ` briot.emmanuel
@ 2018-02-23 17:34       ` Jeffrey R. Carter
  2018-02-23 19:31         ` Mehdi Saada
  1 sibling, 1 reply; 11+ messages in thread
From: Jeffrey R. Carter @ 2018-02-23 17:34 UTC (permalink / raw)


On 02/23/2018 11:51 AM, Mehdi Saada wrote:
> got it ! in "Argument (1)'Length /= 1 and ARGUMENT(1)(1) not in 'n'|'c'|'N'|'C'"
> "and" must be "or" or else it complains only if when the TWO error cases are present... Funny.

What does your fixed code do if you call it like

program "" abc

?

-- 
Jeff Carter
"Strange women lying in ponds distributing swords
is no basis for a system of government."
Monty Python & the Holy Grail
66

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

* Re: alternative elsif branch not tested
  2018-02-23 17:34       ` Jeffrey R. Carter
@ 2018-02-23 19:31         ` Mehdi Saada
  0 siblings, 0 replies; 11+ messages in thread
From: Mehdi Saada @ 2018-02-23 19:31 UTC (permalink / raw)


Index check failed... I'll see that.


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

* Re: alternative elsif branch not tested
  2018-02-22 23:09 ` Mehdi Saada
  2018-02-22 23:29   ` Anh Vo
  2018-02-22 23:54   ` Randy Brukardt
@ 2018-02-23 19:39   ` Mehdi Saada
  2018-02-23 19:53     ` Jeffrey R. Carter
  2 siblings, 1 reply; 11+ messages in thread
From: Mehdi Saada @ 2018-02-23 19:39 UTC (permalink / raw)


I don't understand:
Shouldn't that line
elsif Argument (1)'Length /= 1 or Argument(1)(ARGUMENT(1)'First) not in 'n'|'c'|'N'|'C' then ...
cover the case where Argument(1)'Length = 0 (I suppose it's the problem) ?


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

* Re: alternative elsif branch not tested
  2018-02-23 19:39   ` Mehdi Saada
@ 2018-02-23 19:53     ` Jeffrey R. Carter
  2018-02-23 20:25       ` Mehdi Saada
  0 siblings, 1 reply; 11+ messages in thread
From: Jeffrey R. Carter @ 2018-02-23 19:53 UTC (permalink / raw)


On 02/23/2018 08:39 PM, Mehdi Saada wrote:
> I don't understand:
> Shouldn't that line
> elsif Argument (1)'Length /= 1 or Argument(1)(ARGUMENT(1)'First) not in 'n'|'c'|'N'|'C' then ...
> cover the case where Argument(1)'Length = 0 (I suppose it's the problem) ?

"or" is a binary operator. Like all binary operators, both of its operands are 
evaluated. See ARM 4.5.1

http://www.ada-auth.org/standards/rm12_w_tc1/html/RM-4-5-1.html

-- 
Jeff Carter
"Strange women lying in ponds distributing swords
is no basis for a system of government."
Monty Python & the Holy Grail
66

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

* Re: alternative elsif branch not tested
  2018-02-23 19:53     ` Jeffrey R. Carter
@ 2018-02-23 20:25       ` Mehdi Saada
  0 siblings, 0 replies; 11+ messages in thread
From: Mehdi Saada @ 2018-02-23 20:25 UTC (permalink / raw)


> "or" is a binary operator. Like all binary operators, both of its operands
... which means Argument(1)(ARGUMENT(1)'First) asks for a non existent component. Clever ! Thanks. I correct with "or else", then.

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

end of thread, other threads:[~2018-02-23 20:25 UTC | newest]

Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2018-02-22 22:54 alternative elsif branch not tested Mehdi Saada
2018-02-22 23:09 ` Mehdi Saada
2018-02-22 23:29   ` Anh Vo
2018-02-22 23:54   ` Randy Brukardt
2018-02-23 10:51     ` Mehdi Saada
2018-02-23 11:04       ` briot.emmanuel
2018-02-23 17:34       ` Jeffrey R. Carter
2018-02-23 19:31         ` Mehdi Saada
2018-02-23 19:39   ` Mehdi Saada
2018-02-23 19:53     ` Jeffrey R. Carter
2018-02-23 20:25       ` Mehdi Saada

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