Eiffel:多个通用约束的语法错误
Eiffel: syntax error on multiple Generic constraint
根据 this documentation,我试图将通用参数限制为 2 类 并且在我的实现中需要一个 default_create
创建过程调用。
我在 select
子句上从编译器得到一个 Syntax error
。为什么会这样?
我首先想到调用 default_create
将调用 G
一个可能是 merge/renaming/etc。但似乎在那个级别上我必须调用两者之一或两者都重命名这对我来说很有意义。但是为什么这个语法会失败?
上下文和我的代码如下:
deferred class
IDENTIFIABLE_CASH[G -> {IDENTIFIABLE[ANY],
DB_ENTITY select default_create end} create default_create end]
inherit
DB_SERVICE_CASH[G]
feature -- Access
cash_from_identifier (an_identifier: like {IDENTIFIABLE_DB_ENTITY[ANY]}.identifier): G
-- Returns firt entity found like given an_identifier (like operator is used)
local
l_qry: COMPOSED_SQL_QUERY
do
across
cash is l_item
loop
if l_item.identifier.is_equal(an_identifier) then
Result := l_item
end
end
if not attached Result then
create l_qry.make (item_prototype)
l_qry.add_constraint (create {FIELD_CONSTRAINT}.make (Void, identifier_db_column_name, {CONSTRAINT}.Like_operator, an_identifier))
load_entities (l_qry)
if items.count > 0 then
Result := items.first
else
create Result
check
item_not_found: False
end
end
cash.extend (Result)
end
end
page 声明 select
子句不是标准的一部分,应该使用 rename
代替。换句话说,为两个约束 类 中的至少一个重命名 default_create
并使用该功能的一个版本就足够了,例如default_create
:
G -> {IDENTIFIABLE[ANY], DB_ENTITY rename default_create as d end}
create default_create end
在上面的例子中,Result
可以用create Result
或create Result.default_create
创建。也可以使用第二个版本:
G -> {IDENTIFIABLE[ANY], DB_ENTITY rename default_create as d end}
create d end
现在 Result
只能用 create Result.d
创建。最后,可以列出两个创建过程:
G -> {IDENTIFIABLE[ANY], DB_ENTITY rename default_create as d end}
create default_create, d end
最后一个变体允许使用 create Result.default_create
或 create Result.d
。
根据 this documentation,我试图将通用参数限制为 2 类 并且在我的实现中需要一个 default_create
创建过程调用。
我在 select
子句上从编译器得到一个 Syntax error
。为什么会这样?
我首先想到调用 default_create
将调用 G
一个可能是 merge/renaming/etc。但似乎在那个级别上我必须调用两者之一或两者都重命名这对我来说很有意义。但是为什么这个语法会失败?
上下文和我的代码如下:
deferred class
IDENTIFIABLE_CASH[G -> {IDENTIFIABLE[ANY],
DB_ENTITY select default_create end} create default_create end]
inherit
DB_SERVICE_CASH[G]
feature -- Access
cash_from_identifier (an_identifier: like {IDENTIFIABLE_DB_ENTITY[ANY]}.identifier): G
-- Returns firt entity found like given an_identifier (like operator is used)
local
l_qry: COMPOSED_SQL_QUERY
do
across
cash is l_item
loop
if l_item.identifier.is_equal(an_identifier) then
Result := l_item
end
end
if not attached Result then
create l_qry.make (item_prototype)
l_qry.add_constraint (create {FIELD_CONSTRAINT}.make (Void, identifier_db_column_name, {CONSTRAINT}.Like_operator, an_identifier))
load_entities (l_qry)
if items.count > 0 then
Result := items.first
else
create Result
check
item_not_found: False
end
end
cash.extend (Result)
end
end
page 声明 select
子句不是标准的一部分,应该使用 rename
代替。换句话说,为两个约束 类 中的至少一个重命名 default_create
并使用该功能的一个版本就足够了,例如default_create
:
G -> {IDENTIFIABLE[ANY], DB_ENTITY rename default_create as d end}
create default_create end
在上面的例子中,Result
可以用create Result
或create Result.default_create
创建。也可以使用第二个版本:
G -> {IDENTIFIABLE[ANY], DB_ENTITY rename default_create as d end}
create d end
现在 Result
只能用 create Result.d
创建。最后,可以列出两个创建过程:
G -> {IDENTIFIABLE[ANY], DB_ENTITY rename default_create as d end}
create default_create, d end
最后一个变体允许使用 create Result.default_create
或 create Result.d
。