created 20.11

git-svn-id: https://svn.eiffel.com/eiffel-org/trunk@2267 abb3cda0-5349-4a8f-a601-0c33ac3a8c38
This commit is contained in:
eifops
2020-12-04 15:34:39 +00:00
parent 0f1156d9cc
commit 5049d0d511
2944 changed files with 62467 additions and 0 deletions

View File

@@ -0,0 +1,17 @@
[[Property:modification_date|Mon, 10 Sep 2018 09:09:25 GMT]]
[[Property:publication_date|Mon, 10 Sep 2018 09:09:25 GMT]]
[[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 `out` method that can be used to get a text version of the object. For a lot of classes, this method returns internal information that is not really useful for the end user. But for every `NUMERIC` class, the `out` method returns a text representation of the number that the `NUMERIC` 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 advanced conversion, you can also use a conversion class like `FORMAT_DOUBLE`.

View File

@@ -0,0 +1,28 @@
[[Property:modification_date|Mon, 10 Sep 2018 09:06:41 GMT]]
[[Property:publication_date|Fri, 07 Sep 2018 12:13:00 GMT]]
[[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 `LIST` you can easily use `prune` and `prune_all`. But if you want to remove objects while iterating on that `LIST`, depending on criteria on the objects contained in the `LIST`, here is what you can do.
First of all, if you think about removing an object while iterating, I do not recommend using an `across` loop. If you iterate on the list using a `from until loop end`, just remember to use the `LIST.forth` only when you do not use `LIST.remove`.
For example, let's say we have class `MY_CLASS` with an attribute `has_stopped` and that I want to remove every object of a `LIST` that has this attribute set to `True`. Here is 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_stopped then
a_list.remove
else
a_list.forth
end
end
end
</code>

View File

@@ -0,0 +1,64 @@
[[Property:modification_date|Wed, 17 Apr 2019 14:09:18 GMT]]
[[Property:publication_date|Thu, 06 Sep 2018 15:17:57 GMT]]
[[Property:uuid|96077603-DD2D-4D8C-A486-AF4BD066613A]]
[[Property:weight|2000]]
[[Property:title|Iterating on a LIST]]
There are three Eiffel mechanisms to iterate on every element of a `LIST`.
=== the `across` loop ===
The `across` can be used on every `ITERABLE` object (including `LIST` objects).
<code>
print_elements (a_list: LIST[INTEGER])
-- Print every elements on `a_list`
do
across a_list as ic loop
print (ic.item.out + "%N")
end
end
</code>
Note that the temporary variable (`ic` in the example) represents an iterator of the `ITERABLE` object, and not directly an element like in many other languages (like the `for` structure in Python for example).
=== the `from until` loop syntax===
This syntax offer more possibilities than the `across` 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>
=== Using Eiffel agents and `{LIST}.do_all, ....` ===
It is possible to use agents in conjunction with the `LIST` features `do_all`, `do_if`, `there_exists`, and `for_all` which are inherited from the class `LINEAR`.
<code>
list_traversal_agents
-- Example of traversing a list with do_all
local
a_list: LINKED_LIST [STRING]
do
-- Insert some elements in a_list
create a_list.make
a_list.extend ("The Moon Is Full")
a_list.extend ("Master charge")
a_list.extend ("Black cat bone")
a_list.do_all (agent {STRING}.append (" - Albert Collins"))
a_list.do_all (agent print_element)
end
print_element (a_element: STRING)
-- Print `a_element` to standard output
do
io.put_string (a_element)
io.put_new_line
end
</code>

View File

@@ -0,0 +1,54 @@
[[Property:modification_date|Wed, 17 Apr 2019 14:06:41 GMT]]
[[Property:publication_date|Wed, 17 Apr 2019 14:02:25 GMT]]
[[Property:uuid|5CA34C5D-30F1-4D6F-9FE4-B555E541EA8C]]
[[Property:weight|4000]]
[[Property:title|Managing CTRL+C in console application]]
Normally, if the user uses 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> mechanism to cancel the exception handling 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>.
Note that this code does not work on Windows. If used on Windows, the application will quit, but the <code>rescue</code> call is not launched.
<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,10 @@
[[Property:modification_date|Mon, 10 Sep 2018 09:04:15 GMT]]
[[Property:publication_date|Mon, 10 Sep 2018 09:04:15 GMT]]
[[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 you can use to learn some very specific mechanics in Eiffel. Those how-tos are small by design and can be used to show very fundamental, or more advanced, mechanisms for beginners.