Initial data commit

This commit is contained in:
Ingy döt Net 2023-07-01 11:58:00 -04:00
parent 72d218235f
commit f23f22d71c
199087 changed files with 3378941 additions and 0 deletions

View file

@ -0,0 +1,5 @@
:- func name = string.
name = Name :-
Name = Title ++ " " ++ Given,
Title = "Dr.",
Given = "Bob".

View file

@ -0,0 +1,4 @@
:- pred greet(string::in, io::di, io::uo) is det.
greet(Who, !IO) :-
io.write_string("Hello", !IO),
io.format(", %s!\n", [s(Who)], !IO).

View file

@ -0,0 +1,4 @@
:- pred greet(string::in, io::di, io::uo) is det.
greet(Who, !.IO, !:IO) :-
io.write_string("Hello", !.IO, !:IO),
io.format(", %s!\n", [s(Who)], !.IO, !:IO).

View file

@ -0,0 +1,4 @@
:- pred greet(string::in, io::di, io::uo) is det.
greet(Who, IO0, IO) :-
io.write_string("Hello", IO0, IO1),
io.format(", %s!\n", [s(Who)], IO1, IO).

View file

@ -0,0 +1,9 @@
:- func dr(string) = string.
dr(Name) = Titled :-
some [!SB] (
!:SB = string.builder.init,
put_char(handle, 'D', !SB),
put_char(handle, 'r', !SB),
format(handle, " %s", [s(Name)], !SB),
Titled = to_string(!.SB)
).

View file

@ -0,0 +1,6 @@
% all_under(N, L)
% True if every member of L is less than N
%
:- pred all_under(int::in, list(int)::in) is semidet.
all_under(Limit, L) :-
all [N] (member(N, L) => N < Limit).

View file

@ -0,0 +1,23 @@
:- type accumulator == (pred(int, int, io, io)).
:- inst accumulator == (pred(in, out, di, uo) is det).
:- func accumulator >> accumulator = accumulator.
:- mode in(accumulator) >> in(accumulator) = out(accumulator).
A >> B = C :-
C = (pred(!.N::in, !:N::out, !.IO::di, !:IO::uo) is det :-
A(!N, !IO),
B(!N, !IO)).
:- pred add(int::in, int::in, int::out, io::di, io::uo) is det.
add(N, !Acc, !IO) :-
io.format("adding %d to accumulator (current value: %d)\n",
[i(N), i(!.Acc)], !IO),
!:Acc = !.Acc + N.
:- pred example2(io::di, io::uo) is det.
example2(!IO) :-
F = add(5)
>> add(5)
>> add(-10),
F(0, X, !IO),
io.print_line(X, !IO).

View file

@ -0,0 +1,39 @@
:- module evenodd.
:- interface.
:- import_module io.
:- pred main(io::di, io::uo) is det.
:- implementation.
:- import_module list, string.
:- type coin
---> heads
; tails.
:- inst heads for coin/0
---> heads.
:- inst tails for coin/0
---> tails.
main(!IO) :-
(if heads(heads, N) then
print_heads(N, !IO)
else true).
:- pred print_heads(coin::in(heads), io::di, io::uo) is det.
print_heads(_, !IO) :-
io.write_string("heads\n", !IO).
:- pred print_tails(coin::in(tails), io::di, io::uo) is det.
print_tails(_, !IO) :-
io.write_string("tails\n", !IO).
:- pragma foreign_export_enum("C", coin/0, [prefix("COIN_"), uppercase]).
:- pred heads(coin::in, coin::out(heads)) is semidet.
:- pragma foreign_proc("C",
heads(N::in, M::out(heads)),
[promise_pure, will_not_call_mercury],
"
M = N;
SUCCESS_INDICATOR = N == COIN_HEADS;
").