Since there is some much stir around the presentation made by mtsd. (Great
work by the way) I decided it is a good time to put my lightning talk at
FrosCon out there.
Attached is the original version i gave.
Inline is an updated version with more content which could function as a
PicoLisp tutorial or something.
: "PicoLisp" # Hello today i want to talk a bit PicoLisp.
-> "PicoLisp"
: (* 2 1) #In PicoLisp you can multiply.
-> 2
: (* 3 (* 2 1)) # You can combine use the return values to make more
complicated expressions.
-> 6
: (* 4 (* 3 (* 2 1)))
-> 24
: (** 2 (* 5 (* 4 (* 3 (* 2 1))))) # Numbers in PicoLisp are Integers and
they can be as big as you RAM can handle.
-> 1329227995784915872903807060280344576
: (* 5 4 3 2 1) # Some functions in Picolisp take an arbitrary number of
arguements.
-> 120
: (range 1 12) # And of course there are cleverer ways to generale lists
-> (1 2 3 4 5 6 7 8 9 10 11 12)
: (apply * (range 1 6)) # Here we use the multiply function on the list we
generated with 'range
-> 720
: (de fak (N) (apply * (range 1 N))) # Let's define a function
-> fak
: (mapcar fak (range 1 12)) # Let's test the function by applying to the
number 1 to 12
-> (1 2 6 24 120 720 5040 40320 362880 3628800 39916800 479001600)
: fak # But what is 'fal , really?
-> ((N) (apply * (range 1 N)))
: ('((N) (apply * (range 1 N))) 8) # It is a list in RAM and the list can
be executed on it's own.
-> 40320
:(replace fak '(N) '(m)) #This means we can also modify function as f they
are lists
-> ((m) (apply * (range 1 N))) # Truth be told they are actually trees
: (de treeplace (List Old New) # Define a function
which replaces symbols on a tree
(mapcar #For each member of the
list in which Old was Replaced by New
'((X) (if (lst? X) (treeplace X Old New) X)) # Recure on all lists
you see
(replace List Old New)))
-> treeplace
: fak
-> ((N) (apply * (range 1 N))) # This is was fak looked like
: (treeplace fak 1 2) # Multiplying by one is useless
-> ((N) (apply * (range 2 N))) # Tada, we optimed our code
: fak # What is the 'fak now
-> ((N) (apply * (range 1 N))) # Fak has not change since i used
non-destructive operations and did not give 'fak the value
: treeplace
-> ((List Old New) (mapcar '((X) (if (lst? X) (treeplace X Old New) X))
(replace List Old New))) # The code is not really clear. X is not very
descriptive.
: (setq treeplace (treeplace treeplace 'X 'Sub)) # Since we are working
with a sub-expression or sub-tree let's call it that.
-> ((List Old New) (mapcar '((Sub) (if (lst? Sub) (treeplace Sub Old New)
Sub)) (replace List Old New)))
: treeplace # Setq sets the Symbols value
-> ((List Old New) (mapcar '((Sub) (if (lst? Sub) (treeplace Sub Old New)
Sub)) (replace List Old New))) # See it is way more clear what the code
does now.
Sincerely Johann-Tobias Schäg
: "PicoLisp"
-> "PicoLisp"
: (* 2 1)
-> 2
: (* 3 (* 2 1))
-> 6
: (* 4 (* 3 (* 2 1)))
-> 24
: (** 2 (* 4 (* 3 (* 2 1))))
-> 16777216
: (* 5 4 3 2 1)
-> 120
: (range 1 12)
-> (1 2 3 4 5 6 7 8 9 10 11 12)
: (apply * (range 1 6))
-> 720
: (de fak (N) (apply * (range 1 N)))
-> fak
: (mapcar fak (range 1 12))
-> (1 2 6 24 120 720 5040 40320 362880 3628800 39916800 479001600)
: fak
-> ((N) (apply * (range 1 N)))
: ('((N) (apply * (range 1 N)))
8)
-> 40320
: (replace fak '(N) '(m))
-> ((m) (apply * (range 1 N)))
: (de treeplace (List Old New) (mapcar '((X) (if (lst? X) (treeplace X Old New)
X)) (replace List Old New)))
-> treeplace
: fak
-> ((N) (apply * (range 1 N)))
: (treeplace fak 1 2)
-> ((N) (apply * (range 2 N)))
: (setq treeplace (treeplace treeplace 'X 'Sub))
-> ((List Old New) (mapcar '((Sub) (if (lst? Sub) (treeplace Sub Old New) Sub))
(replace List Old New)))