Read This! | Picolisp | Picolisp Machine | Pil Sources | Pil Tutorials | Picolisp By Example | Linux | BASH | C-Programmming | Javascipt | Python | Scheme | Operating Systems | AssemblyLanguage | Computer Security | Firewalls | Exploitation | Social Engineering | Metasploit | Emacs | vim | Pharo Smalltalk | Databases | Networking | Machine Learning | Git | Machine Learning | Algorithms | Open Data Science |

quote

This article is under construction. There will be plenty of errors so please keep it in mind.

quote Quote is probably the most used character/function/macro in lisp. It is central to getting almost anything done. A good place to start is https://picolisp.com/wiki/?ArticleQuote. This article does a pretty good job of explaining things and part of the official picolisp pages. If you want my take on things (it's literally a tour of lisp itself) please read on!

Picolisp defines quote to return all arguments, without evaluating them.

The question is why you would want to do that and what purpose it serves.

Before we get into quote I really feel it is good to recap on the programming model used in most lisps. What exactly is going on and why does it work the way it does?

Quote just happens to be so fundamental we might as well start at the beginning.

In the beginning...

army Humans got inundated with information and the need to transform the information into more and more useful abstractions.

Ancients Kings and Priests need to ask questions like: As we got more and more advanced our questions and abstraction got more and more complicated, yet, in some fundamental way remained the same. Question like: What essentially remained the same is this:
  1. We have some physical or conceptual system
  2. We want to measure & record it in some unified / standard way.
  3. Those collected measurements are called data
  4. We need to need to transform the data into something useful
  5. while we are at it, we might as well give the data and transformations easy to remember names, so that we can easily refer to them.
Lisp is just one of methodologies that allows us to do this is a very simple and uniform manner and it goes like this:

Primitives

Lets deal with the primitives first. We need them to be the 'bottom' of the system. Somewhat like Lego blocks. You use Lego blocks to build what you want, however, you don't build the blocks themselves. No these usually come from the factory.

lego

A curious thing about Lego blocks are that they are so simple that even a little child can conceive of their purpose, their structure and use, yet it would be very difficult to make them. You need a state of the art factory, distribution systems, staff, labour, etc... to make these blocks successfully.

The picolisp environment is something like this factory. Out of the box, comes some pretty sophisticated primitives, easy to understand and use, but not so easy to code from scratch. Neither should you want to for general use.

So we have primitives like, small numbers, big numbers, symbols, cons pairs, lists, functions, etc... that act as a sort of 'bottom' to the system.

And using them is as simple as typing them out. Please try this for best pedagogic effect.

: 1
is simaccording to these three rulesply the number 1 (you should see -> 1) this means the system got and return a 1,
: "Hello Dear Friend"
is just a symbol (that behaves like a string). Your should get it back.
: Hello
ah, something new happens, you get NIL. So now try this,
: 'Hello
and you should get a Hello back. Why? we shall explore a little later I promise.

(Lists Data Code)

Like Lego, a single block, while being something of interest to look and perhaps study is not very useful by itself. The magic only happens when we start connecting them up to build something of value.

In picolisp we do this with lists.

A list is simply something like a string of beads. Where each bead is a primitive. beads
Which doesn't sound so much more useful a single block until your think of DNA, which is also not so dissimilar to a string of beads. And look at what has been created with DNA!
dna
In picolisp we simply write out lists between Brackets with a space between each item in the list. Such as: However if you type this into your picolisp REPL, you probably won't get the results you are expecting. For that you need to quote. Just why, will be explained later in the article.

But what is data and what is code?

The most important insight is the fact that what is data and what is code is mostly a matter of perspective.

Take for example a recipe to bake a cake.


Vanilla Cake cake

INGREDIENTS

175g margarine, 175g sugar, 3 eggs, 175g self-raising flour, sifted 1tsp baking powder 1tsp vanilla extract pinch of salt

METHOD

Heat the oven to 180°C. Lightly grease an 18cm round cake tin with a margarine and cut a piece of greaseproof paper or non-stick baking parchment to fit the base of the tin. Put all the ingredients in a large mixing bowl and beat with a wooden spoon or a hand-held mixer for 1 minute, or until just combined. It's important not to beat the batter too much - just long enough to make it smooth. Pour or spoon the mixture into the tin, smooth the top and bake on the middle shelf of the oven for about 45-50 minutes. The cake is cooked when it looks well risen and golden; the top should spring back when lightly touched with a fingertip. Another test is to insert a skewer into the centre of the cake - it should come out clean. Let the cake sit in the tin for 5 minutes, then gently run a knife around the edge and turn the cake out onto a wire rack to cool. Serve dusted with icing sugar.



Is it code or is it data?

Mostly it is matter of perspective, it is clearly data, your reading it. Currently saved on a file, served to you over the internet. Yet, if you were in your kitchen with the ingredients, ready to bake a cake, it would be code (that is the instructions to transform ingredients into a cake).

It is the same in picolisp. At times we might want to process a list as code. At other times we might just want read it or store it as data, to be used somewhere else at a later time.

That's what quote does. It lets you choose what is data and what is code.

Read, Evaluate, Print, Loop

  1. Just like your brain right now which is this sentence. Picolisp must read each statement that you load/type into it. This is called 'Reading'
  2. and once it has done reading, just like you, it must 'Evaluate' what it has read. What is vikid saying, what does he mean
  3. And to be any use to you, it must report back its finding. This is called 'Print'ing. As it usually prints it back to the screen. You do this automatically, usually by talking to your self in your head.
  4. then finally, why stop there? Just like you, it will read the next sentence, and the next, till it is told to exit. That is called 'Loop'ing
This is what Wikipedia says about it:


In a REPL, the user enters one or more expressions (rather than an entire compilation unit) and the REPL evaluates them and displays the results. The name read–eval–print loop comes from the names of the Lisp primitive functions which implement this functionality:



However there is a problem here in that everything 'read' is 'evaluated' and very often,
you just don't want to do that. We wouldn't want to bake a cake every time we read the recipe would we? :-)

Sometimes you want to read a recipe so that you can decide what you need to buy at the shops in preparation. Sometimes you want to ready a recipe in order to get ideas to write new recipes, for example to make chocolate cake.

Evaluation

PicoLisp tries to evaluate everything entered into the REPL Basically, it does so by applying the following three rules:
  1. A number evaluates to itself.
  2. A symbol evaluates to its value
  3. A list is evaluated as a function call
    • the first element of the list is considered as the function
    • the rest of the elements are considered data to the function
    • This data is in turn evaluated using the same 3 rules
  4. For a full explanation read the reference.



    To be continued...

http:///wiki/?pilquote

25jun17   admin