Jump to content

Functional programming -- 2009-2010 -- info.uvt.ro/Laboratory/Tools

From Wikiversity


Functional programming (Spring 2010):

Overview

[edit]
PLT Scheme
GNU CLISP
PuTTY
SciTE
  • Lisp aware text editor for Windows and Linux;
  • SciTE -- official site;
NotePad++

How to work with PLT Scheme

[edit]
Using DrScheme (recommended)

DrScheme is a nice graphical shell that allows us to interact with PLT Scheme.

First we must start it:

  1. we can start it either by searching its icon on the desktop or through the Start Menu -> Applications for Windows or by searching it inside the Applications -> Programming in (Ubuntu) Linux (the logo is );
  2. we have to check if the version is at least 4.x.x (in previous versions it was numbered like 372, and there were radical changes between 3xx and 4.x.x); to check this we can look inside the Help -> About DrScheme;
    • another way to check the version is to enter the (version) statement inside the textbox in the lower-half of the window;
  3. please note that in our laboratories the 4.x.x version of PLT Scheme in available only from the NetBoot Linux, and must be started by typing /opt/plt/drscheme & in a terminal, then closing the terminal;

Analyzing the DrScheme user interface we can see:

  • the menu with the options File, Edit, ...;
  • the toolbar with some buttons Save, ..., Check Syntax, Run, Stop;
  • a textbox, in the upper half of the window, with the #lang scheme text in there -- this is the source code editor;
  • another textbox, in the lower half of the window, with a Welcome ... message -- this is the shell;

Usually we use DrScheme as follows:

  • for simple expressions and experiments we use the shell window where we just write the code, press enter and we see the result;
  • for more complex exercises we use the text editor to write the source code (do not remove the #lang scheme text from the beginning of the file):
    1. we first define any functions or constants we need (like (define (sum a b) (+ a b)));
    2. then we make sure that we call the functions and we also printout their result (like (print (sum 1 2)));
    3. and finally we just press the Run button from the toolbar;
    4. (in case our application refuses to finish (because we made an infinite loop) we can just press the Stop button);
    5. after we made sure everything works right we can just save our work by pressing the Save button; the usual extensions for Scheme files are ss or scm (please note that in our laboratories, and in general on any Linux, you are allowed to save files only inside your home-folder (the default location proposed to you by the save dialog));
Using MzScheme

MzScheme is another shell that allows us to interact with the PLT Scheme, but aside from DrScheme this is a console shell. (It is also used to allow us to run unattended Scheme scripts.)

To start it we need:

  1. to open a terminal, in Windows we start the cmd.exe from the Run... menu, and under Linux we can choose the Terminal option from the Applications -> System Tools menu;
  2. we have to check if the version is at least 4.x.x (in previous versions it was numbered like 372, and there were radical changes between 3xx and 4.x.x); to check this we run the command mzscheme --version inside the terminal;
    • another way to check the version is to enter the (version) statement inside the shell if we have started it by just typing mzscheme
  3. please note that in our laboratories the 4.x.x version of PLT Scheme in available only from the NetBoot Linux, and must be started by typing /opt/plt/mzscheme in a terminal;

Using MsScheme shell is quite similar with using DrScheme:

  • for simple expressions we just write the code in the shell and see their outputs;
  • for more complex exercises we usually do the following:
    1. we edit the source code (in another terminal on Linux this can be done with nano, mcedit, emacs or whatever editor feels right for you) (also in Linux we can use a graphical editor like Gedit available from Applications -> Accessories -> Text Editor, and on Windows we could use Scite or NotePad++ presented above):
      1. we first define any functions or constants we need (like (define (sum a b) (+ a b)));
      2. then we make sure that we call the functions and we also printout their result (like (print (sum 1 2)));
      3. we save the file, the usual extensions for Scheme files are ss or scm;
    2. (if we entered mzscheme as presented in the previous steps we need to exit from there by typing (exit));
    3. we just type mzscheme my-program.ss; (or if in our laboratories /opt/plt/bin/mzscheme my-program.ss);

How to work with GNU CLisp

[edit]

To start it we need to open a terminal, in Windows we start the cmd.exe from the Run... menu, and under Linux we can choose the Terminal option from the Applications -> System Tools menu (just like for MzScheme).

Using GNU CLisp shell (just like for MzScheme):

  • for simple expressions we just write the code in the shell and see their outputs;
  • for more complex exercises we usually do the following:
    1. we edit the source code (in another terminal on Linux this can be done with nano, mcedit, emacs or whatever editor feels right for you) (also in Linux we can use a graphical editor like Gedit available from Applications -> Accessories -> Text Editor, and on Windows we could use Scite or NotePad++ presented above):
      1. we first define any functions or constants we need (like (defun sum (a b) (+ a b)));
      2. then we make sure that we call the functions and we also printout their result (like (print (sum 1 2)));
      3. we save the file, the usual extension for Common Lisp files is cl;
    2. (if we entered clisp as presented in the previous steps we need to exit from there by typing (exit));
    3. we just type clisp my-program.cl;