For Programmers: Free Programming Magazines  


Home > Archive > Prolog > May 2004 > where is the error? lists









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author where is the error? lists
Neil

2004-05-04, 2:59 pm

Hi ....when trying to solve this problem, it produces error.
add_order([0,2,4,7,9],[1,3,5,8,10],L)?
expected output is [0,1,2,3,4,5,7,8,10]

______________________

add_order([H1|T1],[H2|T2],[H1|T3]):-
H1 =< H2,!,
append([H2],T2,L2),
add_order(T1,L2,T3).

add_order([H1|T1],[H2|T2],[H2|T3]):-
H1 >= H2,!,
append([H1],T1,L1),
add_order(L1,T2,T3).

add_order([],L,L):-!.

add_order(L,[],L).

% example:
:-
add_order([0,2,4,7,9],[1,3,5,8,10],L)?

The expected output is [0,1,2,3,4,5,7,8,10]

But it just outputs **no.


What is wrong in the code? Thanks.

Regards,
Neil


Pento

2004-05-04, 2:59 pm

"Neil" <neilyork82@yahoo.com> wrote in news:c787lo$57p$1@news.epidc.co.kr:

> The expected output is [0,1,2,3,4,5,7,8,10]
>
> But it just outputs **no.


SWI prolog doesn't :

?- add_order([0,2,4,7,9],[1,3,5,8,10],L).

L = [0, 1, 2, 3, 4, 5, 7, 8, 9, 10] ;

No

--
Pento

De wereld was soep, en het denken meestal een vork,
tot smakelijk eten leidde dat zelden. - H. Mulisch
Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com