I don't know what you think, but prolog is probably the least logical coding language i've ever used. It makes less sense than Assembly, Scheme and a host of basic languages. The fact that error checking is almost impossible doesn't make me like it any more either.<br />With that out of the way.<br />My assignment is 7 long questions from a tic-tac-toe game, logic gates (connecting), graphs, etc... yes this is one assignment. After being out of commision with my knee for a couple weeks i'll admit i missed some lectures, but i've read the material and it does get near as complicated as he wants. Needless to say i'm running out of time to do the assignment and pissed off because i have to go to work, instead of finishing it, but here's my question anyway:<br /><br /><!--c1--><div class='codetop'>CODE</div><div class='codemain'><!--ec1--><br />/*Gates*/<br />gate(a1,and).<br />gate(a2,and).<br />gate(a3,and).<br />gate(b1,or).<br />gate(b2,or).<br />gate(b3,or).<br />gate(c1,xor).<br />gate(c2,xor).<br />gate(c3,xor).<br /><br />/*Gate Rules*/<br />and(1,1,B) :- B is 1,!.<br />and(0,1,B) :- B is 0,!.<br />and(1,0,B) :- B is 0.<br /><br />or(1,_,B)  :- B is 1,!.<br />or(_,1,B)  :- B is 1,!.<br />or(0,0,B)  :- B is 0.<br /><br />xor(1,0,B) :- B is 1,!.<br />xor(0,1,B) :- B is 1,!.<br />xor(X,X,B) :- B is 0. /*when 2 inputs match*/<br /><br />wire(InputGate,OutputGate) :-<br />    gate(InputGate,T1),  /*InputGate must exist*/<br />    gate(OutputGate,T2), /*OutputGate must exist*/<br />    wire(T1,T2,T1).<br />    <br />wire(InGate,[H,T],OutGate,Output):-<br />    and(H,T,Output).<br /><br /><!--c2--></div><!--ec2--><br />i realize i likely need another wire predicate, and that the first should not be passing T1,T2,T1, but i just needed something to see what is happening, and that it is the correct method.<br />We are supposed to be able to link gates together with outputs as inputs, implemented as a tree (i'm guessing).<br /><br />How can i use T1 and T2 as the gate parameters they really are?<br /><br />if i can get that working, linking shouldn't be too much of a problem.<br /><br />InGate is the current gate, <br />H|T are the input values<br />Outgate is the gate getting the output value(if there is one)<br />Output is the value produced in this gate...<br />perhaps i'm going about this all wrong, because i'm used to top down code/O-O programming.<br />If you see anything i'm doing wrong, or even a suggestion on how wire/gate should work together, please post!<br /><br />I just feel so stupid right now, i've never had such trouble with a coding language and had know way to tell if i'm doing it right.
</div>
</div>