Also, Miranda is automatically curried. If + took 2 or 3
arguments and we passed it 2, how would we know that we didn't still
want to pass it one more?
Disadvantage: Reference counting adds a constant factor to the
runtime of memory operations (Note: circular data structures are not
a problem because circular data structures can not be created in a
purely functional language).
What are the results of the following. If there are errors say so.
A disadvantage would be that many program errors what would have been
caught by the compiler at compile time would now not be detected until
runtime when that piece of code is executed. Debugging would me more
difficult.
Miranda has no side-effects. Thus, performing operations that do not
yield a result is pointless.
Miranda is staticly typed. An object passed to a function can only be
of one type. Thus, you can not define a function that chooses which
of two other functions to call based on the type of the argument.
Miranda is statically typed and the type of a function includes how
many arguments it takes. What would the type of + be if +
took 2 or 3 arguments?
Miranda is lazy.
C++ Scheme Miranda Java CLP(Â)
parameter passing
value , reference value lazy value constraint
side-effects
yes yes no yes skip
type-safe
no yes yes yes yes
garbage collected
no yes yes yes yes
typed
static dynamic static static , dynamic dynamic
scoping
static static static static none
Advantage: Reference counting is incremental (it does not stop
the program to collect garbage).
CLP(Â) is sound but not complete.
palindrome(List) :- reverse(List,List).
In a lazy evaluated language, expressions are evaluated when their
results are needed. Typically, side-effect expressions do not produce
results, but even if they did, orchestrating the need of the
result of a side-effect operation to get the output in the correct order
is difficult. There is also the issue of memoization. If expression
values are memoized (which is typically done in lazy languages) then a
its output would only happen once even if the function was called twice.
(define x 10)
(define y (+ x 10)) ;; (+ x 10) not evaluated until 'y' needed.
(set! x 100)
y ;; now x + 10 evaluates to 110.
anyone(1,_,_).
anyone(_,1,_).
anyone(_,_,1).
What are the results of evaluating (include retry behavior):
1 ?- anyone(0,0,0).
*** No
2 ?- anyone(1,1,0).
*** Retry? y
*** Retry? y
*** No
3 ?- anyone(X,Y,0), X + Y = 0, Y < 0.
Y = -1
X = 1
*** Retry? y
*** No
mystery = 0 : 1 : map2 (+) mystery (tl mystery)
The infinite list of Fibonacci numbers: [0,1,1,2,3,5,8,...].
None.
You can't implement an array with a side-effect free set
operation that runs in O(1) time (Note that it is possible to
implement a persistent array with slower set operation).
An abstract class cannot be instantiated. No class implementing
III that does not implement the fff method should be able to be
instantiated. Java forces this by requiring that XXX be
declared abstract.
It is ok because no code is inherited by implementing an interface.
The class will implement the particular method itself and this one
implementation will fulfill both interface requirements.
append3 a b c = a ++ b ++ c
bar a b c = a:b:c
my_const y x = x
my_map f [] = []
my_map f (a:as) = f a : my_map f as
begin
integer i;
array a[1..2] of integer;
procedure fly(j,k: integer);
begin
print(i,j);
j = 0;
k = 2;
print(i,j);
end
a[1] := 10;
a[2] := 20;
i := 1;
fly(a[i],i);
print(a);
end;
What is the result when arguments are passed
1 10
1 0
10 20
1 10
2 20
0 20
1 10
2 0
0 20
clpr
Check if we're in heaven.
What do you believe CLP(Â) does on the goal clpr?
1 ?- clpr.
*** Yes