Data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 7387c8f97b
commit cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions

View file

@ -0,0 +1,17 @@
rosetta_menu([], "") :- !. %% Incase of an empty list.
rosetta_menu(Items, SelectedItem) :-
repeat, %% Repeat until everything that follows is true.
display_menu(Items), %% IO
get_choice(Choice), %% IO
number(Choice), %% True if Choice is a number.
nth1(Choice, Items, SelectedItem), %% True if SelectedItem is the 1-based nth member of Items, (fails if Choice is out of range)
!.
display_menu(Items) :-
nl,
foreach( nth1(Index, Items, Item),
format('~w) ~s~n', [Index, Item]) ).
get_choice(Choice) :-
prompt1('Select a menu item by number:'),
read(Choice).

View file

@ -0,0 +1,20 @@
?- rosetta_menu(["fee fie", "huff and puff", "mirror mirror", "tick tock"], String).
1) fee fie
2) huff and puff
3) mirror mirror
4) tick tock
Select a menu item by number:a.
1) fee fie
2) huff and puff
3) mirror mirror
4) tick tock
Select a menu item by number:10.
1) fee fie
2) huff and puff
3) mirror mirror
4) tick tock
Select a menu item by number:3.
String = "mirror mirror".