View source with raw comments or as raw
    1/*  Part of SWI-Prolog
    2
    3    Author:        Anne Ogborn
    4    WWW:           http://www.swi-prolog.org
    5
    6    This program is free software; you can redistribute it and/or
    7    modify it under the terms of the GNU General Public License
    8    as published by the Free Software Foundation; either version 2
    9    of the License, or (at your option) any later version.
   10
   11    This program is distributed in the hope that it will be useful,
   12    but WITHOUT ANY WARRANTY; without even the implied warranty of
   13    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   14    GNU General Public License for more details.
   15
   16    You should have received a copy of the GNU General Public
   17    License along with this library; if not, write to the Free Software
   18    Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   19
   20    As a special exception, if you link this library with other files,
   21    compiled with a Free Software compiler, to produce an executable, this
   22    library does not by itself cause the resulting executable to be covered
   23    by the GNU General Public License. This exception does not however
   24    invalidate any other reasons why the executable file might be covered by
   25    the GNU General Public License.
   26*/
   27
   28:-module(did_you_know,
   29	 [ did_you_know_script//1,
   30	   did_you_know//0
   31	 ]).

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. */

   39:- use_module(library(http/html_write)).   40:- use_module(library(http/http_dispatch)).   41:- use_module(library(random)).   42:- use_module(news).   43:- use_module(holidays).   44:- use_module(library(http/js_write)).   45
   46:- http_handler(root(dyk), did_you_know, []).
 did_you_know(+Request)
Reply with a non-cacheable DYK fragment.
   52did_you_know(_Request) :-
   53	disable_client_cache,
   54	reply_html_page(plain,
   55			title('SWI-Prolog Did You Know'),
   56			\did_you_know).
   57
   58disable_client_cache :-
   59	format('Cache-Control: no-cache, no-store, must-revalidate\r\n\c
   60                Pragma: no-cache\r\n\c
   61		Expires: 0\r\n').
 did_you_know_script(+Id)//
Emit script to fetch DYK through AJAX
   67did_you_know_script(Id) -->
   68	html('Did you know ... '),
   69	{ http_link_to_id(did_you_know, [], HREF) },
   70	js_script({|javascript(Id, HREF)||
   71		   $(function() {
   72		     $.ajax({ url: HREF,
   73			      success: function(data) {
   74			        $("#"+Id).html(data);
   75			      }
   76		            });
   77		   });
   78		  |}).
 did_you_know//
Generate a DYK fragment.
   85did_you_know -->
   86	{ maybe(0.5) },
   87	random_news, !.
   88did_you_know -->
   89	{ todays_holiday(april_fools_day),
   90	  maybe(0.1)
   91	},
   92	random_silly_hint.
   93did_you_know -->
   94	random_hint.
   95
   96random_silly_hint -->
   97	{ predicate_property(afdyk(_,_), number_of_clauses(N)),
   98	  (   debugging(dyk(Id)),
   99	      integer(Id)
  100	  ->  true
  101	  ;   random_between(1, N, Id)
  102	  ),
  103	  afdyk(Id, Saying)
  104	},
  105	say_af_saying(Saying).
  106
  107say_af_saying(Text-Link) -->
  108	{ link(Link, HREF) },
  109	html([ span(class(lbl), 'Did you know?'),
  110	       ' ',
  111	       span(id(dyknow), a(href(HREF), Text))
  112	     ]).
  113say_af_saying(news(Text-Link)) -->
  114	{ link(Link, HREF) },
  115	html([ span(class(lbl), 'News:'),
  116	       ' ',
  117	       span(id(dyknow), a(href(HREF), Text))
  118	     ]).
  119say_af_saying(news(Text)) -->
  120	html([ span(class(lbl), 'News:'),
  121	       ' ',
  122	       span(id(dyknow), Text)
  123	     ]).
  124say_af_saying(Text) -->
  125	html([ span(class(lbl), 'Did you know?'),
  126	       ' ',
  127	       span(id(dyknow), Text)
  128	     ]).
  129
  130random_hint -->
  131	{ predicate_property(dyk(_,_), number_of_clauses(N)),
  132	  (   debugging(dyk(Id)),
  133	      integer(Id)
  134	  ->  true
  135	  ;   random_between(1, N, Id)
  136	  ),
  137	  dyk(Id, Saying),
  138	  (   Saying = (Text-Link)
  139	  ->  link(Link, HREF),
  140	      Info = a(href(HREF), Text)
  141	  ;   Info = Saying
  142	  )
  143	},
  144	html([ span(class(lbl), 'Did you know?'),
  145	       ' ',
  146	       span(id(dyknow), Info)
  147	     ]).
  148
  149link(section(Id), HREF) :- !,
  150	http_link_to_id(pldoc_man, [section=Id], HREF).
  151link(package(Name), HREF) :- !,
  152	file_name_extension(Name, html, File),
  153	http_link_to_id(pldoc_package, path_postfix(File), HREF).
  154link(pack(Name), HREF) :- !,
  155	http_link_to_id(pack_list, [p(Name)], HREF).
  156link(HREF, HREF).
 dyk(Id, Saying) is nondet
True if Saying is a DYK exression. They come in two forms:

be careful with line lengths for sayings, 40 chars max

  167:- multifile  term_expansion/2.  168
  169:- nb_setval(dyk_id, 1).  170term_expansion(dyk(Saying), dyk(Id, Saying)) :-
  171	nb_getval(dyk_id, Id),
  172	Id2 is Id+1,
  173	nb_setval(dyk_id, Id2).
  174
  175dyk('SWI-Prolog is 28 years old').
  176dyk(['the ', b('Profiler'), ' can speed up your code']-section('profiling-predicates')).
  177dyk('You can hot-swap code').
  178dyk('SWI-Prolog uses logical update view'-section('update')).
  179dyk('M-/ does autocomplete in pceEmacs').
  180dyk('C-c C-c CamelCasesWords in pceEmacs').
  181dyk('C-c C-- underscores_words_in_pce_emacs').
  182dyk('C-+ and C-- changes font size in pceEmacs').
  183dyk('About the nifty drawing program pceDraw').
  184dyk('Special quasiquote syntax for html and javascript'-section('quasiquotations')).
  185dyk('Advice for choosing 32/64 bits'-section('64bits')).
  186dyk('You can configure your environment'-section('initfile')).
  187dyk(['SWI-Prolog supports the ', b('Snowball'), ' stemmer']-section('snowball')).
  188dyk(['SWI-Prolog supports ', b(tabling), ' (SLG resolution)']-section('tabling')).
  189dyk('SWI-Prolog has an RDF Semantic Web Server'-'http://cliopatria.swi-prolog.org/home').
  190dyk('You can interface C++ to SWI-Prolog'-package('pl2cpp')).
  191dyk('SWI-Prolog can work with tar archives'-package('archive')).
  192dyk('This website is written entirely in SWI-Prolog'-package('http')).
  193dyk(['about the full featured ', b('web framework')]-package('http')).
  194dyk(['SWI-Prolog can act as an ', b('http client')]-section('http-clients')).
  195dyk('SWI-Prolog supports PDT, the Prolog Development Tools'-package('pdt')).
  196dyk('You can get Javadoc style documentation automatically'-package('pldoc')).
  197dyk(['SWI-Prolog has a ', b('unit test framework')]-package('plunit')).
  198dyk(['SWI-Prolog has a ', b('Natural Language Processing (NLP)'), ' library']-package('nlp')).
  199dyk(['SWI-Prolog supports ', b('Google Protocol Buffers')]-package('protobufs')).
  200dyk('SWI-Prolog talks to R'-package('R')).
  201dyk(['SWI-Prolog has ', b('powerful Semantic Web tools')]-package('semweb')).
  202dyk(['SWI-Prolog can ', b('parse SGML/XML')]-package('sgml')).
  203dyk(['SWI-Prolog has extensive ', b('GIS Support')]-package('space')).
  204dyk(['SWI-Prolog has support for ', b('large, static tables')]-package('table')).
  205dyk(['SWI-Prolog supports ', b('TIPC')]-package('tipc')).
  206dyk(['You can read/write ', b('.zip'), ' files']-package('zlib')).
  207dyk(['SWI-Prolog can talk to Java,C,C++,Python,and C#']-'/contrib/').
  208dyk(['You can control ', b('MIDI'), ' on Mac with SWI-Prolog']-'/contrib/SamerAbdallah/index.html').
  209dyk(['SWI-Prolog has ', b('an OpenGL Interface')]-'/contrib/OpenGL.html').
  210dyk(['SWI-Prolog is highly ', b('cross platform')]).
  211dyk('SWI-Prolog has multiple high quality random number generators'-'/contrib/SamerAbdallah/index.html').
  212dyk('The SWI-Prolog manual is available in printed form'-
  213    'http://books.google.nl/books/about/SWI_Prolog_Reference_Manual_6_2_2.html?id=q6R3Q3B-VC4C&redir_esc=y').
  214dyk(['ETALIS ', b('Event Processing'), ' runs on SWI-Prolog']-'http://code.google.com/p/etalis/').
  215dyk('This website\'s code is available'-'https://github.com/SWI-Prolog/plweb').
  216dyk(['SWI-Prolog can talk to ', b('Matlab')]-'/contrib/SamerAbdallah/index.html').
  217dyk(['SWI-Prolog has an active ', b('mailing list')]-'/Mailinglist.html').
  218dyk(['Jan loves it when you ', b('Report Bugs')]-'https://github.com/SWI-Prolog/issues/issues').
  219dyk(['You can get ', span(class=colored, 'COLORED'), ' text on the command line']-'/FAQ/ColorConsole.html').
  220dyk(['SWI-Prolog has a ', b('Nifty IDE')]-'/IDE.html').
  221dyk(['SWI-Prolog has a ', b('Graphic Debugger')]-'/gtrace.html').
  222dyk(['Try C-c C-n in pceEmacs']-'/navigator.html').
  223dyk('Try gxref. from the top level with a large project open'-'/gxref.html').
  224dyk('XPCE supports a sophisticated styled text engine').
  225dyk('Your proprietary application can use SWI-Prolog'-'/license.html').
  226dyk(['SWI-Prolog has an interface to FANN, a foss ', b('Neural Net'), ' library']-'http://leenissen.dk/fann/wp/').
  227dyk('SWI-Prolog has lots of useful Packages'-'/pack/list').
  228dyk(['SWI-Prolog can ', b('track open source licenses')]-section(softlicense)).
  229dyk(['SWI-Prolog has a pack to access ', b('Pubmed Data')]-pack(pubmed)).
  230dyk(['SWI-Prolog has ', b('Multi-Thread support')]-section(threads)).
  231dyk(['SWI-Prolog provides ', b('general DCG primitives')]-'/pldoc/doc/swi/library/dcg/basics.pl').
  232dyk('SWI-Prolog can handle Unix signals'-section(signal)).
  233dyk('SWI-Prolog can lazily parse a file'-section(pureinput)).
  234dyk('You can add menus to the swipl-win.exe console in windows'-section(plwin)).
  235dyk(['SWI-Prolog has a ', b('Profiler')]-section(profile)).
  236dyk('SWI-Prolog supports DDE on Windows'-section('DDE')).
  237dyk(['You can create ', b('stand alone exe files'), ' from SWI-Prolog code']-section(runtime)).
  238dyk('SWI-Prolog supports arbitrarily large integers').
  239% below here added by AO 2015-01-18
  240dyk(['There\'s an API to interact with', b('Amazon')]-pack(amazon_api)).
  241dyk('Nifty call graphs'-pack(callgraph)).
  242dyk('condition is an alternative to exceptions'-pack(condition)).
  243dyk('You can train markov chains with BIMS'-pack(bims)).
  244dyk('blog_core is a nifty CMS for SWI-Prolog'-pack(blog_core)).
  245dyk('anything in single quotes is an atom').
  246dyk('Logtalk is now a pack'-pack(logtalk)).
  247dyk('SWI-Prolog has probabilistic logic'-pack(cplint)).
  248dyk(['DCG help at lib ',
  249     a(href='/pldoc/doc/swi/library/dcg/basics.pl', 'dcg/basics'),
  250     ' & packs dcg_util & dcg_utils']).
  251dyk('automatic UML->Prolog translation'-pack(dia)).
  252dyk('docstore is a document oriented DB in SWI-Prolog'-pack(docstore)).
  253dyk('you can deploy to dotcloud'-pack(dotcloud)).
  254dyk('CQL makes dealing with SQL easier'-section('/packages/cql.html')).
  255dyk('you can turn ugraphs into graphml'-pack(graphml)).
  256dyk('you can turn terms into graphviz (.dot) files'-pack(gvterm)).
  257dyk('about nifty JoCaml style multithreading'-pack(jolog)).
  258dyk('the first Prolog interpreter was in Fortran').
  259dyk('julian pack offers match based dates'-pack(julian)).
  260dyk('eliminate helper predicates with pack lambda'-pack(lambda)).
  261dyk('you can parse markdown').
  262dyk('don\'t use format to print errors'-section(debug)).
  263dyk('there\'s a simplex library'-section(simplex)).
  264dyk('use mavis for type checking'-pack(mavis)).
  265dyk('you can read ODF spreadsheets'-pack(odf_sheet)).
  266dyk('how to submit a patch'-'/howto/SubmitPatch.html').
  267dyk('add language:prolog in github search').
  268dyk('there is an official Docker library for SWI-Prolog'-'/Docker.html').
  269dyk('there is a Docker image SWISH'-'/Docker.html').
  270dyk('SWI-Prolog runs on Android Termux'-'/build/Termux.html').
 afdyk(Id, Saying) is nondet
True if Saying is a DYK exression for april fools. They come in four forms:

be careful with line lengths for sayings, 40 chars max

  284term_expansion(afdyk(Saying), afdyk(Id, Saying)) :-
  285	(   predicate_property(afdyk(_,_), number_of_clauses(N))
  286	->  Id is N+1
  287	;   Id = 1
  288	).
  289
  290afdyk('SWI-Prolog complies with ISO JTC1/SC22/WG4'-'http://cobolstandard.info/wg4/wg4.html').
  291afdyk('C-c C-q automatically corrects syntax errors'-'/AprilFools.html').
  292afdyk('SWI-Prolog defaults to EBCDIC'-'/AprilFools.html').
  293afdyk(news('SWI-Prolog is now available on 9-track tape'-'/AprilFools.html')).
  294afdyk('pack_install(agi) installs Skynet'-'/AprilFools.html').
  295afdyk(['SWI-Prolog powers ', a(href='http://java.com' , 'this popular site')]).
  296afdyk('http_get is (?, ?, +)').
  297afdyk(news('A SWI-Prolog program beat the world champion in box hockey'-'/AprilFools.html')).
  298afdyk('8cD'-'https://github.com/Anniepoo/prolog-examples/blob/master/emoticons.pl').
  299afdyk(news('Bill Joy admits he\'s wrong, urges Prolog'-'/AprilFools.html')).
  300afdyk(['Prolog actually ', b('IS'), ' good for torturing undergrads']-'/AprilFools.html').
  301afdyk(news('Colmerauer admits Prolog isn\'t logical at all'-'/AprilFools.html')).
  302afdyk('about pack(antigravity)'-'/AprilFools.html').
  303afdyk('SWI-Prolog 7.1.29 requires OSGi and qPID'-'/AprilFools.html').
  304afdyk('this website powered by windmills'-'/dogfood.html').
  305afdyk('Nou breekt mijn klomp. Prolog is beter!'-'/AprilFools.html').
  306afdyk('about pack(klomp)'-'/AprilFools.html').
  307afdyk('about pack(cheese)'-'/AprilFools.html').
  308afdyk('about pack(chocolate)'-'/AprilFools.html').
  309afdyk('about pack(evil)'-pack(evil)).
  310afdyk('Use Appendix B for clear code'-section(hack)).
  311afdyk('Early Prologs ended clauses with AMEN'-
  312      'http://web.archive.org/web/20070703003934/www.lim.univ-mrs.fr/~colmer/ArchivesPublications/HistoireProlog/19november92.pdf').
  313afdyk('test'-pack(abdcsd))