* Procedure defined in package body accessed by separate procedure @ 2014-02-13 12:15 ashwath30jul77 2014-02-13 13:58 ` G.B. 2014-02-13 16:32 ` Dirk Heinrichs 0 siblings, 2 replies; 9+ messages in thread From: ashwath30jul77 @ 2014-02-13 12:15 UTC (permalink / raw) Hello, I am getting an error when a procedure(say Pr1) defined in a separate file invokes a procedure defined in the package(say Pk1) body(say Pr2). The compiler gives error saying that Pr2 is not declared in Pk1. Please let me know what is the mistake I am doing. Snapshots of source code is shown for better clarity. Greetings.ads: ============================= package Greetings is procedure Hello; procedure Goodbye; end Greetings; Greetings.adb: ============================== with text_io; use Text_IO; package body Greetings is procedure Hello is separate; procedure Goodbye is separate; procedure proc_body is begin put_line("body"); end; end Greetings; Greetings-Hello.ada: ================================ with text_io; use Text_IO; separate (Greetings) procedure Hello is begin put_line("Hello"); Greetings.proc_body;--Compiler error here. Says proc_body is not declared in Greetings end; I am using GNAT pro to compile this. Thanks in Advance Ashwath ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-13 12:15 Procedure defined in package body accessed by separate procedure ashwath30jul77 @ 2014-02-13 13:58 ` G.B. 2014-02-13 16:54 ` adambeneschan 2014-02-13 16:32 ` Dirk Heinrichs 1 sibling, 1 reply; 9+ messages in thread From: G.B. @ 2014-02-13 13:58 UTC (permalink / raw) On 13.02.14 13:15, ashwath30jul77@gmail.com wrote: > package body Greetings is > > procedure Hello is separate; > procedure Goodbye is separate; > procedure proc_body is > begin > put_line("body"); > end; > end Greetings; > > Greetings-Hello.ada: > ================================ > with text_io; > use Text_IO; > separate (Greetings) > > procedure Hello is > begin > put_line("Hello"); > Greetings.proc_body;--Compiler error here. Says proc_body is not declared in Greetings > end; Linearity of reading seems at work here: proc_body, in body Greetings, appears after the line that says "Hello is separate". Therefore, when that line is "evaluated", there is no procedure proc_body (yet). To resolve the issue, either put a specification of procedure proc_body before "... Hello is separate", or put the latter line after proc_body's definition. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-13 13:58 ` G.B. @ 2014-02-13 16:54 ` adambeneschan 2014-02-14 6:30 ` ashwath30jul77 0 siblings, 1 reply; 9+ messages in thread From: adambeneschan @ 2014-02-13 16:54 UTC (permalink / raw) On Thursday, February 13, 2014 5:58:33 AM UTC-8, G.B. wrote: > > package body Greetings is > > procedure Hello is separate; > > procedure Goodbye is separate; > > procedure proc_body is > > begin > > put_line("body"); > > end; > > end Greetings; > > Greetings-Hello.ada: > > ================================ > > with text_io; > > use Text_IO; > > separate (Greetings) > > procedure Hello is > > begin > > put_line("Hello"); > > Greetings.proc_body;--Compiler error here. Says proc_body is not declared in Greetings > > end; > > Linearity of reading seems at work here: proc_body, in body > Greetings, appears after the line that says "Hello is > separate". Therefore, when that line is "evaluated", there > is no procedure proc_body (yet). Yes, that's the reason. The RM says (10.1.3(17)): "Visibility within a subunit is the visibility that would be obtained at the place of the corresponding body_stub (within the parent body) if the context_clause of the subunit were appended to that of the parent body." So that means that the things that are visible to Hello's separate body are the same things that would be visible at the place the "procedure Hello is separate" (the body stub) appeared. If there were a *new* "with" or "use" clause on the separate body, that would make other things visible as well. In this case, since there is already "with Text_IO; use Text_IO;" on the body of Greetings, the WITH and USE on the body of Hello doesn't make anything else visible. (In fact, they're redundant and could be removed. My personal preference is to include redundant WITH's and USE's anyway, so that you don't have to flip between a bunch of source files to figure out what WITH's and USE's are in effect.) But anyway, if you wrote all of Hello inline in the body of Greetings, instead of making it separate, you'd get the same error on proc_body; therefore, the same error occurs in the separate body, since the same identifiers are visible. -- Adam ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-13 16:54 ` adambeneschan @ 2014-02-14 6:30 ` ashwath30jul77 2014-02-14 9:22 ` Simon Wright 0 siblings, 1 reply; 9+ messages in thread From: ashwath30jul77 @ 2014-02-14 6:30 UTC (permalink / raw) On Thursday, February 13, 2014 10:24:53 PM UTC+5:30, adambe...@gmail.com wrote: > On Thursday, February 13, 2014 5:58:33 AM UTC-8, G.B. wrote: > > > > > > package body Greetings is > > > > procedure Hello is separate; > > > > procedure Goodbye is separate; > > > > procedure proc_body is > > > > begin > > > > put_line("body"); > > > > end; > > > > end Greetings; > > > > > > Greetings-Hello.ada: > > > > ================================ > > > > with text_io; > > > > use Text_IO; > > > > separate (Greetings) > > > > procedure Hello is > > > > begin > > > > put_line("Hello"); > > > > Greetings.proc_body;--Compiler error here. Says proc_body is not declared in Greetings > > > > end; > > > > > > Linearity of reading seems at work here: proc_body, in body > > > Greetings, appears after the line that says "Hello is > > > separate". Therefore, when that line is "evaluated", there > > > is no procedure proc_body (yet). > > > > Yes, that's the reason. The RM says (10.1.3(17)): > > > > "Visibility within a subunit is the visibility that would be obtained at the place of the corresponding body_stub (within the parent body) if the context_clause of the subunit were appended to that of the parent body." > > > > So that means that the things that are visible to Hello's separate body are the same things that would be visible at the place the "procedure Hello is separate" (the body stub) appeared. If there were a *new* "with" or "use" clause on the separate body, that would make other things visible as well. In this case, since there is already "with Text_IO; use Text_IO;" on the body of Greetings, the WITH and USE on the body of Hello doesn't make anything else visible. (In fact, they're redundant and could be removed. My personal preference is to include redundant WITH's and USE's anyway, so that you don't have to flip between a bunch of source files to figure out what WITH's and USE's are in effect.) But anyway, if you wrote all of Hello inline in the body of Greetings, instead of making it separate, you'd get the same error on proc_body; therefore, the same error occurs in the separate body, since the same identifiers are visible. > > > > -- Adam Thanks for response Adam. Is this compiler specific?It seems to compile when Tartan compiler is used :S ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-14 6:30 ` ashwath30jul77 @ 2014-02-14 9:22 ` Simon Wright 0 siblings, 0 replies; 9+ messages in thread From: Simon Wright @ 2014-02-14 9:22 UTC (permalink / raw) ashwath30jul77@gmail.com writes: > Is this compiler specific?It seems to compile when Tartan compiler is > used :S That would be a bug in the Tartan compiler. And, could you _please_ trim irrelevant lines? Google Groups may hide them, but other newsreaders don't. ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-13 12:15 Procedure defined in package body accessed by separate procedure ashwath30jul77 2014-02-13 13:58 ` G.B. @ 2014-02-13 16:32 ` Dirk Heinrichs 2014-02-13 16:43 ` adambeneschan 1 sibling, 1 reply; 9+ messages in thread From: Dirk Heinrichs @ 2014-02-13 16:32 UTC (permalink / raw) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 ashwath30jul77@gmail.com wrote: > Hello, > I am getting an error when a procedure(say Pr1) defined in a separate file > invokes a procedure defined in the package(say Pk1) body(say Pr2). The > compiler gives error saying that Pr2 is not declared in Pk1. > > Please let me know what is the mistake I am doing. > > Snapshots of source code is shown for better clarity. > > Greetings.ads: > ============================= > package Greetings is > > procedure Hello; > procedure Goodbye; > > end Greetings; > > Greetings.adb: > ============================== > with text_io; > use Text_IO; > > package body Greetings is > > procedure Hello is separate; > procedure Goodbye is separate; > procedure proc_body is > begin > put_line("body"); > end; > end Greetings; > > Greetings-Hello.ada: > ================================ > with text_io; > use Text_IO; > separate (Greetings) Should be "with Greetings;" > > procedure Hello is > begin > put_line("Hello"); > Greetings.proc_body;--Compiler error here. Says proc_body is not > declared in Greetings Which is correct, because it's not in the spec. As long as it's in the body only, you can't call it from other packages. HTH... Dirk - -- Dirk Heinrichs <dirk.heinrichs@altum.de> Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913 GPG Public Key CB614542 | Jabber: dirk.heinrichs@altum.de -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) iQIVAwUBUvzztcwdtL3LYUVCAQpfDw//Wug+tl7zoj09/08NM/gXxB2kJnThKgdN XzGbqST33GWFyVLv7nVMYHcDfn6leXkPWGh6RZ60X6khq2j/nZ3l0LkxibrmmUIJ hqQFegF9op0i5Y1axHZ5X7yJXZtpK6repwlVrrrSwQPqfkIjDIibfSHydzRTeiLX b59Q0utjOMGd/4isJjyZ4M+oO6VodfOmJEtbap0hNcCBHHA62NEgEhd85Sh+ixdW BWsV6Dw7Libd0iiSuhOdU2r+kSOvOz3nqd2nonW7uKLICDgxrJojqzTnebkeSNwP y4T5UH7/T1VrBpUqTsC8I6Pmh54y9S3ar6G+jLL8ClYILPGXUiwkmUZ+S13TEtn3 9Q4oLNzqOSlYFc7TChhio3WGahk4A0aD2LQXwTwAD9tlhRphTa80+RvaAX31X3Aw qQUC8A3lQ7/+6eV8P0Bd+S7TPKSYcAcB7RsMx+JeihYT1XS2U0cpg0P9sFv6EKmm 2plB6JvExrwBoJ09fB0SpczPt+vCPaMKJ5wVJUtcASYZMIBsVv3m0DaR8usgRe4+ sdw1zprKIer/zBUl+f4SKT+jM34I5bf7ka82uN3ijGHmTLTkTLAhL6RHBcXmTBL/ NdJDQjFMezjsA21plk/OCo888sH6LhdurIkPS/ELRGDxs+D3ZBThGdus4ICxLW5X B2Zt708/0yM= =Mqm8 -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-13 16:32 ` Dirk Heinrichs @ 2014-02-13 16:43 ` adambeneschan 2014-02-13 16:57 ` Dirk Heinrichs 0 siblings, 1 reply; 9+ messages in thread From: adambeneschan @ 2014-02-13 16:43 UTC (permalink / raw) On Thursday, February 13, 2014 8:32:53 AM UTC-8, Dirk Heinrichs wrote: > > > with text_io; > > use Text_IO; > > separate (Greetings) > > Should be "with Greetings;" No, this is misinformation. separate(Greetings) is correct. -- Adam ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-13 16:43 ` adambeneschan @ 2014-02-13 16:57 ` Dirk Heinrichs 2014-02-13 16:59 ` Dirk Heinrichs 0 siblings, 1 reply; 9+ messages in thread From: Dirk Heinrichs @ 2014-02-13 16:57 UTC (permalink / raw) -----BEGIN PGP SIGNED MESSAGE----- Hash: SHA512 adambeneschan@gmail.com wrote: >> > separate (Greetings) >> >> Should be "with Greetings;" > > No, this is misinformation. separate(Greetings) is correct. Hmm, I thought I could only use that in sub units. Bye... Dirk - -- Dirk Heinrichs <dirk.heinrichs@altum.de> Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913 GPG Public Key CB614542 | Jabber: dirk.heinrichs@altum.de -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.14 (GNU/Linux) iQIVAwUBUvz5cswdtL3LYUVCAQr0TA//ZiHWUwdfoVDZkyuZIcqLXbElvBts2Ev4 1Eocxy93PEwGX5pK1vE4XhJ+8mE89/p9yR28aNqmWAyfs/X3clD3VMcA2g/qfjDC KUD89JvZrcJGwZNdtQtkhWdS0OKPmyxCM61YD/sqRktLSmegvpACiCv275hW1mwy Ixhn53crnM+ka9ZaK9eFynB892rxjYIY2tuRymxIxRpdOb61dFD7x/XEE0WCLWpS DHJ/QzqOcZlPu6K6OFICESQw5YBiDGda2m1EYe6u2q05ZfvIyN4W1qc3jjTAf3/q uA1qcNcx5RC8CwjXWprhCS+iAfCO2FgumsCzNxHGIGbiQtFDwDiXbOFXhcttd/Kw Dc6z5rCES4/hjAMgCCB269Mwg3e4hRVWsrnDQ0JIiN/bP4gwRbbhxaYceIF4em3w 2xC5+raR3eojNP7Kquhv5xxDy0l9s7dSAWWy35Yw4XqM5fgK45OMC72IHCYrSOp8 jKZ4ya/nVe2iqtoKOZnatGtDcFu6JYFgmfBr/AhLKa4uFD6A964qTycmqUzMjrH7 b3MJq86V9cc1mA7e8FPt8nBeW+teBO1DXLsRXixT/4srAqFUbYQ45/lbsRsfObZ6 dYJE+N//gKMk5tEjdp/J2FUsv1ohPemBW6EoepGpOFgX/vO3SiZkTfYJtlzsyXu3 ukU1kiLdkYg= =hQCz -----END PGP SIGNATURE----- ^ permalink raw reply [flat|nested] 9+ messages in thread
* Re: Procedure defined in package body accessed by separate procedure 2014-02-13 16:57 ` Dirk Heinrichs @ 2014-02-13 16:59 ` Dirk Heinrichs 0 siblings, 0 replies; 9+ messages in thread From: Dirk Heinrichs @ 2014-02-13 16:59 UTC (permalink / raw) Dirk Heinrichs wrote: >>> > separate (Greetings) >>> >>> Should be "with Greetings;" >> >> No, this is misinformation. separate(Greetings) is correct. > > Hmm, I thought I could only use that in sub units. Ah, sorry. Didn't see that the last file actually IS a sub unit (Greetings- Hello.ada). Bye... Dirk -- Dirk Heinrichs <dirk.heinrichs@altum.de> Tel: +49 (0)2471 209385 | Mobil: +49 (0)176 34473913 GPG Public Key CB614542 | Jabber: dirk.heinrichs@altum.de ^ permalink raw reply [flat|nested] 9+ messages in thread
end of thread, other threads:[~2014-02-14 9:22 UTC | newest] Thread overview: 9+ messages (download: mbox.gz / follow: Atom feed) -- links below jump to the message on this page -- 2014-02-13 12:15 Procedure defined in package body accessed by separate procedure ashwath30jul77 2014-02-13 13:58 ` G.B. 2014-02-13 16:54 ` adambeneschan 2014-02-14 6:30 ` ashwath30jul77 2014-02-14 9:22 ` Simon Wright 2014-02-13 16:32 ` Dirk Heinrichs 2014-02-13 16:43 ` adambeneschan 2014-02-13 16:57 ` Dirk Heinrichs 2014-02-13 16:59 ` Dirk Heinrichs
This is a public inbox, see mirroring instructions for how to clone and mirror all data and code used for this inbox