June 2018 Update

This commit is contained in:
Ingy döt Net 2018-06-22 20:57:24 +00:00
parent ba8067c3b7
commit 22f33d4004
5278 changed files with 84726 additions and 14379 deletions

View file

@ -22,6 +22,11 @@ The input should be an arbitrary story in the form:
found a <noun>. <name> decided to take it home.
</pre>
Given this example, it should then ask for a <tt>name</tt>, a <tt>he or she</tt> and a <tt>noun</tt> (<tt><nowiki><name></nowiki></tt> gets replaced both times with the same value).
;Related tasks:
* &nbsp; [[Old_lady_swallowed_a_fly]]
* &nbsp; [[The Twelve Days of Christmas]]
<br><br>
== {{header|Ada}} ==

View file

@ -1,43 +1,33 @@
integer i;
file f;
data b;
list l;
record r;
f_affix(f, "/dev/stdin");
f.stdin;
o_text("Enter the blank line terminated story:\n");
while (0 < f_b_line(f, b)) {
l_append(l, b);
while (0 < f.b_line(b)) {
l.append(b);
}
i = 0;
while (i < l_length(l)) {
for (, b in l) {
integer p, q;
text s, t;
b = l_q_data(l, i);
while ((p = b_index(b, '<')) ^ -1) {
q = b_probe(b, p, '>');
while ((p = b.place('<')) ^ -1) {
q = b.probe(p, '>');
if (q ^ -1) {
s = cut(b_string(b), p + 1, q - p - 1);
b_erase(b, p, q);
if (!r_key(r, s)) {
o_text(cat3("Replacement for `", s, ":'\n"));
f_line(f, t);
r_put(r, s, t);
s = bq_string(b, p + 1, q - 1);
b.erase(p, q);
if (!r.key(s)) {
o_("Replacement for `", s, "':\n");
f.line(t);
r.put(s, t);
}
b_paste(b, p, r_query(r, s));
b.paste(p, r[s]);
}
}
i += 1;
}
while (l_length(l)) {
o_text(b_string(l_head(l)));
o_newline();
l_delete(l, 0);
}
l.ucall(o_, 0, "\n");

View file

@ -0,0 +1,7 @@
set theNoun to the text returned of (display dialog "What is your noun?" default answer "")
set thePerson to the text returned of (display dialog "What is the person's name?" default answer "")
set theGender to the text returned of (display dialog "He or she? Please capitalize." default answer "")
display dialog thePerson & " went for a walk in the park. " & theGender & " found a " & theNoun & ". " & thePerson & " decided to take it home."

View file

@ -0,0 +1,18 @@
function madlibs(template)
println("The story template is:\n", template)
fields = Set(getfield.(collect(eachmatch(r"<[^>]+>", template)), :match))
print("\nInput a comma-separated list of words to replace the following items:",
join(fields, ", "), "\n -> ")
values = split(readline(STDIN), ",")
for (m, v) in zip(fields, values)
template = replace(template, m, v)
end
println("\nThe story becomes:\n", template)
end
const template = """
<name> went for a walk in the park. <he or she>
found a <noun>. <name> decided to take it home.
"""
madlibs(template)