Eiffel Community (original) (raw)
io.put_string_32 ("[
Hello!
¡Hola!
Bonjour!
こんにちは!
Здравствуйте!
Γειά σου!
]")
Unicode output in console
feature -- Access
...
invariant
all_items_valid: ∀ x: items ¦ x.is_valid at_least_one_marked: ∃ x: items ¦ x.is_marked
end
Assertions: class invariants with symbolic notation
values := << 1, 2, 4, 8 >>
-- Sum of (index * values [index]).
across values as i from sum := 0 loop sum := sum + i.cursor_index * i.item end
rating := locale.plural_translation_in_context ("$1 star", "$1 stars", "example.context", n) ...
rating: READABLE_STRING_32 -- Translated message.
locale: I18N_LOCALE -- Currently selected locale with translations. do ... end
class DINING_PHILOSOPHER ... feature -- Basic operations
eat (left, right: separate FORK)
-- Race-free access to the forks left
and right
.
do
left.use
right.use
end
end
feature -- Access
balance: INTEGER -- Current balance in dollars.
feature -- Element change
withdraw (amount: INTEGER) -- Remove amount
dollars.
require
positive: amount > 0
not_too_big: amount <= balance
do
balance := balance - amount
ensure
increased: balance = old balance - amount
end
run
-- Execute tasks from pool
.
do
from until
not attached retrieved_task (pool) as task
loop
separate task as t do
t.call
end
end
end
class REFEREE:
race_start.publish (create {DATE_TIME}.make_now_utc)
class RACE_CONTROL:
race_start: EVENT_TYPE [DATE_TIME]
class SPRINTER:
race_start.subscribe (agent run_from_now)
run_from_now (t: DATE_TIME)
-- Record t
as starting time and get running.
do
start_time := t
run
end
Event-based programming with agents
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8