Merged 18.01 changes into trunk.

git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2030 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
eiffel-org
2018-05-28 16:59:46 +00:00
parent 9a70b1005d
commit 425ebed7d6
8 changed files with 158 additions and 6 deletions

View File

@@ -0,0 +1,15 @@
[[Property:uuid|B74D374E-895C-4F22-B95F-656BD78ECD03]]
[[Property:weight|1000]]
[[Property:title|Getting a STRING from a NUMERIC object]]
[[Property:link_title|NUMERIC to STRING]]
Every class has the <code>out</code> method that can be used to get a text version of the object. For a lot of class, this method return internal informations that are not really useful for the end user. But for every <code>NUMERIC</code> class, the <code>out</code> method return a text representation of the number that the <code>NUMERIC</code> object represents.
<code>
print_integer(a_integer:INTEGER)
-- Print the value of `a_integer'
do
print(a_integer.out + "%N")
end
</code>
Note that for more advance convertion, you can also used convertion class like <code>FORMAT_DOUBLE</code>.

View File

@@ -0,0 +1,26 @@
[[Property:uuid|78393BBA-9B1E-4523-9881-3D83CEB6A952]]
[[Property:weight|3000]]
[[Property:title|Removing object while iterating on a LIST]]
If you already have the object that you want to remove from the <code>LIST</code> you can easily use <code>prune</code> and <code>prune_all</code>. But if you want to remove objects while iterating on that <code>LIST</code>, depending on criteria on the objects contained in the <code>LIST</code>, here what you can do.
First of all, if you think about removing object while iterating, I do not recommend using an <code>across</code> loop. If you iterate on the list using a <code>from until loop end</code>, just remember to use the <code>LIST.forth</code> only when you do not use <code>LIST.remove</code>.
For example, let's say we have class <code>MY_CLASS</code> with an attribute <code>has_stopped</code> and that I want to remove every object of a <code>LIST</code> that has this attribute set to <code>True</code>. Here what the code will look like.
<code>
removing_stopped(a_list:LIST[MY_CLASS])
-- Removing every closed element of `a_list'
do
from
a_list.start
until
a_list.exhausted
loop
if a_list.item.has_stoped then
a_list.remove
else
a_list.forth
end
end
end
</code>

View File

@@ -0,0 +1,35 @@
[[Property:uuid|96077603-DD2D-4D8C-A486-AF4BD066613A]]
[[Property:weight|2000]]
[[Property:title|Iterating on a LIST]]
There are two Eiffel mechanisms to iterate on every element of a <code>LIST</code>.
The first it the <code>across</code> loop. The <code>across</code> can be used on every <code>ITERABLE</code> object (including <code>LIST</code> objects).
<code>
print_elements(a_list:LIST[INTEGER])
-- Print every elements on `a_list'
do
across a_list as la_list loop
print(la_list.item.out + "%N")
end
end
</code>
Note that the temporary variable (<code>la_list</code> in the example) represent an iterator of the <code>ITERABLE</code> object, and not directly an element like in many other languages (like the <code>for</code> structure in Python for example).
The other mechanism uses the <code>from until</code> loop syntax. This syntax offer more possibilities than the <code>across</code> loop, but is riskier.
<code>
print_elements(a_list:LIST[INTEGER])
-- Print every elements on `a_list'
do
from
a_list.start
until
a_list.exhausted
loop
print(a_list.item.out + "%N")
a_list.forth
end
end
</code>

View File

@@ -0,0 +1,50 @@
[[Property:uuid|5CA34C5D-30F1-4D6F-9FE4-B555E541EA8C]]
[[Property:weight|4000]]
[[Property:title|Managing CTRL+C in console application]]
Normally, if the user use the CTRL+C keys, the Eiffel application detect it as an error and throw an exception of type <code>OPERATING_SYSTEM_SIGNAL_FAILURE</code>.
To manage the CTRL+C keys, you can use a <code>rescue</code> clause to detect the exception and a <code>retry</code> mecanism to cancel the exception handeling done by the Eiffel runtime.
To detect the exception, you can <code>inherit</code> from the <code>EXCEPTIONS</code> class and use an attachment test on <code>Exception_manager.last_exception</code>.
<code>
note
description: "Show how to quit an application using CTRL+C (without trace)."
author: "Louis Marchand"
date: "Wed, 25 Apr 2018 23:12:33 +0000"
revision: "0.1"
class
APPLICATION
inherit
EXCEPTIONS
create
make
feature {NONE} -- Initialization
make
-- Launch `Current'.
local
l_ctrl_c:BOOLEAN
do
if not l_ctrl_c then
from until False loop
io.standard_default.put_string ("Press CTRL+C%N")
io.input.read_line
end
else
io.standard_default.put_string ("%NClosing...%N")
end
rescue
if attached {OPERATING_SYSTEM_SIGNAL_FAILURE}
Exception_manager.last_exception then
l_ctrl_c := True
retry
end
end
end
</code>

View File

@@ -0,0 +1,7 @@
[[Property:link_title|Mini How-tos]]
[[Property:uuid|B2E4622A-2495-47DD-9C02-B9940A026EC1]]
[[Property:weight|0]]
[[Property:title|Mini How-tos]]
In this section, you will find little how-tos that can be used to know how to used some very specific mechanics in Eiffel. Those how-tos are small by design and can be used to show very fundamental mechanisms for beginners or more advance mechanisms.