Feb 3, 2008 #1 nn987 Programmer Feb 4, 2006 37 GB how to proced with the empty lists in this case? %Multiply elements of one list multLista([],1). multLista([E|T],R):-multLista(T,Multiplica),R is Multiplica*E. ~ ex: multLista([1,2,3,4],R). R=24 multLista([],1). R= 1 !!!! Thanks
how to proced with the empty lists in this case? %Multiply elements of one list multLista([],1). multLista([E|T],R):-multLista(T,Multiplica),R is Multiplica*E. ~ ex: multLista([1,2,3,4],R). R=24 multLista([],1). R= 1 !!!! Thanks
Feb 5, 2008 #2 4tangent MIS Feb 5, 2008 4 Hi there Which type of prolog are you using? Regards John Upvote 0 Downvote
Feb 6, 2008 Thread starter #3 nn987 Programmer Feb 4, 2006 37 GB I use this version of prolog SWI-Prolog version 5.4.7 by Jan Wielemaker (jan@swi-prolog.org) Upvote 0 Downvote
Feb 9, 2008 #4 4tangent MIS Feb 5, 2008 4 OK thank you.I don't see what your problem is ; perhaps I am missing something. You have a fact that says multLista([],1). then you ask multLista([],R) ? and it says R = 1. Why is that a surprise? Regards John Upvote 0 Downvote
OK thank you.I don't see what your problem is ; perhaps I am missing something. You have a fact that says multLista([],1). then you ask multLista([],R) ? and it says R = 1. Why is that a surprise? Regards John
May 23, 2008 #5 MstrOfPppts Programmer May 23, 2008 4 SI Maybe you wish to say that: % multLista of empty list is 0 multLista([],0). But than you have to add another edge case so your recursion would work: multLista([A],A). Upvote 0 Downvote
Maybe you wish to say that: % multLista of empty list is 0 multLista([],0). But than you have to add another edge case so your recursion would work: multLista([A],A).