[clean-list] variable sharing between expressions,
gui app prints 42 at the end, rem/mod inconsistency
Peter Hercek
peter at syncad.com
Sun Jun 18 22:46:05 MEST 2006
Hi all,
A few questions from a beginner :)
Clean language report says that "when a variable occurs more than once
in a function body, the semantics prescribe that the actual argument is
shared". So I expected the fib sequence below to have linear (and not
exponential) complexity.
(>>>) infix 0 :: a !b -> a |toString b
(>>>) val msg = trace_n msg val
take_ul :: !Int [#.a] -> [#.a] | UList a
take_ul 1 [# h : t ] = [# h ]
take_ul n [# h : t ] = [# h : take_ul (n-1) t ]
fib = [# 1, 1 : [# a+b >>> a+b \\ a <|- fib & b <|- tail_ul fib ] ]
where
tail_ul [# _ : t ] = t
Start = take_ul 4 fib
But it does not seem that the fib sequence is being shared between right
hand side and left hand side since the computation of the third element
is being done 2 times as the trace output indicates. Can somebody help
me out what I'm missing?
Second problem is that a very simple dialog application is printing 42
at the end (after I confirm the dialog) and waits for keyboard input
before exiting. How to get rid of this 42 and keyboard input?
% cat hello.icl
module hello
import StdEnv, StdIO
Start world =
startIO NDI Void (open_dialog) [ProcessClose closeProcess] world
where
open_dialog pSt
# (okId,pSt) = openId pSt
= snd (openDialog undef (dialog okId) pSt)
dialog okId = Dialog "Hello Dialog"
( TextControl "Hello World, I am a Clean user!" [] :+:
ButtonControl "OK" [ ControlId okId,
ControlFunction quit ]
) [ WindowOk okId ]
quit (ls,pSt) = (ls,closeProcess pSt)
% ./hello.exe
42
%
I'm trying Windows Clean 2.1.1.
And the last one. Is Sparkle and Std environment supposed to be the
same? I though it should but Sparkle defines both rem and mod operators
but Std defines only rem. Also what is the difference between mod and rem?
Peter.
More information about the clean-list
mailing list