This document provides an overview of the LISP (List Processing) programming language. It discusses how LISP was commonly used for artificial intelligence programming due to its ability to modify programs dynamically. The document then describes various LISP dialects and the invention of LISP by John McCarthy. It also summarizes key LISP features like being machine-independent, providing object-oriented programming and advanced data types. The document concludes by explaining functions, predicates, conditionals, recursion, arrays, property lists, mapping functions and lambda expressions in LISP.
PPT on Analysis Of Algorithms.
The ppt includes Algorithms,notations,analysis,analysis of algorithms,theta notation, big oh notation, omega notation, notation graphs
Artificial Intelligence: Introduction, Typical Applications. State Space Search: Depth Bounded
DFS, Depth First Iterative Deepening. Heuristic Search: Heuristic Functions, Best First Search,
Hill Climbing, Variable Neighborhood Descent, Beam Search, Tabu Search. Optimal Search: A
*
algorithm, Iterative Deepening A*
, Recursive Best First Search, Pruning the CLOSED and OPEN
Lists
PPT on Analysis Of Algorithms.
The ppt includes Algorithms,notations,analysis,analysis of algorithms,theta notation, big oh notation, omega notation, notation graphs
Artificial Intelligence: Introduction, Typical Applications. State Space Search: Depth Bounded
DFS, Depth First Iterative Deepening. Heuristic Search: Heuristic Functions, Best First Search,
Hill Climbing, Variable Neighborhood Descent, Beam Search, Tabu Search. Optimal Search: A
*
algorithm, Iterative Deepening A*
, Recursive Best First Search, Pruning the CLOSED and OPEN
Lists
LISP, an acronym for list processing, is a programming language that was designed for easy manipulation of data strings. It is a commonly used language for artificial intelligence (AI) programming.
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxjane3dyson92312
Assg 05: Quicksort
COSC 2336 Data Structures
Objectives
• Practice writing functions
• Practice writing recursive functions.
• Learn about Analysis of algorithms and O(n log n) sorts
Description
In this assignment we will be implementing one of the most popular sorting
algorithms used in libraries (like the C++ STL library, and the UNIX qsort
function) to provide basic sorting abilities, the Quicksort algorithm. I would
recommend that you at least read section 7.5 from our supplemental Shaffer
textbook on Quicksort, if not sections 7.1-7.5 talking about three well known
O(n log n) sorting algorithms, and the 3 O(n2) algorithms we discussed last
week.
Quicksort, when properly implemented, is very attractive because it pro-
vides a way to do a fast sort completely in-place (without having to allocate
additional memory to do the sort, beyond a single value needed when swap-
ping two values in the list being sorted). In the worst case, Quicksort is
actually O(n2), no better than bubble sort. But this worse case only occurs
when every pivot selected is the wort possible, and does not divide the list
at all. This is very unlikely to happen, unless you know how the pivot is
selected, and specifically design the input list to always choose the worst
possible pivot. On average the cost of Quicksort is O(n log n), and it is
usually very likely that average case performance will result when lists to be
sorted are relatively random.
The most direct implementation of Quicksort is as a recursive algorithm.
Quicksort is an example of a divide and conquer approach to solving the
problem of sorting the list. We are given a list of items, A and indexes left
1
and right that indicate a sub-portion of the list to be sorted. left and right
indicate the actual indexes, so if the list is a regular C array of integers, and
the array is of size 10
int left;
int right;
const inst SIZE = 10;
int A[size];
Then to sort the whole list we set left = 0 and right = 9 to initially
call the Quicksort function:
left = 0;
right = size-1;
quicksort(A, left, right);
Conceptually the steps of the Quicksort algorithm are as follows:
1. if list size is 0 or 1 (left <= right) return (lists of this size are sorted
by definition).
2. Choose a pivot value and swap the pivot value to the end of the list
swap(pivotIndex, right)
3. Partition the list. Partitioning means all values less than the pivot
value should end up on the left of the list, and all values greater will
be on the right. The first index k where a value >= to the pivot value
is at indicates the new left and right side sub-lists.
4. Swap the pivot value to its correct position k swap(k, right)
5. Recursively call Quicksort on the new left and right sub-lists
• quicksort(A, left, k-1)
• quicksort(A, k+1, right)
Most of the real work happens in the function/code to partition the list.
The partitioning of the list, for Quicksort to be an in-place sort, must work
by swapping values in-place in the list o.
Assg 05 QuicksortCOSC 2336 Data StructuresObjectives.docxfestockton
Assg 05: Quicksort
COSC 2336 Data Structures
Objectives
• Practice writing functions
• Practice writing recursive functions.
• Learn about Analysis of algorithms and O(n log n) sorts
Description
In this assignment we will be implementing one of the most popular sorting
algorithms used in libraries (like the C++ STL library, and the UNIX qsort
function) to provide basic sorting abilities, the Quicksort algorithm. I would
recommend that you at least read section 7.5 from our supplemental Shaffer
textbook on Quicksort, if not sections 7.1-7.5 talking about three well known
O(n log n) sorting algorithms, and the 3 O(n2) algorithms we discussed last
week.
Quicksort, when properly implemented, is very attractive because it pro-
vides a way to do a fast sort completely in-place (without having to allocate
additional memory to do the sort, beyond a single value needed when swap-
ping two values in the list being sorted). In the worst case, Quicksort is
actually O(n2), no better than bubble sort. But this worse case only occurs
when every pivot selected is the wort possible, and does not divide the list
at all. This is very unlikely to happen, unless you know how the pivot is
selected, and specifically design the input list to always choose the worst
possible pivot. On average the cost of Quicksort is O(n log n), and it is
usually very likely that average case performance will result when lists to be
sorted are relatively random.
The most direct implementation of Quicksort is as a recursive algorithm.
Quicksort is an example of a divide and conquer approach to solving the
problem of sorting the list. We are given a list of items, A and indexes left
1
and right that indicate a sub-portion of the list to be sorted. left and right
indicate the actual indexes, so if the list is a regular C array of integers, and
the array is of size 10
int left;
int right;
const inst SIZE = 10;
int A[size];
Then to sort the whole list we set left = 0 and right = 9 to initially
call the Quicksort function:
left = 0;
right = size-1;
quicksort(A, left, right);
Conceptually the steps of the Quicksort algorithm are as follows:
1. if list size is 0 or 1 (left <= right) return (lists of this size are sorted
by definition).
2. Choose a pivot value and swap the pivot value to the end of the list
swap(pivotIndex, right)
3. Partition the list. Partitioning means all values less than the pivot
value should end up on the left of the list, and all values greater will
be on the right. The first index k where a value >= to the pivot value
is at indicates the new left and right side sub-lists.
4. Swap the pivot value to its correct position k swap(k, right)
5. Recursively call Quicksort on the new left and right sub-lists
• quicksort(A, left, k-1)
• quicksort(A, k+1, right)
Most of the real work happens in the function/code to partition the list.
The partitioning of the list, for Quicksort to be an in-place sort, must work
by swapping values in-place in the list o ...
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala - Part 2Philip Schwarz
(download for perfect quality) See aggregation functions defined inductively and implemented using recursion.
Learn how in many cases, tail-recursion and the accumulator trick can be used to avoid stack-overflow errors.
Watch as general aggregation is implemented and see duality theorems capturing the relationship between left folds and right folds.
Through the work of Sergei Winitzki and Richard Bird.
Folding Unfolded - Polyglot FP for Fun and Profit - Haskell and Scala Part 2 ...Philip Schwarz
(download for perfect quality) See aggregation functions defined inductively and implemented using recursion.
Learn how in many cases, tail-recursion and the accumulator trick can be used to avoid stack-overflow errors.
Watch as general aggregation is implemented and see duality theorems capturing the relationship between left folds and right folds.
Through the work of Sergei Winitzki and Richard Bird.
This version corrects the following issues:
slide 32: = reverse --> reverse =
Slide 33: 100_000 -> 1_000_000
It also adds slides 36, 37 and 38
This first assignment will focus on coding in Python, applying kno.docxabhi353063
This first assignment will focus on coding in Python, applying knowledge students should already have about programming with functions and arrays. When the assignment is complete, there will in fact be some indirect recursion, but that needs not complicate the assignment, if each function is allowed to assume that all other functions are implemented correctly.
Problem Description
Several years of experience in algebra probably yields a consistent interpretation of the expression
12 - 2 * 5 +3
Most would expect that the multiplication would be the first operation, followed by a subtraction, and then an addition, yielding a value of 5. Performing those three operations in any other order would yield very different results.
When a programmer places such an expression into a program, they would expect it to perform the same series of operations. The interpreter or compiler making sense of the expression then must be able to construct the correct meaning of the input. Often one will hear of this behavior called
parsing
.
Assignment Specifications
The input for this assignment will arrive as an instantiated
Python list
consisting of
tokens
, where each token is either an integer numeral or an operator. An additional symbol (such as a semicolon) will appear at the end of the list to mark the end of the input.
The Python list has a great deal in common with the C++ array, and this assignment will treat it as such. One will be able to use an integer subscript to examine each element of the list, just as one could examine consecutive array elements. The next assignment will use a different approach to visit the elements of the list.
Implementation Hints
One very simple method of parsing input is termed
predictive parsing
in which each function has an idea of what it expects to see next (or what alternatives it will encounter). For example, we would expect a numeric expression like the one above to include a series of values to be added or subtracted. Whether those values are explicit numbers (such as 12 and 3) or the results of other operations (such as 2*5) might sound like a complication, but that can just be addressed by some other function.
The pseudocode for parsing a sum expression would therefore look something like this:
to evaluate a sum expression (series of zero or more additions and subtractions): evaluate a product expression (zero or more multiplications and divisions) while the next token is a + or - operator evaluate the product expression that follows the operator perform the addition or subtraction
For the given example, the first product expression would simply be the value 12. This is followed by a minus sign, so the next product is evaluated to be 10, which is subtracted from 12 to yield 2. Since this is followed by a plus sign, the loop would repeat to evaluate and add the 3. No more operators appear, so the final result is 5.
The above specifications said that some other symbol would appear at the very end of the input. Thi ...
ECS140A-F16-07 October 27, 2016ASSIGNMENT 5 LISPDue .docxSALU18
ECS140A-F16-07 October 27, 2016
ASSIGNMENT 5: LISP
Due: November 8, 2016
Overview
The purpose of this assignment is for you to gain some experience designing and implementing
LISP programs. This assignment explores only a few of the many interesting LISP features.
This assignment is broken into several parts. The first part is a fairly straightforward LISP
warmup. The second part continues the warmup. The third part involves writing your own ver-
sion of the standard LISP function every; the remaining parts will use your function. The fourth
part illustrates the standard technique of car-cdr recursion. The remaining parts involve writing
functions that rewrite LISP expressions. More specifically, these parts takes as input a LISP
expression and produces as output another, possibly different LISP expression. The modified
expression will be semantically equivalent to the original, but it will use if’s rather than cond’s.
N.B., you are restricted as to which LISP functions you are allowed to use for various parts of this
assignment. See “Notes” for details.
1
ECS140A-F16-07 October 27, 2016
Part 1: The Cross1 Functions
Write the following three functions.
cross1-recursive (x y)
cross1-iterative (x y)
cross1-mapcar (x y)
If x or y is not a list, the function returns nil. Otherwise, each of these returns the list con-
sisting of pairs, one pair for each element of x; each pair contains as its first element an ele-
ment of x and as its second element the entire list y. The overall order of the list follows the
order from x. For example,
(cross1-recursive ’(1 2) ’(a b c))
returns
((1 (a b c)) (2 (a b c)))
cross1-recursive is to be written recursively, cross1-iterative is to be written iteratively
using either ‘go’ or ‘do’, and cross1-mapcar is to be written using ‘mapcar’.
Part 2: The Cross2 Functions
Write the following three functions.
cross2-recursive (x y)
cross2-iterative (x y)
cross2-mapcar (x y)
If x or y is not a list, the function returns nil. Otherwise, each of these returns the usual
2-dimensional cross-product of x and y. The overall order of the list follows the order from
x. For example,
(cross2-recursive ’(1 2) ’(a b c))
returns
((1 a) (1 b) (1 c) (2 a) (2 b) (2 c))
cross2-recursive is to be written recursively, cross2-iterative is to be written iteratively
using either ‘go’ or ‘do’, and cross1-mapcar is to be written using ‘mapcar’.
If you want, cross2-recursive can use cross1-recursive, cross1-iterative can use cross1-iterative,
and cross1-mapcar can use cross1-mapcar. However, doing so didn’t simplify my solutions.
Hint: for cross2-mapcar, use the “apply-append trick” (see text). In fact, there’s a nice one-line
solution that uses the apply-append trick and lambda expressions, but don’t fret about getting that
solution; get something working first.
2
ECS140A-F16-07 October 27, 2016
Part 3: The my-every Function
The LISP predicate every returns t or nil to indicate whether a gi ...
How to Make a Field invisible in Odoo 17Celine George
It is possible to hide or invisible some fields in odoo. Commonly using “invisible” attribute in the field definition to invisible the fields. This slide will show how to make a field invisible in odoo 17.
Unit 8 - Information and Communication Technology (Paper I).pdfThiyagu K
This slides describes the basic concepts of ICT, basics of Email, Emerging Technology and Digital Initiatives in Education. This presentations aligns with the UGC Paper I syllabus.
The Art Pastor's Guide to Sabbath | Steve ThomasonSteve Thomason
What is the purpose of the Sabbath Law in the Torah. It is interesting to compare how the context of the law shifts from Exodus to Deuteronomy. Who gets to rest, and why?
We all have good and bad thoughts from time to time and situation to situation. We are bombarded daily with spiraling thoughts(both negative and positive) creating all-consuming feel , making us difficult to manage with associated suffering. Good thoughts are like our Mob Signal (Positive thought) amidst noise(negative thought) in the atmosphere. Negative thoughts like noise outweigh positive thoughts. These thoughts often create unwanted confusion, trouble, stress and frustration in our mind as well as chaos in our physical world. Negative thoughts are also known as “distorted thinking”.
Instructions for Submissions thorugh G- Classroom.pptxJheel Barad
This presentation provides a briefing on how to upload submissions and documents in Google Classroom. It was prepared as part of an orientation for new Sainik School in-service teacher trainees. As a training officer, my goal is to ensure that you are comfortable and proficient with this essential tool for managing assignments and fostering student engagement.
The Indian economy is classified into different sectors to simplify the analysis and understanding of economic activities. For Class 10, it's essential to grasp the sectors of the Indian economy, understand their characteristics, and recognize their importance. This guide will provide detailed notes on the Sectors of the Indian Economy Class 10, using specific long-tail keywords to enhance comprehension.
For more information, visit-www.vavaclasses.com
This is a presentation by Dada Robert in a Your Skill Boost masterclass organised by the Excellence Foundation for South Sudan (EFSS) on Saturday, the 25th and Sunday, the 26th of May 2024.
He discussed the concept of quality improvement, emphasizing its applicability to various aspects of life, including personal, project, and program improvements. He defined quality as doing the right thing at the right time in the right way to achieve the best possible results and discussed the concept of the "gap" between what we know and what we do, and how this gap represents the areas we need to improve. He explained the scientific approach to quality improvement, which involves systematic performance analysis, testing and learning, and implementing change ideas. He also highlighted the importance of client focus and a team approach to quality improvement.
2024.06.01 Introducing a competency framework for languag learning materials ...Sandy Millin
http://sandymillin.wordpress.com/iateflwebinar2024
Published classroom materials form the basis of syllabuses, drive teacher professional development, and have a potentially huge influence on learners, teachers and education systems. All teachers also create their own materials, whether a few sentences on a blackboard, a highly-structured fully-realised online course, or anything in between. Despite this, the knowledge and skills needed to create effective language learning materials are rarely part of teacher training, and are mostly learnt by trial and error.
Knowledge and skills frameworks, generally called competency frameworks, for ELT teachers, trainers and managers have existed for a few years now. However, until I created one for my MA dissertation, there wasn’t one drawing together what we need to know and do to be able to effectively produce language learning materials.
This webinar will introduce you to my framework, highlighting the key competencies I identified from my research. It will also show how anybody involved in language teaching (any language, not just English!), teacher training, managing schools or developing language learning materials can benefit from using the framework.
2. SYLLABUS
– Introduction
– Manipulation of functions in LISP
– Definition of functions
– Predicates and conditionals
– The conditional COND
– Iteration and recursion
– Property lists and arrays
– Mapping functions
– Lambda functions and internal storage.
3. Introduction
– LISP became a common language for artificial intelligence (AI) programming, partly
owing to the confluence of LISP and AI work at MIT and partly because AI programs
capable of “learning” could be written in LISP as self-modifying programs.
– LISP has evolved through numerous dialects, such as Scheme and Common LISP.
– John McCarthy invented LISP in 1958, shortly after the development of FORTRAN. It
was first implemented by Steve Russell on an IBM 704 computer.
– It is particularly suitable for Artificial Intelligence programs, as it processes symbolic
information effectively.
– Common Lisp originated, during the 1980s and 1990s, in an attempt to unify the
work of several implementation groups that were successors to Maclisp, like
ZetaLisp and NIL (New Implementation of Lisp) etc.
4. Cont….
– It serves as a common language, which can be easily extended for specific
implementation.
– Programs written in Common LISP do not depend on machine-specific
characteristics, such as word length etc.
5. Features of Common LISP
– It is machine-independent
– It uses iterative design methodology, and easy extensibility.
– It allows updating the programs dynamically.
– It provides high level debugging.
– It provides advanced object-oriented programming.
– It provides a convenient macro system.
– It provides wide-ranging data types like, objects, structures, lists, vectors, adjustable
arrays, hash-tables, and symbols.
– It is expression-based.
6. Cont….
– It provides an object-oriented condition system.
– It provides a complete I/O library.
– It provides extensive control structures.
7. Manipulation of functions in LISP
– The following table provides some commonly used list manipulating functions.
– Sr.No.
– Function & Description
– 1.car
– It takes a list as argument, and returns its first element.
– 2.cdr
– It takes a list as argument, and returns a list without the first element
8. Cont….
– 3.cons
– It takes two arguments, an element and a list and returns a list with the element
inserted at the first place.
– 4.list
– It takes any number of arguments and returns a list with the arguments as member
elements of the list.
– 5.append
– It merges two or more list into one.
– 6.last
– It takes a list and returns a list containing the last element.
9. Cont…
– 7.member
– It takes two arguments of which the second must be a list, if the first argument
is a member of the second argument, and then it returns the remainder of the
list beginning with the first argument.
– 8.reverse
– It takes a list and returns a list with the top elements in reverse order.
10. Definition of functions
– The macro named defun is used for defining functions. The defun macro needs
three arguments −
– Name of the function
– Parameters of the function
– Body of the function
– Syntax for defun is −
– (defun name (parameter-list) "Optional documentation string." body)
11. Example 1
– Let's write a function named averagenum that will print the average of four
numbers. We will send these numbers as parameters.
– Create a new source code file named main.lisp and type the following code in it.
– (defun averagenum (n1 n2 n3 n4)
– (/ ( + n1 n2 n3 n4) 4)
– )
– (write(averagenum 10 20 30 40))
– When you execute the code, it returns the following result −
– 25
12. Predicates and conditionals
– Sr.No.Predicate & Description
– 1 atom
– It takes one argument and returns t if the argument is an atom or nil if otherwise.
– 2.equal
– It takes two arguments and returns t if they are structurally equal or nil otherwise.
– 3.eq
– It takes two arguments and returns t if they are same identical objects, sharing the
same memory location or nil otherwise.
13. Cont…..
– 4.eql
– It takes two arguments and returns t if the arguments are eq, or if they are numbers
of the same type with the same value, or if they are character objects that represent
the same character, or nil otherwise.
– 5.evenp
– It takes one numeric argument and returns t if the argument is even number or nil if
otherwise.
– 7.zerop
– It takes one numeric argument and returns t if the argument is zero or nil if
otherwise.
14. Cont…
– 8.null
– It takes one argument and returns t if the argument evaluates to nil, otherwise
it returns nil.
– 9.listp
– It takes one argument and returns t if the argument evaluates to a list otherwise
it returns nil.
– 10.greaterp
– It takes one or more argument and returns t if either there is a single argument
or the arguments are successively larger from left to right, or nil if otherwise.
15. Cont…
– 11.lessp
– It takes one or more argument and returns t if either there is a single argument or the
arguments are successively smaller from left to right, or nil if otherwise.
– 12.numberp
– It takes one argument and returns t if the argument is a number or nil if otherwise.
– 13.symbolp
– It takes one argument and returns t if the argument is a symbol otherwise it returns nil.
– 14.integerp
– It takes one argument and returns t if the argument is an integer otherwise it returns nil.
16. Cont…
– 15.rationalp
– It takes one argument and returns t if the argument is rational number, either a ratio or a
number, otherwise it returns nil.
– 16.floatp
– It takes one argument and returns t if the argument is a floating point number otherwise it
returns nil.
– 17.realp
– It takes one argument and returns t if the argument is a real number otherwise it returns nil.
– 18.complexp
– It takes one argument and returns t if the argument is a complex number otherwise it returns
nil.
17. Cont….
– 19..characterp
– It takes one argument and returns t if the argument is a character otherwise it returns nil.
– 20.stringp
– It takes one argument and returns t if the argument is a string object otherwise it returns nil.
– 21.arrayp
– It takes one argument and returns t if the argument is an array object otherwise it returns nil.
– 22.packagep
– It takes one argument and returns t if the argument is a package otherwise it returns nil.
18. The conditional COND
– The cond construct in LISP is most commonly used to permit branching.
– Syntax for cond is −
– (cond (test1 action1)
– (test2 action2)
– ...
– (testn actionn))
19. Cont….
– Each clause within the cond statement consists of a conditional test and an
action to be performed.
– If the first test following cond, test1, is evaluated to be true, then the related
action part, action1, is executed, its value is returned and the rest of the clauses
are skipped over.
– If test1 evaluates to be nil, then control moves to the second clause without
executing action1, and the same process is followed.
– If none of the test conditions are evaluated to be true, then the cond statement
returns nil.
20. Example
Create a new source code file named
main.lisp and type the following code in it −
– (setq a 10)
– (cond ((> a 20)
– (format t "~% a is greater than 20"))
– (t (format t "~% value of a is ~d " a)))
– When you click the Execute button, or type Ctrl+E, LISP executes it immediately
and the result returned is −
– value of a is 10
21. Iteration and recursion
– A program is called recursive when an entity calls itself. A program is call iterative
when there is a loop (or repetition).
– Example: Program to find the factorial of a number
– // C++ program to find factorial of given number
– #include<bits/stdc++.h>
– using namespace std;
–
– // ----- Recursion -----
– // method to find factorial of given number
– int factorialUsingRecursion(int n)
22. Cont….
– {
– if (n == 0)
– return 1;
– // recursion call
– return n * factorialUsingRecursion(n - 1);
– }
– // ----- Iteration -----
– // Method to find the factorial of a given number
– int factorialUsingIteration(int n)
23. Cont…
– {
– int res = 1, i;
– // using iteration
– for (i = 2; i <= n; i++)
– res *= i;
– return res;
– }
24. Cont…
– // Driver method
– int main()
– {
– int num = 5;
– cout << "Factorial of " << num <<
– " using Recursion is: " <<
– factorialUsingRecursion(5) << endl;
–
25. Cont…
– cout << "Factorial of " << num <<
– " using Iteration is: " <<
– factorialUsingIteration(5);
– return 0;
– }
26. Property lists and arrays
– LISP allows you to define single or multiple-dimension arrays using the make-
array function. An array can store any LISP object as its elements.
– All arrays consist of contiguous memory locations. The lowest address corresponds
to the first element and the highest address to the last element.
– he number of dimensions of an array is called its rank.
– In LISP, an array element is specified by a sequence of non-negative integer indices.
The length of the sequence must equal the rank of the array. Indexing starts from
zero.
– For example, to create an array with 10- cells, named my-array, we can write −
– (setf my-array (make-array '(10)))
28. Cont….
– The aref function allows accessing the contents of the cells. It takes two
arguments, the name of the array and the index value.
– For example, to access the content of the tenth cell, we write −
– (aref my-array 9)
29. The Property List
– Since its inception, Lisp has associated with each symbol a kind of tabular data
structure called a property list (plist for short). A property list contains zero or more
entries; each entry associates with a key (called the indicator), which is typically a
symbol, an arbitrary Lisp object (called the value or, sometimes, the property).
There are no duplications among the indicators; a property list may only have one
property at a time with a given name. In this way, given a symbol and an indicator
(another symbol), an associated value can be retrieved.
– A property list is very similar in purpose to an association list. The difference is that a
property list is an object with a unique identity; the operations for adding and
removing property-list entries are destructive operations that alter the property list
rather than making a new one. Association lists, on the other hand, are normally
augmented non-destructively (without side effects) by adding new entries to the
front (see acons and pairlis).
30. Cont….
– A property list is implemented as a memory cell containing a list with an even
number (possibly zero) of elements. (Usually this memory cell is the property-list
cell of a symbol, but any memory cell acceptable to setf can be used if getf and remf
are used.) Each pair of elements in the list constitutes an entry; the first item is the
indicator, and the second is the value. Because property-list functions are given the
symbol and not the list itself, modifications to the property list can be recorded by
storing back into the property-list cell of the symbol.
– When a symbol is created, its property list is initially empty. Properties are created
by using get within a setf form.
– Common Lisp does not use a symbol's property list as extensively as earlier Lisp
implementations did. Less-used data, such as compiler, debugging, and
documentation information, is kept on property lists in Common Lisp.
31. Mapping functions
– Mapping functions are a group of functions that could be applied successively to
one or more lists of elements. The results of applying these functions to a list are
placed in a new list and that new list is returned.
– For example, the mapcar function processes successive elements of one or more
lists.
– The first argument of the mapcar function should be a function and the remaining
arguments are the list(s) to which the function is applied.
– The argument function is applied to the successive elements that results into a
newly constructed list. If the argument lists are not equal in length, then the process
of mapping stops upon reaching the end of the shortest list. The resulting list will
have the same number of elements as the shortest input list.
32. Lambda functions and internal
storage
– At times you may need a function in only one place in your program and the
function is so trivial that you may not give it a name, or may not like to store it
in the symbol table, and would rather write an unnamed or anonymous
function.
– LISP allows you to write anonymous functions that are evaluated only when
they are encountered in the program. These functions are called Lambda
functions.
– You can create such functions using the lambda expression. The syntax for the
lambda expression is as follows −
33. Cont….
– (lambda (parameters) body)
– A lambda form cannot be evaluated and it must appear only where LISP expects to find a function.
– Example
– Create a new source code file named main.lisp and type the following code in it.
– (write ((lambda (a b c x)
– (+ (* a (* x x)) (* b x) c))
– 4 2 9 3)
– )
– When you execute the code, it returns the following result −
– 51
34. Internal storage
– "Lisp" is a family of languages, not a single language. Many languages in the family (e.g.,
Common Lisp) don't specify the internal representations, but rather the contract that the
structures and functions have to preserve. In the case of cons, it's roughly the equations:
– (car (cons x y)) == x
– (cdr (cons x y)) == y
– and the requirement that cons returns a new object each time it's called. In some Lisps, cons
cells are immutable, and so the requirement that a new object is returned isn't present.
– Of course, there are actually implementations, and they do actually have to store things, and
it's not unreasonable to ask how they do that. In general, it's probably best to think of a cons
cell as a structure big enough to hold two pointers, and probably some information holding its
type (so that it can be recognized as a cons cell). The pointers used by the implementaiton
might be tagged, though, so that if, e.g., the first three bits are some special values, the
"pointer" can be recognized as the encoding of some primitive value.