PR# 19494 Enable the ability to anchor on an agent's result type.
Problem Report Summary
Submitter: q2santos
Category: Compiler
Priority: Medium
Date: 2018/11/05
Class: Feature Request
Severity: Serious
Number: 19494
Release: 18.7
Confidential: No
Status: Open
Responsible:
Environment: any
Synopsis: Enable the ability to anchor on an agent's result type.
Description
A map function's signature can be as trivial as the following: map (anchor: ANY; mapper: FUNCTION [G, like anchor]): ITERABLE [like anchor] It would be perfect if one could anchor on the function's result like this: map (mapper: FUNCTION [G, ANY]): ITERABLE [like mapper.last_result] Alternatively, one would have generic functions: map [T] (mapper: FUNCTION [G, T]): ITERABLE [T] Or contextual types as suggested by Bertrand Meyer here: https://www.eiffel.org/doc-file/eiffel/expression_language.pdf
To Reproduce
Here's an example where it would be useful: note description: "map_testers application root class" date: "$Date$" revision: "$Revision$" class APPLICATION inherit ARGUMENTS_32 create make feature {NONE} -- Initialization make -- Run application. do -- Mapping to string: across map (<<1, 2, 3>>, "", agent to_string (?)) as cursor loop print (cursor.item + "%N") end -- No mapping: across map (<<1, 2, 3>>, 0, agent identity (?)) as cursor loop print (cursor.item.out + "%N") end end to_string (n: INTEGER): STRING do Result := "(" + n.out + ")" end identity (n: INTEGER): INTEGER do Result := n end feature {NONE} -- Mapping map (source: ITERABLE[INTEGER]; anchor: ANY; mapper: FUNCTION[INTEGER, like anchor]): ITERABLE[like anchor] local target: ARRAYED_LIST[like anchor] do create target.make (10) across source as cursor loop target.extend (mapper (cursor.item)) end Result := target end end
Problem Report Interactions