For Programmers: Free Programming Magazines  


Home > Archive > Prolog > July 2004 > Re: Little problem please help









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 Re: Little problem please help
Nick Wedd

2004-07-02, 8:56 pm

In message <35b3fce2.0407020015.48324b75@posting.google.com>, Magellan
<magellano@poczta.fm> writes
>Nick Wedd <nick@maproom.co.uk> wrote in message news:<GUAktEK4$+4AFALD@
>maproom.demon.co.uk>...
>
>
>Ahhh
>I tried to do it just like you said, but I can't handle with it.
>I wrote something like this:
>
>set_length([],0).
>set_length([_|O],L):-set_length(O,L1),L is L1+1.
>
>sum([],0).
>sum([G|O],L):-sum(O,L1),L is L1+G.


I wish people wouldn't use O as a variable. It looks to me very like 0.
But that's not your fault, the problem is with my eyes, or with my font
settings.

>
>del(X,[X|T],T).
>del(X,[H|T],[H|NT]):-del(X,T,NT).
>
>sublist([],X).


All looks good so far.

>
>sublist(del(X,T,NT),[H|T],X):-member(H,X), sublist(T,X),del(X,T,NT).


This must be wrong. The other clause for sublist had two arguments,
this one has three. And the first argument to sublist/3 is del(X,T,NT).
This is not going to cause a call to del/3.

Try
sublist( [H|T], X ) :-
del( H, X, NX ),
sublist( T, NX ).
I don't guarantee this will work, it is late.

>valid_sublist( L, S ) :-
> sublist( L, S ),
> set_length( S, Set_length ),
> Set_length < 4,

^
typo
> sum( S, Sum),
> Sum < 10.
>
>I think that i did something wrong with sublist:
>sublist([H|T],X):-member(H,X), sublist(T,X), and I now that somewhere
>here I must put 'del'.
>
>Please help me, it's almost the end of the work with it, but I can't
>do this by myself.


Nick
--
Nick Wedd nick@maproom.co.uk
Sponsored Links







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

Copyright 2008 codecomments.com