Ada 程式設計/關鍵字/use
外觀
Use 子句有兩種版本:use_package_clause 和 use_type_clause。
此 use_package_clause 使 包 的內容直接可見。如果應用在庫級別,它的作用範圍是整個庫單元。
Use 子句不會隱藏任何原本無需它就能直接可見的內容。在某個範圍內生效的所有 use 子句都處於同一級別:來自不同包的兩個同音異義詞仍然必須作為選定元件進行命名。
withAda.Text_IO;useAda.Text_IO;procedureHelloisbeginPut_Line("Hello, world!"); New_Line; Put_Line("I am an Ada program with package use.");endHello;
如果可讀性是你的主要關注點,那麼你應該避免使用這種 use 子句。要麼使它更區域性化,要麼使用 use_type_clause。
效果與上面相同,但作用範圍是直接包含的宣告區域。
withAda.Text_IO;procedureHelloisuseAda.Text_IO;beginPut_Line("Hello, world!"); New_Line; Put_Line("I am an Ada program with package use.");endHello;
Use 型別子句有兩種版本。
usetypeType_Name;
使型別的運算子直接可見。
usealltypeType_Name;
使型別的基本操作直接可見。
記錄表示子句指定記錄的 佈局 方面。
列舉表示子句指定列舉型別的 編碼 方面。
參見 Ada 程式設計/表示子句。
- 2.9: 保留字 [註釋]
- 附錄 P:(資訊性)語法摘要 [註釋]
- 8.3: 可見性 [註釋]
- 8.4: Use 子句 [註釋]
- 13.3: 操作和表示屬性 [註釋]
- 13.4: 列舉表示子句 [註釋]
- 13.5.1: 記錄表示子句 [註釋]
| Ada 關鍵字 | ||||
|---|---|---|---|---|
abort
|
else
|
new
|
return
|
|
abs
|
elsif
|
not
|
reverse
|
|
abstract (Ada 95) |
end
|
null
|
||
accept
|
entry
|
select
|
||
access
|
exception
|
of
|
separate
|
|
aliased (Ada 95) |
exit
|
or
|
some (Ada 2012) |
|
all
|
others
|
subtype
|
||
and
|
for
|
out
|
synchronized (Ada 2005) |
|
array
|
function
|
overriding (Ada 2005) |
||
at
|
tagged (Ada 95) |
|||
generic
|
package
|
task
|
||
begin
|
goto
|
parallel (Ada 2022) |
terminate
|
|
body
|
pragma
|
then
|
||
if
|
private
|
type
|
||
case
|
in
|
procedure
|
||
constant
|
interface (Ada 2005) |
protected (Ada 95) |
until (Ada 95) |
|
is
|
use
|
|||
declare
|
raise
|
|||
delay
|
limited
|
range
|
when
|
|
delta
|
loop
|
record
|
while
|
|
digits
|
rem
|
with
|
||
do
|
mod
|
renames
|
||
requeue (Ada 95) |
xor
|
|||
