Home > Archive > Prolog > April 2007 > beginner
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]
|
|
| lovelove 2007-04-10, 4:03 am |
| is there any one tell me how to contruct a list in prolog
like i have a list
[[1,3],[4,5],[6,7]]
i want to make one list of [1,4,6]
and other list of [3,5,7]
and i have write a code below so if i putting a write(O) after [O|
_]=H, it is showing just 146 i want this to be in a list
devide(Kn):-
[H|T]=Kn,
[O|_]=H,
devide(T).
| |
| bart demoen 2007-04-10, 7:04 pm |
| On Mon, 09 Apr 2007 21:25:40 -0700, lovelove wrote:
> is there any one tell me how to contruct a list in prolog
>
>
> like i have a list
>
> [[1,3],[4,5],[6,7]]
>
>
> i want to make one list of [1,4,6]
>
> and other list of [3,5,7]
>
> and i have write a code below so if i putting a write(O) after [O|
> _]=H, it is showing just 146 i want this to be in a list
> devide(Kn):-
> [H|T]=Kn,
> [O|_]=H,
> devide(T).
give devide an extra output argument that you unify with the list you want
to construct
cheers
bd
| |
| lovelove 2007-04-10, 7:04 pm |
| On Apr 10, 10:54 am, bart demoen <b...@cs.kuleuven.be> wrote:
> On Mon, 09 Apr 2007 21:25:40 -0700, lovelove wrote:
>
>
>
>
>
>
> give devide an extra output argument that you unify with the list you want
> to construct
>
> cheers
>
> bd- Hide quoted text -
>
> - Show quoted text -
I have tried
list(List,AN) :-
[H|T]=List,
[A|_]=H,
list(T).
but not working too..
Please help
| |
| lovelove 2007-04-10, 7:04 pm |
| On Apr 10, 10:54 am, bart demoen <b...@cs.kuleuven.be> wrote:
> On Mon, 09 Apr 2007 21:25:40 -0700, lovelove wrote:
>
>
>
>
>
>
> give devide an extra output argument that you unify with the list you want
> to construct
>
> cheers
>
> bd- Hide quoted text -
>
> - Show quoted text -
sorry i didnt understand
| |
| bart demoen 2007-04-10, 7:04 pm |
| On Tue, 10 Apr 2007 13:31:11 -0700, lovelove wrote:
[color=darkred]
>
>
> I have tried
> list(List,AN) :-
>
> [H|T]=List,
> [A|_]=H,
> list(T).
>
> but not working too..
In the body of the clause, you should unify the output AN with the thing
you want it to become equal to. Usually, in the body you can just specify
one more element of the output argument, and the recursive call then
specifies the tail of the output list.
Here is an example, silly but it should teach you something:
in2out([],[]).
in2out(In,Out) :-
In = [X,_|RestIn],
Out = [X|RestOut],
in2out(RestIn,RestOut).
try ?- in2out([1,2,3,4],Out).
Cheers
Bart Demoen
| |
| lovelove 2007-04-10, 10:02 pm |
| On Apr 10, 12:55 pm, bart demoen <b...@cs.kuleuven.be> wrote:
> On Tue, 10 Apr 2007 13:31:11 -0700, lovelove wrote:
>
>
>
>
> In the body of the clause, you should unify the output AN with the thing
> you want it to become equal to. Usually, in the body you can just specify
> one more element of the output argument, and the recursive call then
> specifies the tail of the output list.
> Here is an example, silly but it should teach you something:
>
> in2out([],[]).
> in2out(In,Out) :-
> In = [X,_|RestIn],
> Out = [X|RestOut],
> in2out(RestIn,RestOut).
>
> try ?- in2out([1,2,3,4],Out).
>
> Cheers
>
> Bart Demoen
I have input list as ([[1,2],[3,4],[5,6]],Out) it is not [1,2,3,4]
so it cant work in that.and i want output as [1,3,5]
thnx
please help
| |
| Reuben Grinberg 2007-04-11, 4:04 am |
| lovelove wrote:
> On Apr 10, 12:55 pm, bart demoen <b...@cs.kuleuven.be> wrote:
>
> I have input list as ([[1,2],[3,4],[5,6]],Out) it is not [1,2,3,4]
> so it cant work in that.and i want output as [1,3,5]
>
> thnx
> please help
>
>
>
Something that may help you here is specifying In and Out more:
For example:
someFunction(In,Out) :-
In = [ [First|Second] | RestIn ]
....
In this case, In is expected to be a list of lists, which will work with
[[1,2], [3,4], ...]
Does that make things more clear?
| |
| Bart Demoen 2007-04-11, 7:04 pm |
| lovelove wrote:
>
>
> I have input list as ([[1,2],[3,4],[5,6]],Out) it is not [1,2,3,4]
> so it cant work in that.and i want output as [1,3,5]
My example wasn't supposed to solve your problem, it was supposed to
teach you something, something like teaching you to fish instead of
giving you a fish. Don't try to turn it into a fish :-)
Have you tried the query I suggested ?
Have you seen how parts of the input appear in the output ?
....
Cheers
Bart Demoen
| |
|
|
|
|
|