Added "Workarounds" section and "Print a separate STRING".

Author:halw
Date:2011-07-18T13:30:39.000000Z


git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@942 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
halw
2011-07-18 13:30:39 +00:00
parent c5c596bf43
commit 3bd04c51b4

View File

@@ -65,6 +65,63 @@ and the type of <code>my_query</code> is <code>separate</code>, you should make
In version 6.8, agents targeted on separate objects are not supported.
=Workarounds=
The first implementation of SCOOP, some things that we do commonly in sequential Eiffel become somewhat awkward in SCOOP. Although not strictly limitations in the implementation of SCOOP principles, in order to make SCOOP programming easier, these are areas that should be improved in future releases. In the meantime, there are workarounds for some of these situations.
==Printing a <code>separate STRING</code> ==
Suppose you have declared a class attribute of type <code>separate STRING</code>:
<code>
my_separate_string: separate STRING = "Hello Eiffel World!"
</code>
and you want to output that string using <code>Io.put_string</code>. The solution you might use from sequential Eiffel would be:
<code>
Io.put_string (my_separate_string)
</code>
But the statement above results in a compile error because the argument type (<code>separate STRING</code>) in not compatible with the type (<code>STRING</code>) that <code>put_string</code> is expecting.
Possible workarounds are to produce a non-separate version of the string which would be printable, or to print the string character-by-character. Both involve looping through the string.
To convert objects of type <code>STRING</code> from those of type <code>separate STRING</code>, you could construct a function:
<code>
non_separate_string (a_sep_str: separate STRING): STRING
-- Non-separate copy of `a_sep_str'
do
create Result.make_empty
across (1 |..| a_sep_str.count) as ic loop Result.append_character (a_sep_str [ic.item]) end
end
</code>
Then you could print <code>my_separate_string</code> this way:
<code>
Io.put_string (non_separate_string (my_separate_string))
</code>
The other alternate is to create a procedure that will print an object of type <code>separate STRING</code>:
<code>
print_separate_string (a_sep_str: separate STRING)
-- Print `a_sep_str' on standard output.
do
across (1 |..| a_sep_str.count) as ic loop Io.put_character (a_sep_str [ic.item]) end
end
</code>
Then you could use that procedure to output <code>my_separate_string</code>:
<code>
print_separate_string (my_separate_string)
</code>
=Implementation dependent behavior=