Org Mode support for PicoLisp
However, PicoLisp is no academic exercise in language design. It has been used in several commercial and research programming projects since 1988. Its internal structures are simple enough, allowing an experienced programmer always to fully understand what's going on under the hood, and its language features, efficiency and extensibility make it suitable for almost any practical programming task. Some of the outstanding features of PicoLisp are:
Database entities are first class objects. They are called "external symbols", because they are automatically fetched from database files when accessed, but otherwise behave like normal symbols.
This fetching from external files is completely transparent, the symbols "are just there", and there is no need (or even a function) to read or write them explicitly. Pilog (a built-in Prolog engine) is used as a query language.
It is possible with PicoLisp to build large multi-user databases, distributed across many machines or in a cloud. Such a database system can be optimally fine-tuned, because all its levels are under the developer's control.
For a closer explanation, see the article The Equivalence of Code and Data.
Examples of various programming tasks and their solutions can be found at Rosettacode.
PicoLisp has no compiler, everything starts up very quickly, and code dynamically loaded at runtime (e.g. GUI pages) is immediately ready. Yet, the interpreter is quite fast, usually three times a fast as Python, for example.
At first sight, it might not be obvious why Org Mode users should use anything else but Emacs Lisp when writing lisp code blocks. But Picolisp offers at least two features that make it a valuable Org Babel language: its object-oriented database, and its highly efficient framework for interactive web-applications.
PicoLisp can be downloaded from this download page. There is a 32-bit version written in C, and a 64-bit version written in assembler. Some GNU/Linux distributions ship with PicoLisp packages, so you might be able to use your package manager for installation. A pure Java version (Ersatz PicoLisp) and a minimal version (Mini PicoLisp) are available too.
Detailed and comprehensive installation instructions can be found in the INSTALL file.
The original author of PicoLisp, Alexander Burger, does all his programming work using xterm and vi. PicoLisp is really living the old Unix tradition of simplicity and minimalism.
However, there are no editor-wars going on in the PicoLisp community. Several PicoLisp programmers are Emacs users and contributed to Emacs to enable it as PicoLisp editor.
After installing PicoLisp, you find the elisp files that constitute the Emacs picolisp-mode in the directory picolisp/lib/el. There is a picolisp.el and an inferior-picolisp.el as well as a paredit patch.
There is another file called tsm.el. It makes PicoLisp's transient symbols appear in a special way in the source code, reminding the programmer that they look like Strings and are used as Strings, but are not really Strings but just (transient) Symbols.
The README file in the same directory gives the necesary instructions for configuring the PicoLisp mode for Emacs. Since it is not very long, I cite it here:
#+BEGIN_SRC emacs-lisp ;; In order to get the picolisp-mode working correctly you have to ;; add the following expressions to your .emacs and adapt them ;; according to your set-up:
(add-to-list 'load-path "/picoLisp/lib/el") (load "tsm.el") ;; Picolisp TransientSymbolsMarkup (*Tsm) (autoload 'run-picolisp "inferior-picolisp") (autoload 'picolisp-mode "picolisp" "Major mode for editing Picolisp." t) ;; pil is more modern than plmod (setq picolisp-program-name "/picoLisp/plmod")
;; If you have also SLIME installed, it will suck all possible lisp ;; extensions up (greedy bastard). ;; So in order to get the correct file-association for picolisp ;; files you'll have to also add this:
(add-to-list 'auto-mode-alist '("\\.l$" . picolisp-mode))
;; If you want, you can add a few hooks for convenience:
(add-hook 'picolisp-mode-hook (lambda () (paredit-mode +1) ;; Loads paredit mode automatically (tsm-mode) ;; Enables TSM (define-key picolisp-mode-map (kbd "RET") 'newline-and-indent) (define-key picolisp-mode-map (kbd "C-h") 'paredit-backward-delete) ) )
;; By the way, don't forget to patch your paredit.el (v21) with the ;; patch provided to get a smoother editing. #+END_SRC
The ob-picolisp.el file is part of Emacs now. To activate PicoLisp as an org-babel language, simply add (picolisp . t) to the org-babel-do-load-languages function in your Emacs configuration file, like shown below:
#+BEGIN_SRC emacs-lisp ;; activating picolisp as org babel language (org-babel-do-load-languages 'org-babel-load-languages (quote ((emacs-lisp . t) (picolisp . t) (R . t) (python . t)))) #+END_SRC
ob-picolisp supports external evaluation as well as session-based evaluation of PicoLisp source blocks. Sessions preserve state, therefore the use of sessions in PicoLisp just like in Emacs Lisp makes sense whenever the computations rely on changing state. Depending on the kind of table data you work with, it might be convenient to set the following default header argument:
#+BEGIN_SRC emacs-lisp ;; optionally declare default header arguments for this language (defvar org-babel-default-header-args:picolisp '((:colnames . "no")) "Default arguments for evaluating a picolisp source block.") #+END_SRC
There are no language specific header arguments for PicoLisp.
Many combinations of header arguments and result types are supported by ob-picolisp. Like always in combinatorics, the number of possible combinations increases rapidly when there are several factors with several levels each that can be freely combined.
The following table shows combinations of header arguments and result types that might make sense for a language like PicoLisp. Many (but nor all) of them have been tried successfully with ob-picolisp source blocks.
#+name: header-args-combinations | evaluation | collection | type | | (:session) | (:results) | (:results) | |------------+------------+-------------------| | external | value | table (vector) | | | | scalar (verbatim) | | | | file | | | | raw (org) | | | | html | | | | latex | | | | code | | | | pp | | | output | table (vector) | | | | scalar (verbatim) | | | | file | | | | raw (org) | | | | html | | | | latex | | | | code | | | | pp | | session | value | table (vector) | | | | scalar (verbatim) | | | | file | | | | raw (org) | | | | html | | | | latex | | | | code | | | | pp | | | output | table (vector) | | | | scalar (verbatim) | | | | file | | | | raw (org) | | | | html | | | | latex | | | | code | | | | pp |
More special header arguments and their possible values are summarized in the next table:
| header-arg | | values | | | |------------+----------+---------+----------+---------| | :results | silent | replace | append | prepend | | (handling) | | | | | | :exports | code | results | both | none | | :comments | yes | (no?) | | | | :noweb | no | yes | | | | :tangle | yes | no | filename | | | :no-expand | | | | | | :file | | | | | | :dir | | | | | | :cache | no | yes | | | | :var | x=y | | | | | :hlines | no | yes | | | | :colnames | nil | no | yes | | | :rownames | no | yes | | | | :shebang | "string" | | | | | :eval | never | query | | |
PicoLisp as an Org Babel language works quite similar like its close relatives Emacs Lisp and Scheme, for example.
However, there is one characteristic that really sets it aparts from other supported languages: PicoLisp is not only a language, it is a (object-oriented) database and a web-framework. Unlike other languages, that have (external) frameworks and database drivers, these features are deeply integrated inside the PicoLisp application server framework.
As Alexander Burger describes it in A Unifying Language for Database And User Interface Development:
: Databases and user interfaces are separate
: worlds: Existing class libraries are concerned about
: visual effects and event handling, but not about
: application logic and database maintenance. It is the
: programmer's responsibility to write glue code that
: displays data in corresponding GUI fields, detects
: modifications by the user, validates them, writes changes
: back to the database, and does other housekeeping.
: [PicoLisp is] a language and programming
: environment that closes [this] semantic gap, by unifying
: database and user interface into a single application
: server framework.
The PicoLisp Tutorial has two versions of the notorious "Hello World" function, one without arguments, the other with one argument:
# no arguments (de hello-no-args () (prinl "Hello World")) (hello-no-args)
# with one argument (de hello-one-arg (X) (prinl "Hello " X) ) (hello-one-arg "Argument")
PicoLisp can be used, just like Emacs Lisp, as an efficient scripting language inside of Org Mode documents. Due to its smart and powerfull abstractions, much can be achieved in a few lines of code.
From a PicoLisp programmer's point of view, the integration of the language into Org Babel might be usefull for literate programming (e.g. writing well documented PicoLisp libraries or PicoLisp related papers) or for convenient database report building (making use of Org Mode's multi-language environment and export facilities).
From an Org Mode user's and/or Emacs Lisp programmer's point of view, two use cases might be of special interest:
These two use cases are still a bit theoretical, some investigation and experimentation has to be done that hopefully lead to the production of related tutorials on Worg in the future.
Although not all aspects of PicoLisp are documented and the (often surprinsingly short) source code must be used as ultimate reference in some cases, there are many interesting and well written documents available.
For programmers who want to learn more about PicoLisp, I would suggest to first read Paul Graham's essay The Hundred-Year Language, to get the general idea what PicoLisp is all about. Then, a A Radical Approach to Application Development (PDF) and A Unifying Language for Database And User Interface Development are the next logical steps to learn more about the philosophy behind PicoLisp.
The PicoLisp Reference and the PicoLisp Tutorial are the main references when it comes to 'hands on' experience with the language. Henrik Sarvell's introduction "At a First Glance" is a very helpfull beginners guide too.
The PicoLisp Application Development guide explains in great detail, how amazingly easy and efficient web-programming with PicoLisp can be. There is much more information available, just have a look at the PicoLisp wiki yourself.