Last login: Sun Nov 24 19:55:55 on ttys001 The default interactive shell is now zsh. To update your account to use zsh, please run `chsh -s /bin/zsh`. For more details, please visit https://support.apple.com/kb/HT208050. mba:List processing code johnz$ swipl Welcome to SWI-Prolog (threaded, 64 bits, version 8.0.3) SWI-Prolog comes with ABSOLUTELY NO WARRANTY. This is free software. Please run ?- license. for legal details. For online help and background, visit http://www.swi-prolog.org For built-in help, use ?- help(Topic). or ?- apropos(Word). ?- consult('lp.pro'). true. ?- first([1,2,3],H). H = 1. ?- rest([1,2,3],T). false. ?- consult('lp.pro'). true. ?- first([1,2,3],H). H = 1. ?- rest([1,2,3],T). T = [2, 3]. ?- last_element([1,2,3],Result). Result = 3 . ?- write_list([a,b,c]). a b c true. ?- write_list_reverse([a,b,c]). Correct to: "write_list_reversed([a,b,c])"? Please answer 'y' or 'n'? yes c b a true. ?- size([one,two,three],S). S = 3. ?- | size([one,two,three],S). S = 3. ?- count(a,[a,b,c,a,b],Count). Count = 2 . ?- count(a,[a,a,a,b],Count). Count = 3 . ?- element_of(a,[a,b,c]). true . ?- element_of(a,[b,c]). false. ?- contains([a,b,c],a). true . ?- contains([b,c],a). false. ?- nth(1,[a,b,c],E). E = b . ?- nth(0,[a,b,c],E). E = a . ?- pick([a,b,c],a). false. ?- pick([a,b,c],Item). Item = c . ?- pick([a,b,c],Item). Item = b . ?- pick([a,b,c],Item). Item = c . ?- sum([1,2,3],Sum). Sum = 6. ?- sum([1,9],Sum). Sum = 10. ?- make_list(4,a,[b,c,d]). false. ?- make_list(4,a,b). false. ?- make_list(4,a,[]). false. ?- make_list(1,a,A). A = [a] . ?- make_list(4,a,List). List = [a, a, a, a] . ?- iota(10,Iota). Iota = [1, 2, 3, 4, 5, 6, 7, 8, 9|...] . ?- iota(9,Iota). Iota = [1, 2, 3, 4, 5, 6, 7, 8, 9] . ?- add_first(a,L,A). A = [a|L]. ?- add_first(a,[b,c],A). A = [a, b, c]. ?- add_last(a,[b,c,d],List). List = [b, c, d, a] . ?- esrever([a,b,c],Reversed). Reversed = [c, b, a] . ?- join_lists([one,two],[1,2],Result). Result = [one, two, 1, 2]. ?- join_lists([one,two],[1,2],[a,b],Result). Result = [one, two, 1, 2, a, b]. ?- join_lists([one,two],[1,2],[a,b],[eins,zwei],Result). Result = [one, two, 1, 2, a, b, eins, zwei]. ?- product([1,2,3],Product). Product = 6. ?- product([1,2,3,0],Product). Product = 0. ?- factorial(8,Fac). Fac = 40320 . ?- factorial(3,Fac). Fac = 6 . ?- make_set([a,b,c,c],Set). Set = [a, b, c] . ?- make_set([c,c,c,c,c],Set). Set = [c] . ?- replace(0,1,[a,b,c,d],List). List = [1, b, c, d] . ?- remove(a,[a,b,c],Result). Result = [b, c] . ?- take([a,b,c,d],E,R). E = c, R = [a, b, d] . ?- take([a,b,c,d],E,R). E = d, R = [a, b, c] . ?- split([],L1,L2). L1 = L2, L2 = []. ?- split([a,b,c,d],L1,L2). false. ?- split([[a,b],[c,d],[e,f]],L1,L2). L1 = [a, c, e], L2 = [b, d, f]. ?- split([[1,one],[2,two],[3,three]],L1,L2). L1 = [1, 2, 3], L2 = [one, two, three]. ?- min_pair(2,9,Min). Min = 2 Unknown action: (h for help) Action? Unknown action: [ (h for help) Action? Unknown action: A (h for help) Action? . ?- min_pair(2,9,Min). Min = 2 . ?- min_pair(9,2,Min). Min = 2. ?- max_pair(9,2,Max). Max = 9 . ?- max_pair(2,9,Max). Max = 9. ?- min([4,5,6,7],Min). Min = 4. ?- min([2,7,2,67,1,9],Min). Min = 1 . ?- max([2,7,2,67,1,9],Max). Max = 67 . ?- max([3,3,3,4],Max). Max = 4 . ?- sort_inc([1,5,2,6,2,8,8,34,14],Sorted). Sorted = [1, 2, 2, 5, 6, 8, 8, 14, 34] . ?- sort_dec([2,5,8,2,6,1,7,0,3,6,15],Sorted). Sorted = [15, 8, 7, 6, 6, 5, 3, 2, 2|...] . ?- sort_dec([2,5,8,2,6,1,7,26,35],Sorted). Sorted = [35, 26, 8, 7, 6, 5, 2, 2, 1] . ?- a_list([1,2,3,4],[one,two,three,four],AssociationList). AssociationList = [pair(1, one), pair(2, two), pair(3, three), pair(4, four)] . ?- a_list([1,2,3,4],[one,two,three],AssociationList). AssociationList = [pair(1, one), pair(2, two), pair(3, three), pair(4, three)] . ?- a_list([3,2,1],[a,b,c],AssociationList). AssociationList = [pair(3, a), pair(2, b), pair(1, c)] . ?- assoc([pair(1,one),pair(2,two),pair(3,three)],3,Value). Value = three . ?- assoc([pair(hi,hello),pair(weather,sunny),pair(dog,woof)],dog,Value). Value = woof . ?- halt. mba:List processing code johnz$