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
Oz (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!
=== Laziness === Oz uses [[eager evaluation]] by default, but [[lazy evaluation]]<ref name="Lazy Programming"> {{cite journal | author = Paul Hudak | author-link = Paul Hudak | title = Conception, evolution, and application of functional programming languages | journal = ACM Computing Surveys | year = 1989 | volume = 21 | number = 3 | pages = 359β411 | doi=10.1145/72551.72554| s2cid = 207637854 }} </ref> is possible. Below, the fact is only computed when value of X is needed to compute the value of Y. <syntaxhighlight lang="erlang"> fun lazy {Fact N} if N =< 0 then 1 else N*{Fact N-1} end end local X Y in X = {Fact 100} Y = X + 1 end </syntaxhighlight> [[Lazy evaluation]] gives the possibility of storing truly infinite data structures in Oz. The power of lazy evaluation can be seen from the following code sample: <syntaxhighlight lang="erlang"> declare fun lazy {Merge Xs Ys} case Xs#Ys of (X|Xr)#(Y|Yr) then if X < Y then X|{Merge Xr Ys} elseif X>Y then Y|{Merge Xs Yr} else X|{Merge Xr Yr} end end end fun lazy {Times N Xs} case Xs of nil then nil [] X|Xr then N*X|{Times N Xr} end end declare H H = 1 | {Merge {Times 2 H} {Merge {Times 3 H} {Times 5 H}}} {Browse {List.take H 6}} </syntaxhighlight> The code above elegantly computes all the [[Regular Number]]s<ref name="Hamming Numbers"> {{cite journal |author1=Rao, AC |author2=Varada Raju, D |name-list-style=amp | title = Application of the Hamming number technique to detect isomorphism among kinematic chains and inversions | journal = Mechanism and Machine Theory | volume = 26 | number = 1 | pages = 55β75 | year = 1991 | doi=10.1016/0094-114x(91)90022-v}} </ref> in an infinite list. The actual numbers are computed only when they are needed.
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)