comp.lang.ada
 help / color / mirror / Atom feed
From: Mehdi Saada <00120260a@gmail.com>
Subject: On naming space and the good use of qualified expression
Date: Fri, 19 Jan 2018 09:51:04 -0800 (PST)
Date: 2018-01-19T09:51:04-08:00	[thread overview]
Message-ID: <310b1dea-459b-4a8b-b249-5bb63ea43512@googlegroups.com> (raw)

At that point of the program, I have three "/" operators visibles:
function "/" (A: T_Rational, B: T_Rational) return T_Rational;
function "/" (A: T_Integer, B: T_Integer) return T_Integer;
function "/" (A: T_Integer, B: T_Integer) return T_Rational; -- my constructor method
which makes this expression ambiguous:
Result.Coef(Ind) := Poly_A.Coef(Ind+1) * (Ind+1)/1;
(Coef is an array of T_Rational, Ind is of the same type as the index)

For the first time, I grasp what "namespace polution" means. I overestimated the compiler's smartness. I tried then:
Result.Coef(Ind) := Poly_A.Coef(Ind+1) * T_Rational'((Ind+1)/1);
As I thought qualified expression were a means to inform the compiler of the intended type of the parenthesed expression, so that it could choose based on the litteral inside AND the different visible homonymous functions.
But I got the same error with or without qualified expression:
p_poly_v1_g.adb:82:71: expected private type "T_Rational" defined at p_rationals_g.ads:11, instance at p_poly_v1_g.ads:19
p_poly_v1_g.adb:82:71: found type "Standard.Integer"

Was I mistaken about qualified expressions ?
How can I express myself so that the compiler understand, BESIDES prefixing every single operators with P_Rationals, which is ugly.
I try to understand the use of "use type" and use "all type ...", but I don't manager to for the moment. The language doesn't help, when confronted with new technical stuff. I get it better through exemples...


             reply	other threads:[~2018-01-19 17:51 UTC|newest]

Thread overview: 5+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2018-01-19 17:51 Mehdi Saada [this message]
2018-01-19 18:37 ` On naming space and the good use of qualified expression Niklas Holsti
2018-01-19 18:38 ` AdaMagica
2018-01-19 18:55 ` Jeffrey R. Carter
2018-01-19 23:23   ` Mehdi Saada
replies disabled

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