Print list without recursive form

Discussions related to Visual Prolog
Miguelags
Posts: 8
Joined: 9 Jan 2014 15:06

Print list without recursive form

Unread post by Miguelags » 3 Apr 2014 3:30

Hello community VIP

I'm trying to print elements without recursive form, this is my little code in mode console

Code: Select all

implement main     open core   class predicates    print_one:(string*)determ. clauses     run():-         console::init(),         succeed(),         print_one(["frank","leonard","Tedd"]). % place your own code here :cry:           print_one([]):-!.         print_one([I1, I2, I3]):-               stdIO::write(I1), _ = stdIO::readChar(). end implement main
this code shows one error, someone could help me to solve this.

Thanks
looking for new solutions...
mi_garcias@hotmail.com

User avatar
Tonton Luc
VIP Member
Posts: 500
Joined: 16 Oct 2001 23:01

Unread post by Tonton Luc » 3 Apr 2014 6:39

Hi,

:idea:
Try to replace :

Code: Select all

print_one([I1, I2, I3]):-
by :

Code: Select all

print_one([I1|_]):-
in your code.

Miguelags
Posts: 8
Joined: 9 Jan 2014 15:06

All terms at the same time

Unread post by Miguelags » 3 Apr 2014 16:39

looking for new solutions...
mi_garcias@hotmail.com

Paul Cerkez
VIP Member
Posts: 202
Joined: 6 Mar 2000 0:01

Unread post by Paul Cerkez » 4 Apr 2014 14:13

replace

Code: Select all

 print_one([]):-!.         print_one([I1, I2, I3]):-               stdIO::write(I1), _ = stdIO::readChar().
with

Code: Select all

 print_one([]):-!.         print_one([I1|T]):-               % process first item in list               stdIO::write(I1) = stdIO::readChar(), % I don't understand what this is trying to do.  Are you trying to output a list item and then have the user enter it back in and test if they match or are you trying to pass the list item value to another predicate?               % pass the rest of the list back to this predicate.               print_one(T).  % this will allow N list entries to process.
AI Rules!
P.

Miguelags
Posts: 8
Joined: 9 Jan 2014 15:06

Unread post by Miguelags » 6 Apr 2014 2:06

Paul,

Thanks for read my post and your help.
Certainly, your prediction is correct, actually I need to send or pass four parameters, from one predicate to another (just 5 predicates, like overloading) and then return a result (phrase), depending of the parameters sent (as a parameter list).

Because this, I need to pass the parameters and use all them at the same time, and no recursively.

I need one example with these characteristics.

Thanks,
I appreciate your help, or any solution.

Miguel
looking for new solutions...
mi_garcias@hotmail.com

User avatar
Thomas Linder Puls
VIP Member
Posts: 1622
Joined: 28 Feb 2000 0:01

Unread post by Thomas Linder Puls » 6 Apr 2014 9:28

The problem with your code is that you only handle lists of certain lengths: empty and with three elements. But your code must handle all lists to be a procedure.

Code: Select all

clauses     print_one([I1, I2, I3]) :-         !, % lists of length 3         ... % do something       print_one(L) :-         % lists of other lengths         ... % optionally do something
Regards Thomas Linder Puls
PDC

Post Reply