This lab will focus on abstract data types
"A student is a data structure with three elements, an id, a name and a list of grades.
As with most things in Scheme, we can ABSTRACT this process, so we don't have to type as much. We can't quite do this ourselves (as we must manipulate the Scheme syntax to create a new special form---this is one example of the "macro" capability of the Lisp family of languages discussed in the Paul Graham paper) but it has been done in the Intermediate Student language and the Pretty Big languages that we have been using.(define (make-student id name grades) (list id name grades))
(define (student-id student) (car student))
(define (student-name student) (cadr student))
(define (student-grades student) (caddr student))"
(define-struct student (id name grades))This is a simple example of how lisp macros can take the drudgery out of programming by abstracting code construction itself.
;defines (make-student i n g), (student-id s), (student-name s) and (student-grades s)
Exercise
1: A peer-to-peer network (like GNUtella) consists of individual
nodes that are connected to the rest of the network through one or more
neighboring nodes. In a simplified model, each node has only one
neighbor and a list of files that it can serve. Every node has a unique
number representing its address.
(define-struct file (name contents))
(define-struct node (address files neighbor))
Develop the function P2P-search. The function
consumes the name of file and a P2P-network, and returns the address of
the first node that is discovered to have the file or false if the file
does not exist anywhere within the network.
Exercise
2: A copyright enforcement group wants to collect the addresses
of all nodes on a P2P-Network that are hosting a particular file.
Develop the function P2P-search-all, which is like P2P-search except
that it returns the list of addresses of all nodes having a copy of the
file being searched for.
Excercise
3: Develop the function P2P-get. The function consumes the name
of file, the address of a node, and a P2P-network and returns the
contents of the file. Assume that both the node and file exist.