Page 1 of 1
Print list without recursive form
Posted: 3 Apr 2014 3:30
by Miguelags
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
Posted: 3 Apr 2014 6:39
by Tonton Luc
Hi,
Try to replace :
by :
in your code.
All terms at the same time
Posted: 3 Apr 2014 16:39
by Miguelags
Posted: 4 Apr 2014 14:13
by Paul Cerkez
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.
Posted: 6 Apr 2014 2:06
by Miguelags
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
Posted: 6 Apr 2014 9:28
by Thomas Linder Puls
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