1 #+OPTIONS: H:3 num:nil toc:2 \n:nil ::t |:t ^:{} -:t f:t *:t tex:t d:(HIDE) tags:not-in-toc
2 #+STARTUP: align fold nodlcheck hidestars oddeven lognotestate hideblocks
3 #+SEQ_TODO: TODO(t) INPROGRESS(i) WAITING(w@) | DONE(d) CANCELED(c@)
4 #+TAGS: Write(w) Update(u) Fix(f) Check(c) noexport(n)
5 #+TITLE: PicoLisp Source Code Blocks in Org Mode
6 #+AUTHOR: Thorsten Jolitz
7 #+EMAIL: tj[at]data-driven[dot]de
9 #+HTML_LINK_UP: index.html
10 #+HTML_LINK_HOME: https://orgmode.org/worg/
11 #+EXCLUDE_TAGS: noexport
15 <div id="subtitle" style="float: center; text-align: center;">
17 Org Mode support for <a href="http://picolisp.com/5000/!wiki?home/">PicoLisp</a>
20 <a href="http://picolisp.com/5000/!wiki?home/">
21 <img src="http://picolisp.com/5000/wiki/logo.png"/>
27 * Template Checklist [12/12] :noexport:
29 - [X] Indicate #+AUTHOR:
31 - [X] Revise banner source block [3/3]
32 - [X] Add link to a useful language web site
33 - [X] Replace "Language" with language name
34 - [X] Find a suitable graphic and use it to link to the language
36 - [X] Write an [[Introduction]]
37 - [X] Describe [[Requirements%20and%20Setup][Requirements and Setup]]
38 - [X] Replace "Language" with language name in [[Org%20Mode%20Features%20for%20Language%20Source%20Code%20Blocks][Org Mode Features for Language Source Code Blocks]]
39 - [X] Describe [[Header%20Arguments][Header Arguments]]
40 - [X] Describe support for [[Sessions]]
41 - [X] Describe [[Result%20Types][Result Types]]
42 - [X] Describe [[Other]] differences from supported languages
43 - [X] Provide brief [[Examples%20of%20Use][Examples of Use]]
45 ** Brief description of PicoLisp
46 PicoLisp is a minimal and pure Lisp dialect created by Alexander
47 Burger. First of all, PicoLisp is a virtual machine architecture,
48 and then a programming language. It is the result of a language
49 design study, trying to answer the question "What is a minimal but
50 useful architecture for a virtual machine?"
52 However, PicoLisp is no academic exercise in language design. It has
53 been used in several commercial and research programming projects
54 since 1988. Its internal structures are simple enough, allowing an
55 experienced programmer always to fully understand what's going on
56 under the hood, and its language features, efficiency and
57 extensibility make it suitable for almost any practical programming
58 task. Some of the outstanding features of PicoLisp are:
60 - Integrated Database :: Database functionality is built into the core
61 of the language. PicoLisp is a database query and manipulation
64 Database entities are first class objects. They are called
65 "external symbols", because they are automatically fetched from
66 database files when accessed, but otherwise behave like normal
69 This fetching from external files is completely transparent, the
70 symbols "are just there", and there is no need (or even a
71 function) to read or write them explicitly. Pilog (a built-in
72 Prolog engine) is used as a query language.
74 It is possible with PicoLisp to build large multi-user databases,
75 distributed across many machines or in a cloud. Such a database
76 system can be optimally fine-tuned, because all its levels are
77 under the developer's control.
79 - Equivalence of Code and Data :: This is actually a feature of Lisp in
80 general. However, PicoLisp really lives it. It makes it easy to write
81 things like the HTML, PostScript or TeX libraries, exploring a syntax
82 of nested function calls. This results in very succinct and precisely
85 For a closer explanation, see the article [[http://picolisp.com/5000/!wiki?EquivalenceCodeData][The Equivalence of Code
88 - Expressiveness :: PicoLisp is a very expressive language. Programs are
89 often much shorter and concise than equivalent programs written in
92 Examples of various programming tasks and their solutions can be
93 found at [[http://rosettacode.org/wiki/Category:PicoLisp][Rosettacode]].
95 - Efficiency :: PicoLisp uses (at least when compared to other Lisps)
96 very little memory, on disk as well as in memory (heap space).
98 For example, the installation size in the OpenWRT distribution is
99 only 575 kB (uncompressed), where the statically linked
100 interpreter with 296 kB takes the largest part. Yet, it includes
101 the full runtime system with interpreter, database, HTTP server,
102 XHTML and JavaScript application framework, watchdog, and the
103 debugger, PostScript and XML libraries.
105 PicoLisp has no compiler, everything starts up very quickly, and
106 code dynamically loaded at runtime (e.g. GUI pages) is
107 immediately ready. Yet, the interpreter is quite fast, usually
108 three times a fast as Python, for example.
110 ** Range of typical uses within Org Mode
111 At first sight, it might not be obvious why Org Mode users should
112 use anything else but Emacs Lisp when writing lisp code blocks. But
113 Picolisp offers at least two features that make it a valuable Org
114 Babel language: its object-oriented database, and its highly
115 efficient framework for interactive web-applications.
117 * Requirements and Setup
118 ** Installation and configuration of PicoLisp software
119 PicoLisp can be downloaded from this [[http://software-lab.de/down.html][download page]]. There is a
120 32-bit version written in C, and a 64-bit version written in
121 assembler. Some GNU/Linux distributions ship with PicoLisp
122 packages, so you might be able to use your package manager for
123 installation. A pure Java version (Ersatz PicoLisp) and a minimal
124 version (Mini PicoLisp) are available too.
126 Detailed and comprehensive installation instructions can be found
127 in the [[http://software-lab.de/INSTALL][INSTALL]] file.
129 ** Emacs configuration
130 The original author of PicoLisp, Alexander Burger, does all his
131 programming work using xterm and vi. PicoLisp is really living
132 the old Unix tradition of simplicity and minimalism.
134 However, there are no editor-wars going on in the PicoLisp
135 community. Several PicoLisp programmers are Emacs users and
136 contributed to Emacs to enable it as PicoLisp editor.
138 After installing PicoLisp, you find the elisp files that constitute
139 the Emacs picolisp-mode in the directory /picolisp/lib/el/. There
140 is a picolisp.el and an inferior-picolisp.el as well as a paredit
143 There is another file called tsm.el. It makes PicoLisp's
144 transient symbols appear in a special way in the source code,
145 reminding the programmer that they look like Strings and are used
146 as Strings, but are not really Strings but just (transient)
149 The README file in the same directory gives the necesary
150 instructions for configuring the PicoLisp mode for Emacs. Since it
151 is not very long, I cite it here:
153 #+BEGIN_SRC emacs-lisp
154 ;; In order to get the picolisp-mode working correctly you have to
155 ;; add the following expressions to your .emacs and adapt them
156 ;; according to your set-up:
158 (add-to-list 'load-path "<path-to>/picoLisp/lib/el")
159 (load "tsm.el") ;; Picolisp TransientSymbolsMarkup (*Tsm)
160 (autoload 'run-picolisp "inferior-picolisp")
161 (autoload 'picolisp-mode "picolisp" "Major mode for editing
163 ;; pil is more modern than plmod
164 (setq picolisp-program-name "<path-to>/picoLisp/plmod")
166 ;; If you have also SLIME installed, it will suck all possible lisp
167 ;; extensions up (greedy bastard).
168 ;; So in order to get the correct file-association for picolisp
169 ;; files you'll have to also add this:
171 (add-to-list 'auto-mode-alist '("\\.l$" . picolisp-mode))
173 ;; If you want, you can add a few hooks for convenience:
175 (add-hook 'picolisp-mode-hook
177 (paredit-mode +1) ;; Loads paredit mode automatically
178 (tsm-mode) ;; Enables TSM
179 (define-key picolisp-mode-map (kbd "RET") 'newline-and-indent)
180 (define-key picolisp-mode-map (kbd "C-h") 'paredit-backward-delete) ) )
183 ;; By the way, don't forget to patch your paredit.el (v21) with the
184 ;; patch provided to get a smoother editing.
188 ** Org-mode configuration (org-babel-do-load-languages)
189 The ob-picolisp.el file is part of Emacs now. To activate PicoLisp
190 as an org-babel language, simply add (picolisp . t) to the
191 org-babel-do-load-languages function in your Emacs configuration
192 file, like shown below:
194 #+BEGIN_SRC emacs-lisp
195 ;; activating picolisp as org babel language
196 (org-babel-do-load-languages
197 'org-babel-load-languages (quote ((emacs-lisp . t)
203 * Org Mode Features for PicoLisp Source Code Blocks
206 ob-picolisp supports external evaluation as well as session-based
207 evaluation of PicoLisp source blocks.
208 *** Typical use for sessions
209 Sessions preserve state, therefore the use of sessions in PicoLisp
210 just like in Emacs Lisp makes sense whenever the computations rely
212 ** Header Arguments and Result Types
213 *** Language-specific default values
214 Depending on the kind of table data you work with, it might be
215 convenient to set the following default header argument:
217 #+BEGIN_SRC emacs-lisp
218 ;; optionally declare default header arguments for this language
219 (defvar org-babel-default-header-args:picolisp
220 '((:colnames . "no"))
221 "Default arguments for evaluating a picolisp source block.")
224 *** Language-specific header arguments
225 There are no language specific header arguments for PicoLisp.
227 *** Combinations of header-args and result types
228 Many combinations of header arguments and result types are
229 supported by ob-picolisp. Like always in combinatorics, the number
230 of possible combinations increases rapidly when there are several
231 factors with several levels each that can be freely combined.
233 The following table shows combinations of header arguments and
234 result types that might make sense for a language like PicoLisp.
235 Many (but nor all) of them have been tried successfully with
236 ob-picolisp source blocks.
238 #+name: header-args-combinations
239 | evaluation | collection | type |
240 | (:session) | (:results) | (:results) |
241 |------------+------------+-------------------|
242 | external | value | table (vector) |
243 | | | scalar (verbatim) |
250 | | output | table (vector) |
251 | | | scalar (verbatim) |
258 | session | value | table (vector) |
259 | | | scalar (verbatim) |
266 | | output | table (vector) |
267 | | | scalar (verbatim) |
276 More special header arguments and their possible values are
277 summarized in the next table:
279 #+name: other-header-args
281 | header-arg | | values | | |
282 |------------+----------+---------+----------+---------|
283 | :results | silent | replace | append | prepend |
284 | (handling) | | | | |
285 | :exports | code | results | both | none |
286 | :comments | yes | (no?) | | |
287 | :noweb | no | yes | | |
288 | :tangle | yes | no | filename | |
289 | :no-expand | | | | |
292 | :cache | no | yes | | |
294 | :hlines | no | yes | | |
295 | :colnames | nil | no | yes | |
296 | :rownames | no | yes | | |
297 | :shebang | "string" | | | |
298 | :eval | never | query | | |
302 *** Differences from other supported languages
303 PicoLisp as an Org Babel language works quite similar like its
304 close relatives Emacs Lisp and Scheme, for example.
306 However, there is one characteristic that really sets it aparts from
307 other supported languages: PicoLisp is not only a language, it _is_ a
308 (object-oriented) database and a web-framework. Unlike other
309 languages, that _have_ (external) frameworks and database drivers,
310 these features are deeply integrated inside the PicoLisp application
313 As Alexander Burger describes it in [[http://software-lab.de/dbui.html][A Unifying
314 Language for Database And User Interface Development]]:
317 : Databases and user interfaces are separate
318 : worlds: Existing class libraries are concerned about
319 : visual effects and event handling, but not about
320 : application logic and database maintenance. It is the
321 : programmer's responsibility to write glue code that
322 : displays data in corresponding GUI fields, detects
323 : modifications by the user, validates them, writes changes
324 : back to the database, and does other housekeeping.
326 : [PicoLisp is] a language and programming
327 : environment that closes [this] semantic gap, by unifying
328 : database and user interface into a single application
334 The [[http://software-lab.de/doc/tut.html][PicoLisp Tutorial]] has two versions of the notorious "Hello World"
335 function, one without arguments, the other with one argument:
337 #+BEGIN_SRC picolisp :exports both :results output
340 (prinl "Hello World"))
345 #+BEGIN_SRC picolisp :exports both :results output
347 (de hello-one-arg (X)
350 (hello-one-arg "Argument")
354 PicoLisp can be used, just like Emacs Lisp, as an efficient
355 scripting language inside of Org Mode documents. Due to its smart
356 and powerfull abstractions, much can be achieved in a few lines of
359 From a PicoLisp programmer's point of view, the integration of the
360 language into Org Babel might be usefull for literate programming
361 (e.g. writing well documented PicoLisp libraries or PicoLisp
362 related papers) or for convenient database report building (making
363 use of Org Mode's multi-language environment and export
366 From an Org Mode user's and/or Emacs Lisp programmer's point of
367 view, two use cases might be of special interest:
369 - use PicoLisp as a _real_ (object-oriented) database replacement
370 for things like bbdb and eieio, i.e. as a tool for
371 object-oriented lisp programming that can handle _big_ (even
372 replicated) databases, offers a powerfull prolog-based query
373 language (Pilog) and _speed_ (see [[http://picolisp.com/5000/!wiki?NeedForSpeed][The Need for Speed]]).
374 - use the PicoLisp application server framework to enable
375 interactive web-development with Org Mode, i.e. combine the
376 static html-export facilities of Org Mode with PicoLisp's ability
377 to produce html-forms that communicate directly with an
378 underlying PicoLisp database.
380 These two use cases are still a bit theoretical, some investigation
381 and experimentation has to be done that hopefully lead to the
382 production of related tutorials on Worg in the future.
384 ** Links to tutorials and other resources
385 Although not all aspects of PicoLisp are documented and the (often
386 surprinsingly short) source code must be used as ultimate reference in
387 some cases, there are many interesting and well written documents
390 The one-stop-shop for everything with regards to PicoLisp is the
391 [[http://picolisp.com/5000/!wiki?home][PicoLisp Wiki]]. There is a [[mailto:picolisp@software-lab.de?subject%3DSubscribe][PicoLisp Mailing List]] too, as well as an IRC
394 For programmers who want to learn more about PicoLisp, I would suggest
395 to first read Paul Graham's essay [[http://paulgraham.com/hundred.html][The Hundred-Year Language]], to get
396 the general idea what PicoLisp is all about. Then, a [[http://software-lab.de/radical.pdf][A Radical Approach
397 to Application Development (PDF)]] and [[http://software-lab.de/dbui.html][A Unifying Language for Database
398 And User Interface Development]] are the next logical steps to learn
399 more about the philosophy behind PicoLisp.
401 The [[http://software-lab.de/doc/ref.html][PicoLisp Reference]] and the [[http://software-lab.de/doc/tut.html][PicoLisp Tutorial]] are the main
402 references when it comes to 'hands on' experience with the language.
403 Henrik Sarvell's introduction [[http://www.prodevtips.com/2008/03/28/pico-lisp/]["At a First Glance"]] is a very helpfull
406 The [[http://software-lab.de/doc/app.html][PicoLisp Application Development]] guide explains in great detail,
407 how amazingly easy and efficient web-programming with PicoLisp can be.
408 There is much more information available, just have a look at the
409 PicoLisp wiki yourself.