I'm really stuck in how to pass an argument to a second level of an Eiffel agent call. Hope my example is enough self explaining:
main_call
do
b (agent d(?, ?))
end
b (a_proc: PROCEDURE[STRING])
local
l_something_else: INTEGER
do
l_something_else := 1
-- z("a_line", a_proc(l_something_else)) -- How can I pass at this stade l_something_else to the d procedure!!!
end
d (line: STRING; something_else: INTEGER)
do
-- do_some_stuff_with_line (line, something_else)
do_nothing
end
z (a_line: STRING; a_proc: PROCEDURE[STRING])
do
a_proc.call([a_line])
end
I would have liked to be able to do something like
z("a_line", a_proc(?, something_else))
But its not possible, as I try with the agent keyword, the a_proc argument is not recognized!
So what would be the syntax? I even tried to add an argument to a_proc with a_proc.set_operands
but am lost with the OPEN_ARGS
class
Implementation case
If you need a goal... just imagine I'd like to have 2 different implementations of the d
function, and in my case its using UT_CSV_HANDLER
that I'd like to have 2 different functions for each line of a CVS
The following code gives a Non-compatible actual argument in feature call
Feature: import_from_csv_impl
Called feature: import_from_csv_impl (a_rest_request: REST_REQUEST; a_procedure: PROCEDURE [DS_ARRAYED_LIST [STRING_8], INTEGER_64, STRING_8]): [detachable like items] detachable SIT_LINKED_LIST [MEASURING_POINT] from MEASURING_POI...
Argument name: ia_name
Argument position: 2
Formal argument type: STRING_8
Actual argument type: INTEGER_64
Line: 258
ia_procedure.call (ia_measuring_point_id, ia_name)
-> end (?, l_measuring_point_id, l_s)
l_csv_handler.read_file (l_is, l_partially_closed)
The complete example:
-- Main call
import_from_abb_csv (a_rest_request: REST_REQUEST): detachable like items
do
Result := import_from_csv_impl (a_rest_request, agent impl_for_each_csv_line_import_from_abb_csv)
end
-- Second call
import_from_csv_impl (a_rest_request: REST_REQUEST; a_procedure: PROCEDURE[DS_ARRAYED_LIST [STRING_8], INTEGER_64, STRING]): detachable like items
local
l_csv_handler: UT_CSV_HANDLER
l_is: KL_STRING_INPUT_STREAM
l_measuring_point_id: INTEGER_64
l_s: STRING
l_partially_closed: PROCEDURE[DS_ARRAYED_LIST[STRING]]
do
l_s := "whatever"
l_measuring_point_id := 12
create l_csv_handler.make_with_separator (',')
l_partially_closed := agent (i_al: DS_ARRAYED_LIST[STRING]; ia_measuring_point_id: INTEGER_64; ia_name: STRING; ia_procedure: PROCEDURE[INTEGER_64, STRING])
do
ia_procedure.call (ia_measuring_point_id, ia_name)
end (?, l_measuring_point_id, l_s)
l_csv_handler.read_file (l_is, l_partially_closed)
end
-- end call
impl_for_each_csv_line_import_from_abb_csv (a_csv_line: DS_ARRAYED_LIST [STRING_8]; a_measuring_point_id: INTEGER_64; l_cu_name: STRING)
do
-- do_my_business
end
-- for information signature of read_file is:
-- read_file (a_file: KI_TEXT_INPUT_STREAM; a_action: PROCEDURE [DS_ARRAYED_LIST [STRING]])