mitthögskolan 10/8/2015 1 common lisp lists. mitthögskolan 10/8/2015 2lists n lists are one of the...

39
Mitthögskolan 07/04/22 Common Lisp Common Lisp LISTS LISTS

Upload: stewart-ellis

Post on 20-Jan-2016

213 views

Category:

Documents


0 download

TRANSCRIPT

Page 1: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 1

Common LispCommon LispLISTSLISTS

Page 2: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 2

ListsLists Lists are one of the fundamental data Lists are one of the fundamental data

structures in Lisp.structures in Lisp. However, it is not the only data structure.However, it is not the only data structure. Common Lisp has moved on from being Common Lisp has moved on from being

merely a LISt Processor.merely a LISt Processor.

Page 3: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 3

ConsesConses

What cons really does is combines two objects What cons really does is combines two objects into a two-part object called a into a two-part object called a conscons..

Conceptually, a cons is a pair of pointers.Conceptually, a cons is a pair of pointers. The first one is the car, and the second is the cdr.The first one is the car, and the second is the cdr. Conses provide a convenient representation for Conses provide a convenient representation for

pairs of any type.pairs of any type. The two halves of a cons can point to any kind of The two halves of a cons can point to any kind of

object, including conses.object, including conses. This is the mechanism for building lists.This is the mechanism for building lists.

Page 4: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 4

PairsPairs

Lists in CL are defined as pairs.Lists in CL are defined as pairs. Any non empty list can be considered as a Any non empty list can be considered as a

pair of the first element and the rest of the pair of the first element and the rest of the list.list.

We use one half of the cons to point to the We use one half of the cons to point to the first element of the list, and the other to first element of the list, and the other to point to the rest of the list (which is either point to the rest of the list (which is either another cons or nil).another cons or nil).

Page 5: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 5

Box notationBox notation

nil

a

A one element list (A)

nil

a b c

A list of 3 elements (A B C)

Page 6: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 6

What sort of list is this?What sort of list is this?

nil

a d

b c

> (setf z (list ‘a (list ‘b ‘c) ‘d)) (A (B C) D)

Page 7: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 7

Lists of listsLists of lists

Given z is (A (B C) D)Given z is (A (B C) D) What value is returned here?What value is returned here?

– > (car (cdr z))> (car (cdr z))

Page 8: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 8

ConspConsp The function The function consp consp returns true if its returns true if its

argument is a cons.argument is a cons. So listp could be defined:So listp could be defined:

(defun our-listp (x)(defun our-listp (x)

(or (null x) (consp x)))(or (null x) (consp x))) Since everything that is not a cons is an Since everything that is not a cons is an

atom, the predicate atom, the predicate atomatom could be defined: could be defined:

(defun out-atom (x) (not (consp x)))(defun out-atom (x) (not (consp x))) Remember, Remember, nilnil is both an is both an atomatom and a and a list list..

Page 9: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 9

EqualityEquality

Each time you call cons, Lisp allocates a new Each time you call cons, Lisp allocates a new piece of memory with room for two pointers. piece of memory with room for two pointers.

So if we call cons twice with the same So if we call cons twice with the same arguments, we get back two values that look arguments, we get back two values that look the same, but are in fact distinct objects:the same, but are in fact distinct objects:

> (eql (cons ‘a nil) (cons ‘a nil))> (eql (cons ‘a nil) (cons ‘a nil))

NILNIL

Page 10: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 10

EqualEqual

We also need to be able to ask whether two lists have the We also need to be able to ask whether two lists have the same elements.same elements.

CL provides an equality CL provides an equality predicatepredicate for this, for this, equalequal.. eql returns true only if its arguments are the same object,eql returns true only if its arguments are the same object, equal, more or less, returns true if its arguments would equal, more or less, returns true if its arguments would

print the same.print the same.

> (equal (cons ‘a nil) (cons ‘a nil))> (equal (cons ‘a nil) (cons ‘a nil))

TT Note: if x and y are eql, they are also equal.Note: if x and y are eql, they are also equal.

Page 11: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 11

Why Lisp has no pointersWhy Lisp has no pointers

One of the secrets to understanding Lisp is One of the secrets to understanding Lisp is to realize that variables have values in the to realize that variables have values in the same way that lists have elements.same way that lists have elements.

As conses have pointers to their elements, As conses have pointers to their elements, variables have pointers to their values.variables have pointers to their values.

Page 12: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 12

Pointers to valuesPointers to values

What happens, for example, when we set What happens, for example, when we set two variables to the same list:two variables to the same list:

> (setf x ‘(a b c))> (setf x ‘(a b c))

(A B C)(A B C)

> (setf y x)> (setf y x)

(A B C)(A B C)

Page 13: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 13

The location in memory associated with the The location in memory associated with the variable x does not contain the list itself, but variable x does not contain the list itself, but a pointer to it.a pointer to it.

When we assign the same value to y, Lisp When we assign the same value to y, Lisp copies the pointer, not the list.copies the pointer, not the list.

Therefore, what would the value ofTherefore, what would the value of

> (eql x y)> (eql x y)

be, T or NIL?be, T or NIL?

Page 14: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 14

Building ListsBuilding Lists

The function The function copy-listcopy-list takes a list and takes a list and returns a copy of it.returns a copy of it.

The new list will have the same elements, The new list will have the same elements, but contained in new conses.but contained in new conses.

> (setf x ‘(a b c)> (setf x ‘(a b c)

y (copy-list x))y (copy-list x))

(A B C)(A B C) Spend a few minutes to draw a box diagram Spend a few minutes to draw a box diagram

of x and y to show where the pointers point.of x and y to show where the pointers point.

Page 15: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 15

AppendAppend

The Common Lisp function The Common Lisp function appendappend returns returns the concatenation of any number of lists:the concatenation of any number of lists:

> (append ‘(a b) ‘(c d) ‘(e))> (append ‘(a b) ‘(c d) ‘(e))

(A B C D E)(A B C D E) AppendAppend copies all the arguments except the copies all the arguments except the

last.last.

Page 16: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 16

List access functionsList access functions

To find the element at a given position in a To find the element at a given position in a list we call the function list we call the function nthnth..

> (nth 0 ‘(a b c))> (nth 0 ‘(a b c))

AA and to find the and to find the nnth cdr, we call th cdr, we call nthcdrnthcdr..

> (nthcdr 2 ‘(a b c))> (nthcdr 2 ‘(a b c))

(C)(C) Both nth and nthcdr are zero indexed.Both nth and nthcdr are zero indexed.

Page 17: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 17

Zerop and LastZerop and Last

The function The function zeropzerop returns true if its argument is returns true if its argument is zero.zero.

> (zerop 0)> (zerop 0)

TT The function The function lastlast returns the last cons in a list. returns the last cons in a list.

> (last ‘(a b c))> (last ‘(a b c))

(C)(C) We also have: We also have: firstfirst, , secondsecond ... ... tenthtenth, and, and ccxxr, where r, where xx is a string of up to four is a string of up to four aas or s or dds.s.

Page 18: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 18

Mapping functionsMapping functions Common Lisp provides several mapping Common Lisp provides several mapping

functions.functions. Mapcar Mapcar is the most frequently used.is the most frequently used. It takes a function and one or more lists, It takes a function and one or more lists,

and returns the result of applying the and returns the result of applying the function to elements taken from each list, function to elements taken from each list, until one of the list runs out:until one of the list runs out:

Page 19: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 19

> (mapcar #’(lambda (x) (+ x 10))> (mapcar #’(lambda (x) (+ x 10))

‘ ‘(1 2 3))(1 2 3))

(11 12 13)(11 12 13)

> (mapcar #’list> (mapcar #’list

‘ ‘(a b c)(a b c)

‘ ‘(1 2 3 4))(1 2 3 4))

((A 1) (B 2) (C 3))((A 1) (B 2) (C 3))

Page 20: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 20

MaplistMaplist The related function The related function maplistmaplist takes the same takes the same

arguments, but calls the function on arguments, but calls the function on successive cdrs of the lists:successive cdrs of the lists:

> (maplist #’(lambda (x) x)> (maplist #’(lambda (x) x)

‘ ‘(a b c))(a b c))

((A B C) (B C) (C))((A B C) (B C) (C)) There is also There is also mapcanmapcan and and mapcmapc. Use the . Use the

on-line on-line Common Lisp the Language Common Lisp the Language to to discover what these mapping functions do.discover what these mapping functions do.

Page 21: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 21

Keyword argumentsKeyword arguments

> (member ‘b ‘(a b c))> (member ‘b ‘(a b c))

(B C)(B C) Member Member returns true, but instead of simply returns true, but instead of simply

returning returning tt, its returns the part of the list , its returns the part of the list beginning with the object it was looking for.beginning with the object it was looking for.

By default, By default, membermember compares objects using compares objects using eql.eql.

You can override this behavior by You can override this behavior by employing a employing a keyword keyword argument.argument.

Page 22: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 22

An example of a An example of a keywordkeyword argument is argument is :test.:test. If we pass some function as the :test If we pass some function as the :test

argument in a call to member, than that argument in a call to member, than that function will be used to test for equality function will be used to test for equality instead of instead of eqleql..

> (member ‘(a) ‘((a) (z)) :test #’equal)> (member ‘(a) ‘((a) (z)) :test #’equal)

((A) (Z))((A) (Z)) KeywordKeyword arguments are always optional. arguments are always optional.

Page 23: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 23

Another Another keywordkeyword argument accepted by argument accepted by member is a member is a :key :key argument.argument.

This allows you to specify a function to be This allows you to specify a function to be applied to each element before comparison:applied to each element before comparison:

> (member ‘a ‘((a b) (c d)) :key #’car)> (member ‘a ‘((a b) (c d)) :key #’car)

((A B) (C D))((A B) (C D))

Page 24: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 24

Member-ifMember-if

If we want to find an element satisfying an If we want to find an element satisfying an arbitrary predicate we use the function arbitrary predicate we use the function member-ifmember-if::

> (member-if #’oddp ‘(2 3 5))> (member-if #’oddp ‘(2 3 5))

(3 5)(3 5)

Page 25: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 25

adjoinadjoin

The function The function adjoinadjoin is like a conditional is like a conditional conscons..

It takes an object and a list, and conses the It takes an object and a list, and conses the object onto the list only if it is not already a object onto the list only if it is not already a member:member:

> (adjoin ‘b ‘(a b c))> (adjoin ‘b ‘(a b c))

(A B C)(A B C)

> (adjoin ‘z ‘(a b c))> (adjoin ‘z ‘(a b c))

(Z A B C)(Z A B C)

Page 26: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 26

SetsSets

CL has the functions, CL has the functions, unionunion, , intersectionintersection, and , and set-set-differencedifference for performing set operations on lists. for performing set operations on lists.

These functions expect exactly two lists and also These functions expect exactly two lists and also the same the same keywordkeyword arguments as arguments as membermember..

Remember, there is no notion of ordering in a set. Remember, there is no notion of ordering in a set. These functions won’t necessarily preserve the These functions won’t necessarily preserve the order of the two lists.order of the two lists.

Give me an example of a call to Give me an example of a call to unionunion. Show the . Show the arguments and the return value.arguments and the return value.

Page 27: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 27

SortSort

Common Lisp has a built in function called Common Lisp has a built in function called sortsort.. It takes a sequence and a comparison function of It takes a sequence and a comparison function of

two arguments, and returns a sequence with the two arguments, and returns a sequence with the same elements, sorted according to the function:same elements, sorted according to the function:

> (sort ‘(0 2 1 3 8) #’>)> (sort ‘(0 2 1 3 8) #’>)

(8 3 2 1 0)(8 3 2 1 0) Sort is destructiveSort is destructive!!!! What can you do if you don’t want your list What can you do if you don’t want your list

modified?modified?

Page 28: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 28

Every and SomeEvery and Some

The functions The functions everyevery and and somesome take a predicate and one or more take a predicate and one or more sequences.sequences.

When given just one sequence, they test whether the elements satisfy When given just one sequence, they test whether the elements satisfy the predicate:the predicate:

> (every #’oddp ‘(1 3 5))> (every #’oddp ‘(1 3 5))

TT

> (some #’evenp ‘(1 2 3))> (some #’evenp ‘(1 2 3))

TT If they are given more than one sequence, the predicate must take as If they are given more than one sequence, the predicate must take as

many arguments as there are sequences, and arguments are drawn one many arguments as there are sequences, and arguments are drawn one at a time from all the sequences:at a time from all the sequences:

> (every #’> ‘(1 3 5) ‘(0 2 4))> (every #’> ‘(1 3 5) ‘(0 2 4))

TT

Page 29: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 29

Push and PopPush and Pop

The representation of lists as conses makes it The representation of lists as conses makes it natural to use them as pushdown stacks.natural to use them as pushdown stacks.

This is done so often that CL provides two macros This is done so often that CL provides two macros for the purpose,for the purpose, push push, and , and poppop..

Both are defined in terms of Both are defined in terms of setfsetf..

(push obj lst)(push obj lst)

is the same asis the same as

(setf lst (cons obj lst)(setf lst (cons obj lst) How can How can poppop (pop lst) be defined? (pop lst) be defined?

Page 30: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 30

(let ((x (car lst)))(let ((x (car lst)))

(setf lst (cdr lst))(setf lst (cdr lst))

x)x) We also have a We also have a pushnewpushnew, which is like , which is like

pushpush but uses but uses adjoinadjoin instead of instead of conscons.. What difference would that make?What difference would that make?

Page 31: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 31

Dotted ListsDotted Lists

The kind of lists that can be built by calling The kind of lists that can be built by calling listlist are more precisely known as are more precisely known as proper proper listslists..

A proper list is either A proper list is either nilnil, or a , or a conscons whose whose cdrcdr is a proper list. is a proper list.

However, conses are not just for building However, conses are not just for building lists.lists.

Whenever you need a structure with two Whenever you need a structure with two fields you can use a cons.fields you can use a cons.

Page 32: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 32

You will be able to use You will be able to use carcar to refer to the to refer to the first field and first field and cdrcdr to refer to the second. to refer to the second.

> (setf pair (cons ‘a ‘b))> (setf pair (cons ‘a ‘b))

(A . B)(A . B) Because this cons is not a proper list, it is Because this cons is not a proper list, it is

displayed in dot notation.displayed in dot notation. In dot notation the car and cdr of each cons In dot notation the car and cdr of each cons

are shown separated by a period.are shown separated by a period.

Page 33: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 33

A cons that isn’t a proper list is called a A cons that isn’t a proper list is called a dotted list.dotted list.

However, remember that a dotted list isn’t However, remember that a dotted list isn’t really a list at all.really a list at all.

It is a just a two part data structure.It is a just a two part data structure.

a b

(A . B)

Page 34: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 34

Assoc-listsAssoc-lists

It is natural to use conses to represent It is natural to use conses to represent mappings.mappings.

A list of conses is called an A list of conses is called an assoc-listassoc-list or or alistalist..

Such a list could represent a set of Such a list could represent a set of translations, for example:translations, for example:

> (setf languages ‘((lisp . easy) (C . hard) > (setf languages ‘((lisp . easy) (C . hard) (Pascal . good) (Ada . bad))(Pascal . good) (Ada . bad))

Page 35: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 35

Assoc-lists are slow, but convenient when Assoc-lists are slow, but convenient when engaged in rapid prototyping.engaged in rapid prototyping.

Common Lisp has a built in function, Common Lisp has a built in function, assocassoc, for , for retrieving the pair associated with a given key:retrieving the pair associated with a given key:

> (assoc ‘C languages)> (assoc ‘C languages)

(C . HARD)(C . HARD)

> (assoc ‘Smalltalk languages)> (assoc ‘Smalltalk languages)

NILNIL Like Like membermember, , assocassoc takes takes keywordkeyword arguments, arguments,

including including :test :test and and :key.:key.

Page 36: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 36

Garbage CollectionGarbage Collection

Automatic memory management is one of Lisp’s most valuable features.Automatic memory management is one of Lisp’s most valuable features. A Lisp system maintains a segment of memory called the A Lisp system maintains a segment of memory called the heapheap.. The system keeps track of unused memory in the heap and allocates it to The system keeps track of unused memory in the heap and allocates it to

new objects.new objects. Allocating memory from the heap is sometimes known asAllocating memory from the heap is sometimes known as consing consing.. If such memory was never freed, Lisp would quickly run out of heap If such memory was never freed, Lisp would quickly run out of heap

space.space. So the Lisp system periodically searches through the heap, looking for So the Lisp system periodically searches through the heap, looking for

memory that is no longer needed and can be reclaimed.memory that is no longer needed and can be reclaimed. This is called This is called garbagegarbage, and the scavenging operation is called , and the scavenging operation is called garbage garbage

collectioncollection, GC., GC.

Page 37: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 37

An ExampleAn Example

Search is one of the basic problem solving Search is one of the basic problem solving strategies in artificial intelligence strategies in artificial intelligence programming.programming.

Lets look at an example of breadth-first Lets look at an example of breadth-first search.search.

Page 38: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 38

NetworkNetwork

A

B

C

D

(setf network ‘((A B C) (B C) (C D)))

Page 39: Mitthögskolan 10/8/2015 1 Common Lisp LISTS. Mitthögskolan 10/8/2015 2Lists n Lists are one of the fundamental data structures in Lisp. n However, it

Mitthögskolan 04/21/23 39

sourcessources

J.E. SpraggJ.E. Spragg

MitthögskolanMitthögskolan

19971997