poole@CPSC-M-POOLE01 prolog % swipl Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit https://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- [lists]. true. ?- list([1,2,a,b,[5,6]]). true. ?- list(X). X = [] ; X = [_] ; X = [_, _] ; X = [_, _, _] ; X = [_, _, _, _] ; X = [_, _, _, _, _] . ?- list([1,2|X]). X = [] ; X = [_] ; X = [_, _] ; X = [_, _, _] ; X = [_, _, _, _] . ?- member(val(b,V),[val(aa,3), val(b,7), val(dd,23)]). V = 7 . ?- append([1,2,3],[a,b,c],R). R = [1, 2, 3, a, b, c]. ?- append(L1, L2, [a,b,c]). L1 = [], L2 = [a, b, c] ; L1 = [a], L2 = [b, c] ; L1 = [a, b], L2 = [c] ; L1 = [a, b, c], L2 = [] ; false. ?- append(Before, [jul|After], [jan,feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]). Before = [jan, feb, mar, apr, may, jun], After = [aug, sep, oct, nov, dec] ; false. ?- append(_, [M1,jul,M2|_], [jan,feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]). M1 = jun, M2 = aug . ?- append(_,[X|_],[jan,feb, mar, apr, may, jun, jul, aug, sep, oct, nov, dec]). X = jan ; X = feb ; X = mar ; X = apr ; X = may . ?- append([1,2,3],X,Y). Y = [1, 2, 3|X]. ?- nume(2,[1,2,3,2,1],N). N = 0+1+1 . ?- sum([2,3,4,5],S). S = 14. ?- sum([2,3,X,5],14). ERROR: Arguments are not sufficiently instantiated ERROR: In: ERROR: [13] _144 is _150+5 ERROR: [11] sum([3,_188|...],_178) at /Users/poole/World/cs312/2024/prolog/lists.pl:61 ERROR: [10] sum([2,3|...],14) at /Users/poole/World/cs312/2024/prolog/lists.pl:61 ERROR: [9] toplevel_call(user:user: ...) at /opt/local/lib/swipl/boot/toplevel.pl:1173 ERROR: ERROR: Note: some frames are missing due to last-call optimization. ERROR: Re-run your program in debug mode (:- debug.) to get more detail. ?- suma([2,3,4,5],S). S = 14. ?- [lists]. true. ?- rev3([1,2,3,4],[a,b],R). R = [4, 3, 2, 1, a, b]. ?- rev3([a,b,c],X,Y). Y = [c, b, a|X]. ?- Y=[a,b,c,c,b,a|X], X=[7,8]. Y = [a, b, c, c, b, a, 7, 8], X = [7, 8]. ?- [bstree]. true. ?- val(1,V, bnode(2,b, bnode(1,a,empty,empty), bnode(5,e,empty,empty))). V = a . ?- val(4,V, bnode(2,b, bnode(1,a,empty,empty), bnode(5,e,empty,empty))). false. ?- val(V,e,bnode(2,b, bnode(1,a,empty,empty), bnode(5,e,empty,empty))). ERROR: Arguments are not sufficiently instantiated ERROR: In: ERROR: [11] _28492<2 ERROR: [10] val(_28518,e,bnode(2,b,bnode(1,a,empty,empty),bnode(5,e,empty,empty))) at /Users/poole/World/cs312/2024/prolog/bstree.pl:11 ERROR: [9] toplevel_call(user:user: ...) at /opt/local/lib/swipl/boot/toplevel.pl:1173 Exception: (10) val(_27558, e, bnode(2, b, bnode(1, a, empty, empty), bnode(5, e, empty, empty))) ? creep ?- val(a,7,T). T = bnode(a, 7, _, _) Unknown action: (h for help) Action? Unknown action: [ (h for help) Action? Unknown action: A (h for help) Action? . ?- val(7,h,T),val(3,g,T). T = bnode(7, h, bnode(3, g, _, _), _) . ?- val(4,d,T), val(1,a,T). T = bnode(4, d, bnode(1, a, _, _), _) . ?- val(1,a,T), val(4,d,T). T = bnode(1, a, _, bnode(4, d, _, _)) . ?- val(4,d,T), val(1,a,T), val(2,b,T), val(1,V,T). T = bnode(4, d, bnode(1, a, _, bnode(2, b, _, _)), _), V = a . ?- val(4,d,T), val(1,a,T). T = bnode(4, d, bnode(1, a, _, _), _) ; ERROR: Arguments are not sufficiently instantiated ERROR: In: ERROR: [13] 1<_21398 ERROR: [12] val(1,a,bnode(_21430,_21432,_21434,_21436)) at /Users/poole/World/cs312/2024/prolog/bstree.pl:11 ERROR: [11] val(1,a,bnode(4,d,bnode(_21478,_21480,_21482,_21484),_21474)) at /Users/poole/World/cs312/2024/prolog/bstree.pl:12 ERROR: [10] ''(user:user: ...) ERROR: [9] toplevel_call(user:user: ...) at /opt/local/lib/swipl/boot/toplevel.pl:1173 Exception: (12) val(1, a, _19488) ? creep Exception: (11) val(1, a, bnode(4, d, _19488, _19490)) ? abort % Execution Aborted ?- [bstreec]. Warning: /Users/poole/World/cs312/2024/prolog/bstreec.pl:11: Warning: Redefined static procedure val/3 Warning: Previously defined at /Users/poole/World/cs312/2024/prolog/bstree.pl:9 Warning: /Users/poole/World/cs312/2024/prolog/bstreec.pl:26: Warning: Redefined static procedure insert/4 Warning: Previously defined at /Users/poole/World/cs312/2024/prolog/bstree.pl:22 true. ?- ^D % halt poole@CPSC-M-POOLE01 prolog % swipl Welcome to SWI-Prolog (threaded, 64 bits, version 9.0.4) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit https://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- [bstreec]. true. ?- val(4,d,T), val(1,a,T). T = bnode(4, d, bnode(1, a, _, _), _) ; T = bnode(4, d, bnode(_A, _, bnode(1, a, _, _), _), _), _A in 2..sup . ?- val(K,V,bnode(2,22, bnode(1,57,empty,empty), bnode(5,105,empty,empty))). K = 2, V = 22 ; K = 1, V = 57 ; K = 5, V = 105 ; false. ?-