On Thu, 31 Jul 2008 14:46:59 +0200, Andreas Rossberg
<[EMAIL PROTECTED]> wrote:
>Benjamin L. Russell wrote:
>> Unfortunately, when I actually typed
>>
>>
>>> val rec fibs = 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs)))
>>>
>>
>> into Alice, this is what happened:
>>
>>> 1.15-1.63: recursive declaration's right-hand side is not a value
>>>
>
>Indeed, thanks for pointing this out. We restricted the definition of
>value expressions at some point (IIRC, because there were problems with
>the jitter). Apparently, we forgot to adapt some parts of the manual. I
>entered a bug report.
I see. Thank you for entering the bug report.
>You can work around this limitation by using the (much more general)
>mechanism of promises:
>
>- open Promise;
>[...]
>- val p = promise ();
>val p : '1 promise = promise{|_future|}
>- val fibs = future p;
>val fibs : '2 = _future
>- fulfill (p, 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs))));
>val it : unit = ()
>- fibs;
>val it : int list = 1 :: 1 :: _lazy
>
>If you need recursive constructions like that more often you could write
>a simple fixpoint combinator:
>
>- fun fix f =
> let val p = promise ()
> val x = future p
> in
> fulfill (p, f x); x
> end;
>val fix : ('a -> 'a) -> 'a = _fn
>- fix (fn fibs => 1 :: 1 :: (lazy mapz op+ (zipz (fibs, tl fibs))));
>val it : int list = 1 :: 1 :: _lazy
>
>See the manual page on futures or
>http://www.ps.uni-sb.de/alice/manual/library/promise.html for
>documentation of the Promise structure.
Unfortunately, I'm still a beginner, and at this point, it would
probably require quite a detour from the manual to cover promises and
fixpoint combinators before at least finishing Alice Manual - A Tour
to Wonderland. I have never programmed in any dialect of ML before,
and am more familiar with Scheme, and to a much lesser extent,
Haskell. Usually, I try to cover the introductory tutorial before
jumping up to higher ground, lest I get caught up in something very
subtle and intricate assuming background knowledge of something else
not already covered.
Is it possible for somebody on the development or documentation team
to fix the introductory tutorial, and to post an updated version
sometime when they have enough time to finish it, before I proceed
further? I am willing to wait if necessary. At this point, I am
afraid to proceed further with the tutorial, because I forsee similar,
and perhaps more subtle, problems further down the road. For example,
if the documentation on promises and fixpoint combinators is similarly
outdated, and overcoming that problem then requires further knowledge
of something else that I don't know, then I could forsee getting stuck
in a tar pit.
>> Also, I discovered the following bug in the manual:
>>
>>> We can define a lazy variant of the map function:
>>>
>>> fun mapz f xs = lazy (case xs of nil => nil
>>> | x::xs' => f x :: mapz f xs')
>>> val mapz : ('a -> 'b) -> 'a list -> 'b list = _fn
>>>
>>
>> Unfortunately, when I actually typed the above definition of mapz into
>> Alice, Alice returned an error message, as follows:
>>
>>> 2.40-2.40: syntax error found at DARROW
>>>
>
>Mh, that works fine for me. Are you sure you pasted the code correctly?
>(The ticks shouldn't be a problem.)
Ah, I just discovered the cause of the problem: When I manually typed
the code into the Interpreter, I forgot to insert the guard ('|')
symbol on the second line. It works now. Sorry about the code typo.
-- Benjamin L. Russell
_______________________________________________
alice-users mailing list
[email protected]
http://www.ps.uni-sb.de/mailman/listinfo/alice-users