[mercury-users] Newbie problem. :)

Rob zharradan at suffering.org
Sat Jun 12 20:38:44 AEST 1999


Rob wrote:

I fixed it. Yay. heh.
I'm sure all of you picked up the error straight away, but this is the
first non "hello world" code I have done in Mercury. :)

> my_insert(X, Y, Z) :-
>         (
>             Y = [Hd | Tl],
>             (
>                 X =< Hd,                  <-- Line 40
>                 Z = [X | [Hd | Tl]]
>             ;
>                 X > Hd,
>                 my_insert(X, Tl, W),
>                 Z = [Hd | W]
>             )
>         ;
>             Y = [],
>             Z = [X]
>         ).


I chanded this switch into an if-then-else, (actually, I made it a
Condition -> TrueCase ; FalseCase) and all was fine. Makes sense,
really. I want something more like exclusive-or as opposed to straight
logical or.
I was thinking "do this, OR do that" forgetting that I dealing with
logic here. Aah well. Best way to learn, I guess. :)

In any case, Rob's Dodgy Insertion Sort(tm) now works on lists of
integers. Beware! heh.
I also did something to calculate the factors of an integer.. This is
actually rather easy to pick up.

Today first-year programming, tomorrow the world!

rob
--------------------------------------------------------------------------
mercury-users mailing list
post:  mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the users mailing list