Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
Eiffel (programming language)
(section)
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
===Once routines=== A routine's result can be cached using the <code>once</code> keyword in place of <code>do</code>. Non-first calls to a routine require no additional computation or resource allocation, but simply return a previously computed result. A common pattern for "once functions" is to provide shared objects; the first call will create the object, subsequent ones will return the reference to that object. The typical scheme is: <syntaxhighlight lang="eiffel"> shared_object: SOME_TYPE once create Result.make (args) -- This creates the object and returns a reference to it through `Result'. end </syntaxhighlight> The returned object—<code>Result</code> in the example—can itself be mutable, but its reference remains the same. Often "once routines" perform a required initialization: multiple calls to a library can include a call to the initialization procedure, but only the first such call will perform the required actions. Using this pattern initialization can be decentralized, avoiding the need for a special initialization module. "Once routines" are similar in purpose and effect to the [[singleton pattern]] in many programming languages, and to the [[b:Computer Science Design Patterns/Singleton#Python|Borg pattern]] used in Python. By default, a "once routine" is called ''once per thread''. The semantics can be adjusted to ''once per process'' or ''once per object'' by qualifying it with a "once key", e.g. <code>once ("PROCESS")</code>.
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)