Tags:
create new tag
, view all tags
+ The PrologPlugin (version 1.000)

ALERT! NOTE: This is an ObsoletePluginPackage. It has been superceeded by the wonderful ProgramsPlugin

[ move comments to PrologPluginDev ]

The PrologPlugin introduces the %PROLOG{...}% tag that:

  • runs a TWiki:Codev/GnuProlog query
  • replaces the tag with the run's output (you can also choose the output format)
  • you can cache the result at save time to speed viewing the page
  • you can impose a timeout to avoid runaway programs
NOTE: This is a first example of:
  • an object-oriented plugin.
  • a plugin using a TWiki:Codev/PoorManCache
  • a plugin that declares its syntax.
  • so you need version 1.011 or above of Plugins.pm (attached) that handles objects and syntax declarations


++ Syntax +++ Syntax of the PrologPlugin defined tags ++++ %PROLOG{...}%: Runs a Gnuprolog program

Parameter Default value Allowed values Description
goal ''   Short for initgoal="Goal,halt;halt" (results without prompt)
when 'view' 'view', 'save' When the program should run (at view or at save time)
dir 'web' 'web', 'topic' In which directory the program should run (in the web or in the topic attachments' dir)
timeout '5'   Timeout in seconds
format '$stdout'   Output format (use $stdout, $stderr to insert output)
initgoal ''   Init predicates (executed at start)
entrygoal ''   Entry predicates (executed before main loop)
querygoal ''   Query predicates (executed at main loop)
globalsz '8192'   Size of the heap memory area (bytes)
localsz '4096'   Size of the control memory area (bytes)
trailsz '3072'   Size of the trail memory area (bytes)
cstrsz '3072'   Size of the constraint memory area (bytes)

++++ %SAVEDPROLOG{...}%: Cache of the PROLOG execution at save time (do not use)

++ Tips and tricks

  • use when="save" to run the program at save time and cache the result
  • use goal="<goal without closing dot>" to run a program without showing the prompt
  • use dir="web" to run the program in the topic's web
    • useful to consult topics ... so that you can edit prolog programs as topics
      • yes, the META tags do not interfere, as they start with %, the prolog comment char
  • use dir="topic" to run the program in the topic's attachments dir
    • useful if you want to create attachments rachable with the %ATTACHURL% tag
  • use a looooong timeout together with when="save" to run long programs and cache the result

++ Installation

  • install GnuProlog (see http://www.gnu.org/software/prolog)
  • install the IPC::Run Perl module (from CPAN)
  • install version 1.011 or above of Plugins.pm
  • apply the attached patch needed to avoid processing verbatim tags in beforeSaveHandler
  • unzip the PrologPlugin.zip package in the twiki directory (as usual)
    • Move the Plugins/PrologPlugin.txt* files to the TWiki web if you like
  • check if the first example works

++ Settings

  • Set DEBUG to 1 to see the command called
    • Set DEBUG = 0
  • Description of this Plugin
    • Set SHORTDESCRIPTION = GnuProlog wrapper (and example of caching at save time)
  • Default timeout for stopping long (runaway) runs
    • Set TIMEOUT = 2
    • NOTE: long running programs can be cached at save time by using the when="save" parameter together with a long timeout

++ BUGS

  • Security Issue: the prolog program runs not (yet) chrooted

++ TODO

  • run in a Safe box?
  • run under chroot?
  • compile a safe version of GnuProlog? <-- this one is better
  • allow the usage of other implementations of prolog (SWI Prolog, Sicstus, ...)

++ Dependencies

  • Plugins.pm version 1.011 or above
  • the attached patch needed to avoid processing verbatim tags in beforeSaveHandler
  • The GnuProlog prolog/constraint solver: http://www.gnu.org/software/prolog (tested with version 1.2.16)
  • The CPAN module IPC::Run

++ Change history


++ Examples +++ Example without prompt
When you type
%PROLOG{
   goal="
      member(K,['TOPIC','WEB','ATTACHDIR','WEBDIR']),
      environ(K,V),
      format('\t* ~a = ~a\n',[K,V]),
      fail" 
}%
You get
  • TOPIC = PrologPlugin
  • WEB = Plugins
  • ATTACHDIR = /home/twiki/pub/Plugins/PrologPlugin
  • WEBDIR = /home/twiki/data/Plugins
If correctly installed you get the same below
%PROLOG{ goal=" member(K,['TOPIC','WEB','ATTACHDIR','WEBDIR']), environ(K,V), format('\t* ~a = ~a\n',[K,V]), fail" }%

+++ Example cached at save time

When you type
<pre>
%PROLOG{
   initgoal="write('%RED%initgoal is running%ENDCOLOR%'),nl" 
   entrygoal="write('%BLUE%entrygoal is running%ENDCOLOR%'),nl" 
   querygoal="write('%GREEN%querygoal is running%ENDCOLOR%'),nl,halt" 
   when="save"}%
</pre>
You get
initgoal is running
GNU Prolog 1.2.16
By Daniel Diaz
Copyright (C) 1999-2002 Daniel Diaz
entrygoal is running
| ?- write('querygoal is running'),nl,halt.
querygoal is running

+++ Example of timeout expiration

When you type
%PROLOG{
   goal="repeat,sleep(1),write(query),nl,fail" 
   format="
      <center>
      <table border='1'>
         <tr><th>stdout</th><th>stderr</th></tr>
         <tr><td><pre>$stdout&nbsp;</pre></td><td><pre>$stderr&nbsp;</pre></td></tr>
      </table>
      </center>"
   when="save"
}%
You get
stdoutstderr
query
query
Prolog process timed out after 2 seconds. 
 

+++ Writing to an attachment

When you type
%PROLOG{
   goal="
      tell('pippo.txt'),
      write('| la vecchia con la borsa ... |'),
      nl,
      write('| ... salta il fosso senza rincorsa. |'),
      nl,
      told" 
   dir="topic" 
   when="save"
}%
| *Content of %ATTACHURL%/pippo.txt* | 
%INCLUDE{"%ATTACHURL%/pippo.txt"}%
You get

Content of .../pippo.txt
la vecchia con la borsa ...
... salta il fosso senza rincorsa.


-- AndreaSterbini - 22 Aug 2003

Plugin Installation Instructions

Note: You do not need to install anything on the browser to use this plugin. The following instructions are for the administrator who installs the plugin on the server where TWiki is running.

  • Install GnuProlog
  • Install the IPC::Run Perl module (from CPAN)
  • Install version 1.011 or above of Plugins.pm
  • Apply the attached patch needed to avoid processing verbatim tags in beforeSaveHandler
  • Unzip the PrologPlugin.zip package in the twiki directory (as usual)
    • Move the Plugins/PrologPlugin.txt* files to the TWiki web if you like
  • Check if the first example works

Plugin Info

Plugin Author: TWiki:Main/AndreaSterbini
Plugin Version: 22 Aug 2003 (V1.000)
Change History:  
22 Aug 2003: First release v1.000
CPAN Dependencies: IPC::Run
Other Dependencies: * Plugins.pm version 1.011 or above
* the attached patch needed to avoid processing verbatim tags in beforeSaveHandler
* The GnuProlog prolog/constraint solver (tested with version 1.2.16)
Perl Version: 5.005
Plugin Home: http://TWiki.org/cgi-bin/view/Plugins/PrologPlugin
Feedback: http://TWiki.org/cgi-bin/view/Plugins/PrologPluginDev

Related Topics: TWikiPreferences, TWikiPlugins

-- TWiki:Main/AndreaSterbini - 22 Aug 2003

Topic attachments
I Attachment History Action Size Date Who Comment
Perl source code filepm Plugins.pm r1 manage 13.9 K 2003-08-21 - 23:20 AndreaSterbini v 1.011 for OO plugins and syntax declarations
Compressed Zip archivetgz PrologPlugin.tgz r1 manage 10.6 K 2003-08-21 - 23:02 AndreaSterbini v 1.000
Unknown file formatdiff Store-verbatim.diff r1 manage 0.7 K 2003-08-21 - 23:08 AndreaSterbini avoid verbatim processing while saving
Edit | Attach | Watch | Print version | History: r6 < r5 < r4 < r3 < r2 | Backlinks | Raw View | Raw edit | More topic actions
Topic revision: r6 - 2004-11-16 - PeterThoeny
 
  • Learn about TWiki  
  • Download TWiki
This site is powered by the TWiki collaboration platform Powered by Perl Hosted by OICcam.com Ideas, requests, problems regarding TWiki? Send feedback. Ask community in the support forum.
Copyright © 1999-2017 by the contributing authors. All material on this collaboration platform is the property of the contributing authors.