Sunteți pe pagina 1din 21

Elliot Ricca, Vivian Tat, Jose Lascano,

Javier Sanchez
History of Oz
Created by Gert Smolka, Peter
Van Roy, and Seifi Haridi from
1991-1996
Universite Catholique de Louvain
Swedish Institute of Computer Science
Designed as High-Level,
Multi-Paradigm Language
-Functional
-Object-Oriented
-Logical/Relational
-Concurrent
-Imperative
-Constraint
-Distributed
Programming environment funded by Mozart Consortium, Oz is commonly referred as Mozart Oz
Ja
Ja
Main Program itself written to send
inputs to a Function and receive
outputs like a mathematical function.
Functions are defined by using other
functions and so on and so on much
like Lisp, C++
Support for Lambda functions.
Also, Procedures are supported.
%Returns square of X
fun {Square X}
X*X
end
%Same but Lambda function
Square = fun {$ X} X*X end
Functional Programming
Ja
Support for Object Classes and
Instances, much like Java, Scala
Object fields can only be accessed by
Object methods, good for data hiding
and secure data handling
Support for Inheritance and Mixing
with other Paradigms such as
Logical/Relational and Concurrent
class Counter
attr val
meth init(Val<=0)
val <- Val
end
meth inc(Val<=1)
val <- @val + Val
end

meth browse
{Inspect @val}
end
end
O = {New Counter init}
{O incr} {O incr(3)}
{O browse}
% prints 4 in Inspector
Object-Oriented
Ja
Multiple results can come from a call to
a piece of code; zero, one, two, or
more results can arrise. Oz is a popular
Logical language used in AI.
i.e. All Solutions to a problem
Just like Prolog in the sense that it
continues evaluating outputs based on
database of facts and rules.
Can declare databases and rules using
Ozs Procedures
proc {Happy X}
{Man X}
{Whistles X}
end
proc {Man X}
choice
X = paul
[] X = john
end
end
proc {Whistles X}
choice
X = mary
[] X = john
end
end
{Inspect {Search.base.one Happy}}
% [john]
Logical/Relational
Ja
Concurrent programming is a
paradigm where code is designed to
run in parallel
Found in many languages, used often
in Oz
Threads are instantiated and
evaluated
Allocated resources of memory and
processing time
thread
Z = X+Y % thread suspends until both X and Y are bound to a value
{Browse Z} % shows the value of Z.
end
thread X = 40 end %thread variables are being bound
thread Y = 2 end %both variables bound, program thread continues
Concurrency
Ja
Data Types
Jo
Data type is
automatically detected
by the Oz compiler. No
need to say int, string,
float, etc
Print/Show
Jo
Print/Browse
Jo
Hello World
{Show Hello World} {Show Hello World}
Output: Hello World Output: [72 101 108 108 111 32 87 111 114 108 100]
the string itself a list of ascii values of the given string
E
Strings are declared in single quotes
Declaring Variables
Local Variables
Global Variables
E
Declaring Variables cont.
local X Y Z in declare X Y Z
X = 5 X = 5 X = 5
Y = 10 Y = 10 Y = 10
Z = X + Y Z = X + Y Z = X + Y
{Show Z} {Show Z} {Show Z}
end
Output:15 Output: 15 Output: variable not
introduced error
Dynamically typed
Variables cannot be manipulated once bound
Cannot mix data types, trying to add an int and a float will give an error
E
If Statement
Jo
Procedures & Functions
local Add X Y Z in local Add X Y in
proc {Add X Y Z} fun {Add X Y}
Z = X + Y X + Y
end end
{Add 5 10 Z} {Show {Add 5 10}}
{Show Z} end
end
Output: 15 Output: 15
E
Mapping (Lisp similarity)
Similar to Mapcar in Lisp, Map takes every element of a list one at a time and applies the given
function to every element and returns a new list of values based on that function
local Sq X List in
fun {Sq X}
X * X
end
List = [1 2 3 4 5 6 7 8 9 10]
{Show {Map List Sq}}
end
Output: [1 4 9 16 25 36 49 64 81 100]
V
Compiler
Implemented using the Mozart Programming System through an Emacs
interface
Feed the code to Mozart and it is executed in the Oz Emulator
Entire code
Specified region
Single line
Paragraph
V
Difficulties in Oz
-Loops
Doable but hard to control
-User input
The only way to get input from the user is through file IO.as far as we
know. There is a way, but it does not show it within the documentation
-List Operations
Theres no way to manipulate a single element in a list, such as RPLACA in
lisp, you would have to find out which element you need to manipulate and
then create a whole new list. This is because of the fact that you cant change
variables once they have already been initialized.
-Tuples
Tuples have more capabilities than lists and are more prefered to be used,
but are also much harder to use for the average programmer
V
Pros
- Brings together many programming
paradigms
- Objected oriented features similar
to Java and C++
- Effective concurrent language
Cons
- Slow compiler
- Difficult to pick up
- Relatively new language with little
documentation
- Difficult to take input from user
Pros and Cons
V
Demo - Integration Method
Based on Trapezoidal Riemann Sums
integration technique learned in all
Calculus courses.
Approximation accurate to a couple
decimal place, more steps -> better
accuracy.
Example of a nice Functional feature
called Higher Order Programming in
Oz, aka Passing in Functions as
parameters much like LISP
Ja
Example Output
Ja

S-ar putea să vă placă și