Jump to content

Simple database: Difference between revisions

m
→‎{{header|Pike}}: fix line length
m (→‎{{header|Pike}}: lines too long)
m (→‎{{header|Pike}}: fix line length)
Line 154:
(main (argv))</lang>
=={{header|Pike}}==
{{lines_too_long|Pike}}
an almost direct translation from common lisp:
<lang Pike>mapping db = ([]);
Line 165 ⟶ 164:
void print_episode(mapping episode)
{
write(" %-30s %10s %-30s (%{%d.%})\n", episode->series, episode->episode, episode->title, episode->date);
episode->series, episode->episode, episode->title, episode->date);
}
 
Line 208:
void watch_list(mapping database)
{
map(Array.sort_array(get_latest(database), compare_by_date), print_episode);
print_episode);
}
 
Line 224 ⟶ 225:
mapping prompt_for_episode()
{
return make_episode(prompt_read("Series"), prompt_read("Title"), prompt_read("Episode"), parse_date(prompt_read("Date watched")));
prompt_read("Title"),
prompt_read("Episode"),
parse_date(prompt_read("Date watched")));
}
 
// pike offers encode_value() and decode_value() as standard ways to save and read data,
// to save and read data, but that is not a human readable format.
// therefore we are instead printing the structure as debug-output which is a readable form
// which is a readable form as long as it only contains integers, strings, mappings, arrays and multisets this format can be read by pike.
// strings, mappings, arrays and multisets this format can be read by pike.
// to read it we are creating a class that contains the data as a value,
// which is then compiled and instantiated to allow us to pull the data out.
Line 246 ⟶ 251:
{
if (file_stat(filename))
return compile_string("mixed data = " +Stdio.read_file(filename)+";")()->data;
Stdio.read_file(filename) + ";")()->data;
else return ([]);
}
Anonymous user
Cookies help us deliver our services. By using our services, you agree to our use of cookies.