The following 302 words could not be found in the dictionary of 635 words (including 635 LocalSpellingWords) and are highlighted below:

about   actually   add   additional   admittedly   akenn   Alice   alice   am   an   An   and   Andreas   Annotations   anything   anyway   application   asking   assert   Assert   assertion   Assertion   Assertions   await   aware   away   be   because   becomes   been   Bene   both   But   but   by   By   can   cannot   Cannot   carries   case   catch   changing   Common   complex   Component   consider   counter   crash   created   creates   Ctrl   currently   de   debugging   definition   Design   Developments   deviate   did   differs   documentation   does   doing   don   Editor   editor   either   enough   entry   Err   etc   evaluate   even   example   exception   Exceptional   exceptions   exchange   exit   exn   Exp   Fail   Failed   failed   failure   file   files   fn   for   forces   forever   fragile   from   fulfill   fun   future   Future   generate   gone   gray   hack   handle   happened   how   identify   idiom   Idioms   If   if   ignore   implement   implementation   implemented   import   in   incompatible   incr   information   interest   interested   interesting   internal   interpreter   ispawn   its   Januar   Joachim   Jon   Julian   just   know   Kubuntu   label   let   lib   like   line   link   lock   locks   Managers   manual   Manual   map   Max   Maybe   menu   Message   message   microsoft   migration   modify   Moving   Mozart   must   my   mysteriously   name   Name   necessary   never   Nevermind   New   new   Niehren   No   Note   now   number   occurs   of   official   One   open   opens   operator   or   origin   output   own   Oz   paper   Patterns   pdf   people   perhaps   place   possibilities   possible   precisely   preferable   pretty   probably   problems   Process   promise   Promise   promises   Promises   ps   purposes   put   raise   raised   really   Ref   ref   reference   references   research   Resolvers   respective   returned   right   running   Samples   save   sb   shortcuts   should   signatures   since   situations   sml   So   so   some   someone   something   somthing   soon   Sorry   spawn   Stacks   std   still   structure   structures   stupid   such   surely   swallowed   Syntax   t1   t2   task08   terminate   terminated   Text   Thanks   that   there   therefore   This   this   thread   threads   time   to   too   Tools   tossed   trouble   two   uncaught   uni   until   use   used   useful   Using   using   utility   val   value   version   wait   want   way   ways   we   What   what   when   whenever   Which   which   will   With   with   work   Workarounds   worth   would   written   wrong   Yes   yet   You   you   your  

Clear message

Idioms and Design Patterns

Using Promises as locks

You can use promises to lock references:

val counter = ref 1

fun incr () =
    let val p = Promise.promise ()
        val s = Ref.exchange (counter, Promise.future p)
        Promise.fulfill (p, s + 1)

val t1 = spawn incr ()
val t2 = spawn incr ()
(* wait for both threads to be terminated *)
val _  = Future.await t1 
val _  = Future.await t2
val _  = assert (!counter == 3)

- Bene

Note that this is precisely what Ref.modify does. So incr could also be implemented as

fun incr () = Ref.modify (fn i => i+1) counter

But the idiom is still useful in more complex situations.

- Andreas

Common problems and Workarounds

Cannot save anything

I feel pretty stupid asking this but I cannot save files. The menu-entry for doing so is gray. The shortcuts do not work either. I am running Alice 1.4 on Kubuntu 12.04. What am I doing wrong?

- Julian [01.07.2012] Nevermind, I have been using the interpreter and not the editor. Editor opens when you generate a new file, but not when you open Alice. Maybe worth changing if more people have trouble with that?


spawn swallowed my exception!

You have written something like this:

fun f () = raise Fail "my exception"

fun foo () =
    spawn f ();
    print "thread created"

val _ = foo ()

But mysteriously you never actually see that exception.

What happened? As you probably know spawn creates a future. This future becomes failed as soon as the exception is raised. This STOPS the exception, until someone forces the future evaluate. But in this case the future is tossed away by the ; operator and therefore the exception is gone forever.

So there are two possibilities. You must either use the value returned by the thread, or if you are just interested in the exceptions for debugging purposes (such as the Assert exception) use Ctrl.ispawn from "x-alice:/lib/utility/Ctrl":

import structure Ctrl from "x-alice:/lib/utility/Ctrl"

fun f () = raise Fail "my exception"

fun foo () =
    Ctrl.ispawn (_file_, _line_) f ();
    print "thread created"

val _ = foo ()

Which will terminate your application with a debugging message whenever an uncaught exception occurs.

- Bene

But anyway, since the utility lib is not official and may change any time it is currently preferable to use your own version of ispawn. One possible definition is:

fun ispawn label f x = 
        fun crashWith e =
            (TextIO.output (TextIO.stdErr, label ^ ": uncaught exception " ^ exnName e ^ "\n");
             OS.Process.exit OS.Process.failure)
        ignore (spawn f a handle e => crashWith e)

It is used like:

ispawn "task08_15" f ()

- Andreas

Moving from Oz to Alice


For reference documentation about how the implementation of Resolvers, Component Managers etc. in Alice differs from Mozart, see the [WWW] Alice Manual.


New Developments in ML

(Sorry, don't know if the Wiki is even the right place to put this)

-Jon S.

Thanks for the link. Yes, we are aware of that paper. It surely is interesting, but we did not consider to implement it yet, because for now, we do not want to deviate from SML in (too) incompatible ways.

- Andreas

Assertions Annotations

Is there a way to add some additional information to a failed assertion? somthing like

assert myAssertionExp onFail myAssertionFailedMessage

- Max

No, but the Assert exception carries file name and line number of the respective assertion, which should be enough to identify its origin. If really necessary, you could catch it and use this information to map it to a message, but admittedly, that would be a pretty fragile hack.

- Andreas