PicoLisp Crash Course - Level 0

PicoLisp Crash Course - Level 0


Learning PicoLisp Lightening Fast.

Reading the following examples you can understand a lot of PicoLisp very fast !
Though, much more to learn is on the way!

#####################################
## crash course on PicoLisp (Level 0)
#####################################

#####################################

## Making Arithmetics (Simple)

#####################################
(+ 3 4)
(- 4 3)
(* 4 3)

: (setq *Scl 3)
-> 3
: (*/ 2.1 3.0 1.0)
-> 6300
: (format (*/ 2.1 3.0 1.0) *Scl)
-> "6.300"

#####################

## Define Variables

#####################
(setq a0 12)
(setq a1 "hello")
(setq a2 '(11 22 33 44))
(setq var-add '((x y)(+ x y)))
(setq var-sub '((x y)(- x y)))
(setq var-mult '((x y)(* x y)))

#######################

## Printing Variables 

#######################
(println a0)
(println a1)
(println a2)
(println var-add)

########################

# Printing Results

########################
: (println a0)
12
-> 12
: (println a1)
"hello"
-> "hello"
: (println a2)
(11 22 33 44)
-> (11 22 33 44)
: (println var-add)
((x y) (+ x y))
-> ((x y) (+ x y))
#######################

#########################

## Reading Information 

#########################
: (setq a1 (read))
hello
-> hello
: a1
-> hello
: (setq a2 (line T))
hello my friend Tom
-> "hello my friend Tom"
: a2
-> "hello my friend Tom"

###########################################

# Calling Functions Saved Into Variables

###########################################
(var-add 2 3)
(var-sub 6 4)
(var-mult 3 4)

#########################
## Results Of Calling Functions
#########################
: (var-add 2 3)
-> 5
: (var-sub 6 4)
-> 2
: (var-mult 3 4)
-> 12

###############################

## Making Decisions (Simple)

###############################
## if
(let x 0  (if (> x 1) "True" "False"))
(let x 10 (if (> x 0)(println "x > 0")(println "x < 0")))

## ifn -> if not
(let x 0  (ifn (> x 1) "True" "False"))
(let x 10 (ifn (> x 0)(println "x < 0")(println "x > 0")))

## cond
(let x 22
   (cond
      ((= x 0) "Zero")
      ((= x 1) "One")
      ((= x 2) "Two")
      "Uknown Number!" ) )
-> "Uknown Number!"


###########################

## Looping Constructs

###########################
(for i 3 (println "hello"))
(for i '(1 22 33)(println i))
(do 4 (println "hello"))
(let q 3 (loop (println q)(T (=0 (dec 'q)) 'Done)))

(let x 0
     (while(< x 6)
           (print x) (setq x (+ x 1))))

(let x 0
     (until(> x 5)
              (println x)(setq x (+ x 1))))

########################

# Function Definition

########################
(de h1() "hello")
(de h2(msg) msg)
(de h3() (print "hello"))
(de h4(msg)(print msg))
(de h5 @ (while(args) (next)(print(arg))))

######################

## File Manipulation

######################
###################
## Appending A File
###################
(de appendFile(filename data)
    (out (pack "+" filename) (print data)))

###########################
## Reading A File
###########################
(de readFile(filename)
    (in filename (while(not(eof))(print(line T)))))