PicoLisp for Python and Chicken Scheme programmers


Introduction

PicoLisp is a powerful virtual machine and programming language which can be sufficiently called 'learn one for all' language. It is an extremely speedy Lisp interpreter with a small memory footprint having a simple structure with just three datatypes (Numbers, Symbols, Lists) yet complete in design as well as in execution. Thus it is simple to learn, simple to use and simple to maintain.

Because of its transparent architecture, a programmer needs to only understand it thoroughly as the language itself is very efficient and extensible. Truly it has the potential to make students clear all major, intricate Computer Science concepts, thus giving a major impetus for learning while practically doing programming. Alexander Burger (the brain and heart behind PicoLisp) well mentions that "it is not just a toy of theoretical value".

Hello, world!

PICOLISP
(prinl "Hello, world!")


Chicken
(print "Hello, world!")


Python
print "Hello, world!"

Definitions, assignment and bindings

PICOLISP
Variables are symbols.
(let A 0 A) 


Chicken
Defining a variable:
(define a 0)


Assigning a variable a value:
(set! a 0)


PS: CHICKEN automatically defines a global variable when a variable is set without being defined. However, it is best practice (and most compatible with other Schemes) to define all variables.

Binding a value to a variable: (let ((a 0)) a)

Python
Python has only one operator for both assignments and definitions of variables (=).
a = 0

Strings

Concatenation

PICOLISP
(pack "1" "2")


Chicken
(string-append "1" "2")

(conc "1" "2")

(string-intersperse '("1" "2") "")


Python
a = "1" + "2"

a = "".join(["1", "2"])

Splitting a string

PICOLISP
(mapcar pack (split (chop "this is a string") " "))


Chicken
(string-split "this is a string")


Python
"this is a string".split()

File I/O

Reading the contents of a file and returning a string

PICOLISP
(in "my-file.txt" (till NIL T))


Chicken
(read-all "my-file.txt")


read-all is defined in Unit utils.

Python
open("my-file.txt").read() # Deprecated

with open("my-file.txt") as f:
    f.read() 

Reading the contents of a file and returning a list of lines

PICOLISP
(in "my-file.txt" (make (until (eof) (link (line T)))))


Chicken
(read-lines "my-file.txt")


read-lines is defined in Unit utils.

Python
open("my-file.txt").readlines()

with open("my-file.txt") as f:
    f.readlines()

Conditionals

Single condition

PICOLISP
(if (< 1 2) "yes" "no")


Chicken
(if (< 1 2) "yes" "no")


PS: in Scheme, the result of the evaluation of an if form is passed to its continuation.

Python
"yes" if 1<2 else "no"

Multiple conditions

PICOLISP
(cond ((< 1 2) "1 < 2")
      ((> 1 2) "1 > 2")
      (T "1 = 2"))


Chicken
(cond ((< 1 2) "1 < 2")
      ((> 1 2) "1 > 2")
      (else "1 = 2"))


PS: in Scheme, the result of the evaluation of a cond form is passed to its continuation.

Python
result = None
if 1 < 2:
    result = "1 < 2"
elif 1 > 2:
    result = "1 > 2"
else:
    result = "1 = 2"

Iteration

Iterating through and printing the elements of a list

PICOLISP
(for L (1 2 3 4) (printsp L))


Chicken
(define l '(1 2 3 4))
(for-each print l)


Python
l = [1, 2, 3, 4]
for i in l:
    print i

Applying a procedure/function to each item of a list

PICOLISP
(setq L (1 2 3 4))

(de add10 (N) (+ N 10))

(mapcar add10 L)


Chicken
(define l '(1 2 3 4))

(define (add10 N) (+ N 10))

(map add10 l)


Python
l = [1, 2, 3, 4]

def add10(n):
    return n + 10

[ add10(i) for i in l ]


I am extremely thankful to the PicoLisp creator, Alexander Burger for suggesting improvements in this document.

Examples taken from https://wiki.call-cc.org/chicken-for-python-programmers.





https://picolisp.com/wiki/?picolispforpythonandchickenschemeprogrammers

23aug17   yumaikas