Changes between Version 2 and Version 3 of LispNotation

Apr 4, 2012, 12:36:44 PM (10 years ago)



  • LispNotation

    v2 v3  
    131131What is ''the type'' of this expression? Well, it is a ''table'', '''and''' it is an ''associative list'', '''and''' it is a ''list of pairs'', '''and''' it is ''list of lists''.
    133 What is underlying representation of this? Bunch of tags and pointers.)
     133What is ''underlying machine representation'' of this? Lets call it a ''bunch of tags and pointers'' for now.)
     135Now lets consider some ''functions''
     137y = x^2
     141f(x) = x^2
     143Some famous function have their own names such as ''sin'' or ''cos'' or ''exp'' or ''sqrt'' but the wast majority are nameless, anonymous, too ordinary.
     145The way to represent a function without name is by writing down its body:
     147x * x
     149or in the ''prefix notation''
     151(* x x)
     153So, an ''expression'' (of a function) is mere a ''list'' of ''symbols''. Symbols are just ''names'' of (''tags'' or ''pointers'' to) something, their meaning are their ''values'' - what is behind a name.
     155To evaluate an ''expression'' is to get the ''value'' of that expression. For a ''symbol'' (a ''name'') it will be its ''value'' (a ''number'' or a ''list'' - another ''expression''). There is no limit. It is called recursion.
     157There is some special notation in Math for anonymous functions - the ''lambda notation''. Because it is boring to write Greek symbols on qwerty-keyboard, people are using the word ''lambda'' instead with the same meaning:
     159(lambda (x)
     160        (* x x))
     162which means "there is a procedure without a name, with one parameter named 'x' which multiplies it by itself".
     164This ''lambda expression'' then (which is a mere list of lists) is the ''special form'' to define a procedure without a name. 
     166Now, how to evaluate a procedure without a name? The only way is just to write it down here and then invoke it with an actual value (3):
     168((lambda (x)
     169         (* x x))
     170         3)
     172This is the small miracle of the ''prefix notation'' - this is why we write {{{(* x x)}}} instead of {{{(x * x)}}}.
     174The reason is that the ''body'' of a procedure (which is a list of expressions) always comes as the ''first element'' ('''car''') of the invocation expression (which is a list itself).
     176The rest ('''cdr''') of the invocation expression is the ''list'' of ''values'' of parameters of a procedure. This list could be ''infinite'' (it is limited only by hardware) or even ''undefined'' (to be produced at the time of invocation ''on demand'').
     178Now lets say it: '''To square something is to multiply it by itself'''.
     180; the definition of square:
     183;         \     |
     184(define (square x) (* x x))
     185;                  /  |  \
     186;            MULTIPLY IT BY ITSELF
     188Which is just an abbreviation for: define a procedure named ''square''
     189to be a multiplication of the parameter named ''x'' by itself:
     191;              WITH AN ARGUMENT
     192;                  /   NAMED X
     193(define square
     194        (lambda (x) (* x x)))
     195;          |           |
     196;   MAKE A PROCEDURE   |
     197;                      |
     198;             THAT RETURNS THE
     199;             RESULT OF
     200;             MULTIPLYING X BY X
     202Everything is a list of expressions (of lists). This is the symbolic
     203representation (using the prefix notation) of.. of everything. Code is
     204a list of expressions, expressions are lists themselves. Code is data.
     206This is called the unity of the language.