Chapter 1 : Command Line
pantalla1.png

Picolisp REPL is very powerful. Alexander Burger, the original author of PicoLisp, uses only the REPL plus a small editor (vi) to develop all of his programs and PicoLisp itself.

If you like the Unix way of doing things, you'll love the REPL.

Anyway, there are people like me, that are used to use a full featured IDE. For those, the picolisp-mode for Emacs is wonderful and rich of features.

We'll teach both styles throughout this chapter, so you can choose.

Installing PicoLisp

Installing PicoLisp is just a matter of uncompressing the tgz archive to some directory, and start using it. Download picoLisp.tgz from here, and just write this in a shell:

cd directory_where_downloaded
tar xvfz picoLisp.tgz

If you've got a 32 bit, you need to compile the 32 bit version under src:

cd src
make

If you prefer the 64bit versions just do:

cd src64
make
info.png

The 32 and 64 bits versions of PicoLisp are completely different implementations of the same language. The 32bits one is made in C, while the 64bits one is made in assembler. The reasons for doing so are various, and, contrary to what you may think, the main reason was not speed, but because the assembler is better to express low level algorithms. You can read more about this in the doc64/README file of the distribution. Even that, we estimate an improvement of around 30% of speed in the 64 bits version.

Global installation

For global installation, you generally just make two symlinks from where picolisp is installed to /usr or /usr/local. For example:

$ ln -s /<installdir> /usr/lib/picolisp
$ ln -s /usr/lib/picolisp/bin/picolisp /usr/bin/picolisp

Anyway, the program which is started is picolisp, which is the minimum usable. You'll need to use some libraries at any point, so when doing your scripts you should include a special line which we'll describe later in this chapter.

In general, it is recomended to not use this way of calling PicoLisp except for scripts. It is better to just call it with relative paths, as explained in the next section.

Running PicoLisp from the shell

PicoLisp is designed to be working with both relative and global calls. There is no classpath in the style of Java.
When using relative paths, you must make sure you are working in the right directory. For this example, just do:

cd picoLisp

Next step is to run the program, and here you have to choose too:

  • running p is the recommended way for production versions of your program.
  • running dbg includes debug libraries and ways to call vim inside the REPL.
  • if you use picolisp-mode (for Emacs, as we describe later) you just don't worry, as Emacs calls a special version called pilmode.

For the purpose of this section, just execute dbg as it is very convenient:

# ./dbg

and the interpreter will be avaiable to run.

Whenever you want to run a program made by you or others, all what you need to do is just call path_to_p/p your_program_name.

info.png

You might be thinking why PicoLisp doesn't use a classpath like other scripting languages and Java do. It is because we always follow the principle of minimum complexity. You'll find this very convenient when distributing your program, because picolisp is so small that there is no need to worry to include the interpreter with it.

Some REPL usage

Just for the purpose of you learning how to directly use the interpreter, let us practice a little. Insert these commands in the REPL:

: (+ 1 2 3)

Once you press enter, the expression will be executed, and will show you a return value. After that, the prompt will ask you to enter another command. Something similar to this is what you should be watching now:

: (+ 1 2 3)
-> 6
:

Using the REPL plus Vim for interactive development (unix way)

This section if for those preferring Vim over Emacs. If you are not sure if you prefer using Vim or Emacs, then you should skip this section and go in with Emacs, as Emacs is easier to use for a novice.

By "unix way", I mean using small tools and the shell as a glue, for developing picoLisp applications, in contrast to the Emacs way.

picoLisp is very well integrated with Vim. In fact, most parts of picoLisp has been edited using Vim. A tipical session consist on two or three terminal sessions plus a browser if you use the GUI. If you prefer using a graphical interface for Vim (like gvim), you can substitute one terminal with it.

Here is an image of a typical session (made by Alex Burger, original author of picoLisp):

vimsession.png

There is a long terminal (the whole height of the screen) on the left side, and another terminal on the bottom right.
The terminal on the right has the REPL, and it is started/stopped very often, dropping back to the shell etc.

You usually start applications using:

/dbg xxx/main.l

And GUI applications (using the server and a browser):

vimsession2.png
./dbg xxx/main.l -main -go

The 'go' function waits until a browser connects, then shows the ':' prompt.
And, while navigating with the browser through the application, you can inspect data, forms, set breakpoints and more in the REPL. So this is a very nice interactive development environment.

If you modify some parts of the source, hit Enter in the REPL, then restart ./dbg xxx/main.l … from the shell for a new try. This way, the application is usually very short-lived, but the editor can be open all day long.

Using Emacs for interactive development

Making you own scripts

#!/usr/bin/picolisp /usr/lib/picolisp/lib.l

This is because it needs to know where to find the libraries. The executable just extracts the path from the first argument and thus knows where to find the libraries you'll specify later in the code. We'll explain this in more detail later.

Unless otherwise stated, the content of this page is licensed under Creative Commons Attribution-NonCommercial-ShareAlike 3.0 License