-
Notifications
You must be signed in to change notification settings - Fork 10
/
did_you_know.pl
341 lines (310 loc) · 14.3 KB
/
did_you_know.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/* Part of SWI-Prolog
Author: Anne Ogborn
WWW: https://www.swi-prolog.org
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public
License along with this library; if not, write to the Free Software
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
As a special exception, if you link this library with other files,
compiled with a Free Software compiler, to produce an executable, this
library does not by itself cause the resulting executable to be covered
by the GNU General Public License. This exception does not however
invalidate any other reasons why the executable file might be covered by
the GNU General Public License.
*/
:-module(did_you_know,
[ did_you_know_script//1,
did_you_know//0
]).
/** <module> Interesting snippets about SWI-Prolog
This module generates the 'Did You Know blah blah' bit that appears on
every pldoc and SWI-Prolog website page.
*/
:- use_module(library(http/html_write)).
:- use_module(library(http/http_dispatch)).
:- use_module(library(random)).
:- use_module(library(debug)).
:- use_module(news).
:- use_module(holidays).
:- use_module(page).
:- use_module(library(http/js_write)).
:- http_handler(root(dyk), did_you_know, []).
%% did_you_know(+Request)
%
% Reply with a non-cacheable DYK fragment.
did_you_know(_Request) :-
disable_client_cache,
reply_html_page(plain,
title('SWI-Prolog Did You Know'),
\did_you_know).
disable_client_cache :-
format('Cache-Control: private, no-store\r\n').
%% did_you_know_script(+Id)//
%
% Emit script to fetch DYK through AJAX
did_you_know_script(Id) -->
html('Did you know ... '),
{ http_link_to_id(did_you_know, [], HREF) },
js_script({|javascript(Id, HREF)||
$(function() {
$.ajax({ url: HREF,
success: function(data) {
console.log(data);
$("#"+Id).html(data);
}
});
});
|}).
%% did_you_know//
%
% Generate a DYK fragment.
did_you_know -->
{ maybe(0.2) },
!,
html([ span(class('dyk-sponsor'), 'We need you to '),
\github_actions([sponsor]),
span(class('dyk-sponsor'), ' to keep SWI-Prolog sustainable')
]).
did_you_know -->
{ maybe(0.5) },
random_news, !.
did_you_know -->
{ todays_holiday(april_fools_day),
maybe(0.1)
},
random_silly_hint.
did_you_know -->
random_hint.
random_silly_hint -->
{ predicate_property(afdyk(_,_), number_of_clauses(N)),
( debugging(dyk(Id)),
integer(Id)
-> true
; random_between(1, N, Id)
),
afdyk(Id, Saying)
},
say_af_saying(Saying).
say_af_saying(Text-Link) -->
{ link(Link, HREF) },
html([ span(class(lbl), 'Did you know?'),
' ',
span(id(dyknow), a(href(HREF), Text))
]).
say_af_saying(news(Text-Link)) -->
{ link(Link, HREF) },
html([ span(class(lbl), 'News:'),
' ',
span(id(dyknow), a(href(HREF), Text))
]).
say_af_saying(news(Text)) -->
html([ span(class(lbl), 'News:'),
' ',
span(id(dyknow), Text)
]).
say_af_saying(Text) -->
html([ span(class(lbl), 'Did you know?'),
' ',
span(id(dyknow), Text)
]).
random_hint -->
{ predicate_property(dyk(_,_), number_of_clauses(N)),
( debugging(dyk(Id)),
integer(Id)
-> true
; random_between(1, N, Id)
),
dyk(Id, Saying),
( Saying = (Text-Link)
-> link(Link, HREF),
Info = a(href(HREF), Text)
; Info = Saying
)
},
html([ span(class(lbl), 'Did you know?'),
' ',
span(id(dyknow), Info)
]).
link(section(Id), HREF) :- !,
http_link_to_id(pldoc_man, [section=Id], HREF).
link(object(Obj), HREF) :-
format(string(SObj), '~w', Obj),
http_link_to_id(pldoc_doc_for, [object=SObj], HREF).
link(package(Name), HREF) :- !,
format(atom(HREF), '/pldoc/package/~w', [Name]).
link(pack(Name), HREF) :- !,
http_link_to_id(pack_list, [p(Name)], HREF).
link(library(Name), HREF) :- !,
format(atom(HREF), '/pldoc/doc/_SWI_/library/~w.pl', [Name]).
link(HREF, HREF).
%% dyk(Id, Saying) is nondet
%
% True if Saying is a DYK exression. They come in two forms:
%
% * HTML - HREF
% * HTML
%
% be careful with line lengths for sayings, 40 chars max
:- multifile term_expansion/2.
:- nb_setval(dyk_id, 1).
term_expansion(dyk(Saying), dyk(Id, Saying)) :-
nb_getval(dyk_id, Id),
Id2 is Id+1,
nb_setval(dyk_id, Id2).
dyk(['SWI-Prolog is ', Years, ' years old']) :-
get_time(Now),
Years is floor((Now-536454000)/(365*24*3600)).
dyk(['the ', b('Profiler'), ' can speed up your code']-section('profiling-predicates')).
dyk('You can hot-swap code'-library(hotfix)).
dyk('M-/ does autocomplete in pceEmacs').
dyk('C-c C-c CamelCasesWords in pceEmacs').
dyk('C-c C-- underscores_words_in_pce_emacs').
dyk('C-+ and C-- changes font size in pceEmacs').
dyk('Quasi Quoting allows embedding e.g. html, javascript, etc.'-section('quasiquotations')).
dyk('You can configure your environment'-section('initfile')).
dyk(['SWI-Prolog supports the ', b('Snowball'), ' stemmer']-section('snowball')).
dyk(['SWI-Prolog supports ', b(tabling), ' (SLG resolution)']-section('tabling')).
dyk('SWI-Prolog has an RDF Semantic Web Server'-'http://cliopatria.swi-prolog.org/home').
dyk('You can interface C++ to SWI-Prolog'-package('pl2cpp')).
dyk('SWI-Prolog can work with many archive files'-package('archive')).
dyk('This website is written entirely in SWI-Prolog'-package('http')).
dyk(['about the full featured ', b('web framework')]-package('http')).
dyk(['SWI-Prolog can act as an ', b('http client')]-section('http-clients')).
dyk('SWI-Prolog supports PDT, the Prolog Development Tools'-package('pdt')).
dyk('You can get Javadoc style documentation automatically'-package('pldoc')).
dyk(['SWI-Prolog has a ', b('unit test framework')]-package('plunit')).
dyk(['SWI-Prolog has a ', b('Natural Language Processing (NLP)'), ' library']-package('nlp')).
dyk(['SWI-Prolog supports ', b('Google Protocol Buffers')]-package('protobufs')).
dyk('SWI-Prolog talks to R'-package('R')).
dyk(['SWI-Prolog has ', b('powerful Semantic Web tools')]-package('semweb')).
dyk(['SWI-Prolog can ', b('parse HTML/SGML/XML')]-package('sgml')).
dyk(['SWI-Prolog has extensive ', b('GIS Support')]-package('space')).
dyk(['SWI-Prolog has support for ', b('large, static tables')]-package('table')).
dyk(['SWI-Prolog supports ', b('TIPC')]-package('tipc')).
dyk(['You can read/write ', b('.zip'), ' files']-package('zlib')).
dyk(['SWI-Prolog can talk to many other languages']-'/contrib/').
dyk(['You can control ', b('MIDI'), ' on Mac with SWI-Prolog']-'/contrib/SamerAbdallah/index.html').
dyk(['SWI-Prolog has ', b('an OpenGL Interface')]-'/contrib/OpenGL.html').
dyk(['SWI-Prolog is highly ', b('cross platform')]-'/build/').
dyk('SWI-Prolog has multiple high quality random number generators'-'/contrib/SamerAbdallah/index.html').
dyk('The SWI-Prolog manual is available in printed form'-
'http://books.google.nl/books/about/SWI_Prolog_Reference_Manual_6_2_2.html?id=q6R3Q3B-VC4C&redir_esc=y').
dyk(['ETALIS ', b('Event Processing'), ' runs on SWI-Prolog']-'http://code.google.com/p/etalis/').
dyk('This website\'s code is available'-'https://github.com/SWI-Prolog/plweb').
dyk(['SWI-Prolog can talk to ', b('Matlab')]-'/contrib/SamerAbdallah/index.html').
dyk(['SWI-Prolog has an active ', b('Discourse forum')]-'https://swi-prolog.discourse.group/').
dyk(['Jan loves it when you ', b('Report Bugs')]-'https://github.com/SWI-Prolog/issues/issues').
dyk(['You can get ', span(class=colored, 'COLORED'), ' text on the command line']-'/FAQ/ColorConsole.html').
dyk(['SWI-Prolog has a ', b('Nifty IDE')]-'/IDE.html').
dyk(['SWI-Prolog has a ', b('Graphic Debugger')]-'/gtrace.html').
dyk(['Try C-c C-n in pceEmacs']-'/navigator.html').
dyk('Try gxref. from the top level with a large project open'-'/gxref.html').
dyk('Your proprietary application can use SWI-Prolog'-'/license.html').
dyk(['SWI-Prolog has an interface to FANN, a foss ', b('Neural Net'), ' library']-'http://leenissen.dk/fann/wp/').
dyk('SWI-Prolog has lots of useful Packages'-'/pack/list').
dyk(['SWI-Prolog can ', b('track open source licenses')]-section(softlicense)).
dyk(['SWI-Prolog has a pack to access ', b('Pubmed Data')]-pack(pubmed)).
dyk(['SWI-Prolog has ', b('Multi-Thread support')]-section(threads)).
dyk(['SWI-Prolog provides ', b('general DCG primitives')]-'/pldoc/doc/swi/library/dcg/basics.pl').
dyk('SWI-Prolog can handle Unix signals'-section(signal)).
dyk('SWI-Prolog can lazily parse a file'-section(pureinput)).
dyk('You can add menus to the swipl-win.exe console in windows'-section(plwin)).
dyk(['SWI-Prolog has a ', b('Profiler')]-section(profile)).
dyk('SWI-Prolog supports DDE on Windows'-section('DDE')).
dyk(['You can create ', b('stand alone exe files'), ' from SWI-Prolog code']-section(runtime)).
dyk('SWI-Prolog supports arbitrarily large integers').
dyk('SWI-Prolog supports rational numbers (\u211A)').
% below here added by AO 2015-01-18
dyk(['There\'s an API to interact with ', b('Amazon')]-pack(amazon_api)).
dyk('Nifty call graphs'-pack(callgraph)).
dyk('condition is an alternative to exceptions'-pack(condition)).
dyk('You can train markov chains with BIMS'-pack(bims)).
dyk('anything in single quotes is an atom').
dyk('Logtalk is now a pack'-pack(logtalk)).
dyk('SWI-Prolog has probabilistic logic'-pack(cplint)).
dyk(['DCG help at lib ',
a(href='/pldoc/doc/swi/library/dcg/basics.pl', 'dcg/basics'),
' & packs dcg_util & dcg_utils']).
dyk('automatic UML->Prolog translation'-pack(dia)).
dyk('docstore is a document oriented DB in SWI-Prolog'-pack(docstore)).
dyk('you can deploy to dotcloud'-pack(dotcloud)).
dyk('CQL makes dealing with SQL easier'-section('/packages/cql.html')).
dyk('you can turn ugraphs into graphml'-pack(graphml)).
dyk('you can turn terms into graphviz (.dot) files'-pack(gvterm)).
dyk('about nifty JoCaml style multithreading'-pack(jolog)).
dyk('the first Prolog interpreter was in Algol-W by Philippe Roussel (1972)').
dyk('julian pack offers match based dates'-pack(julian)).
dyk('you can parse markdown').
dyk('don\'t use format/2 to print debug messages'-section(debug)).
dyk('don\'t use format/2 to print errors'-object(print_message/2)).
dyk('there\'s a simplex library'-section(simplex)).
dyk('use mavis for type checking'-pack(mavis)).
dyk('you can read ODF spreadsheets'-pack(odf_sheet)).
dyk('how to submit a patch'-'/howto/SubmitPatch.html').
dyk('add language:prolog in github search').
dyk('there is an official Docker library for SWI-Prolog'-'/Docker.html').
dyk('there is a Docker image SWISH'-'/Docker.html').
dyk('SWI-Prolog runs on Android Termux'-'/build/Termux.html').
dyk('SWI-Prolog can be compiled to WASM to run in your browser'-'https://wasm.swi-prolog.org/wasm/shell').
dyk('SWI-Prolog for WASM is an npm package'-'https://www.npmjs.com/package/swipl-wasm').
dyk(['Janus provides a rich and fast bi-directional interface to ', b('Python')]-package(swipy)).
dyk(['Janus-swi lets you embed SWI-Prolog in ', b('Python')]-'https://pypi.org/project/janus-swi/').
dyk('Sweep provides a rich Prolog mode for GNU-Emacs'-'https://eshelyaron.com/sweep.html').
dyk('SWI-Prolog supports the full Unicode character set \U0001F600'-section(widechars)).
dyk(['SWI-Prolog provides ', b(engines), ' for coroutinging']-section(engines)).
dyk('print_term/2 can print large terms in readable format'-object(print_term/2)).
dyk([i('Blobs'), ' provide access to typed and garbage collected foreign data']-section(blob)).
dyk(['The ', b(libssh), ' pack provides secure login to Prolog server processes']-pack(libssh)).
dyk(['SWI-Prolog tabling provides ', i('Well Founded Semantics')]-section('WFS')).
dyk(['SWI-Prolog tabling provides ', i('incremental tabling')]-section('tabling-incremental')).
dyk(['SWI-Prolog tables can be ', i('shared'), ' between threads']-section('tabling-shared')).
dyk(['s(CASP) implements top-down answer set programming (ASP)']-pack('scasp')).
dyk(['s(CASP) add explanations to ASP']-pack('scasp')).
dyk(['s(CASP) implements ASP ', i('without grounding')]-pack('scasp')).
%% afdyk(Id, Saying) is nondet
%
% True if Saying is a DYK exression for april fools. They come in
% four forms:
%
% * HTML - HREF
% * HTML
% * news(HTML - HREF)
% * news(HTML)
%
% be careful with line lengths for sayings, 40 chars max
term_expansion(afdyk(Saying), afdyk(Id, Saying)) :-
( predicate_property(afdyk(_,_), number_of_clauses(N))
-> Id is N+1
; Id = 1
).
afdyk('SWI-Prolog complies with ISO JTC1/SC22/WG4'-'http://cobolstandard.info/wg4/wg4.html').
afdyk('C-c C-q automatically corrects syntax errors'-'/AprilFools.html').
afdyk('SWI-Prolog defaults to EBCDIC'-'/AprilFools.html').
afdyk(news('SWI-Prolog is now available on 9-track tape'-'/AprilFools.html')).
afdyk('pack_install(agi) installs Skynet'-'/AprilFools.html').
afdyk(['SWI-Prolog powers ', a(href='http://java.com' , 'this popular site')]).
afdyk('http_get is (?, ?, +)').
afdyk(news('A SWI-Prolog program beat the world champion in box hockey'-'/AprilFools.html')).
afdyk('8cD'-'https://github.com/Anniepoo/prolog-examples/blob/master/emoticons.pl').
afdyk(news('Bill Joy admits he\'s wrong, urges Prolog'-'/AprilFools.html')).
afdyk(['Prolog actually ', b('IS'), ' good for torturing undergrads']-'/AprilFools.html').
afdyk(news('Colmerauer admits Prolog isn\'t logical at all'-'/AprilFools.html')).
afdyk('about pack(antigravity)'-'/AprilFools.html').
afdyk('SWI-Prolog 7.1.29 requires OSGi and qPID'-'/AprilFools.html').
afdyk('this website powered by windmills'-'/dogfood.html').
afdyk('Nou breekt mijn klomp. Prolog is beter!'-'/AprilFools.html').
afdyk('about pack(klomp)'-'/AprilFools.html').
afdyk('about pack(cheese)'-'/AprilFools.html').
afdyk('about pack(chocolate)'-'/AprilFools.html').
afdyk('about pack(evil)'-pack(evil)).
afdyk('Use Appendix B for clear code'-section(hack)).
afdyk('Early Prologs ended clauses with AMEN'-
'http://web.archive.org/web/20070703003934/www.lim.univ-mrs.fr/~colmer/ArchivesPublications/HistoireProlog/19november92.pdf').
afdyk('test'-pack(abdcsd)).