Last updated: Thu, 19 Feb 2015 10:31:32 -0500
DUE: Monday 2/23/2015, 9pm EST
You must use the Intermediate Student with lambda language to complete this assignment. Select it via the Choose Language... menu located at the bottom-left of the DrRacket window.
Put all your solution files in a directory named set06 in your repository.
Download extras.rkt to this directory (right-click and choose "Save As"; don’t copy and paste) and commit it as well.
Use begin-for-test and rackunit to define your examples and tests.
- Don’t forget to tell us how many hours you spent working on the assignment. This should be a global variable called TIME-ON-TASK in each file. For example:
(define TIME-ON-TASK 10.5) ; hours
- So each solution file must have at least the following at the top:
(require "extras.rkt") (require rackunit) (define TIME-ON-TASK <number-of-hours-you-spent>)
- After you’ve submitted your solution, use a web browser to go to https://github.ccs.neu.edu/ and check that your repository contains the following files:
For this week’s alternate data definition, revise your Xexpr data definition so that plain text is represented with XWords instead of plain strings. Then comment on how two of your functions would be affected.
Git Commit Requirement: For this assignment, you must have at least three well-labeled git commits (including the final commit). A well-labeled git commit accurately and succinctly describes the changes since the previous commit. Something like "commit2", or "home work 3" is not an acceptable git commit label. Failure to meet this requirement will result in loss of points.
(check-location "06" "xexpr.rkt")
(Do you prefer to read the textbook version without aliases or this one?)
; An Xexpr is one of: ; - Symbol ; - String ; - Number ; - (cons Tag (cons ListOf<Attribute> ListOf<Xexpr>)) ; - (cons Tag ListOf<Xexpr>) ; Represents an XML element. (define HTML-EMPTY '(html ((lang "en-US")) (body (p) (br) (p) (br)))) (define HTML-WITH-TEXT '(html ((lang "en-US")) (body (p "Here is assignment " 5) (br) (p "This is a " (b "data") " definition.")))) (define IMG '(img ((src "balls.png") (width "100") (height "50")))) ; A Tag is a Symbol, representing the name of an XML element. (define H1 'h1) (define P 'p) (define BR 'br) ; An Attribute is a (list AttrName AttrValue) ; representing an attribute name-value pair in an XML element. (define HREF-NEU (list 'href "http://northeastern.edu")) (define IMG-SRC (list 'src "ball.gif")) ; An AttrName is a Symbol, ; representing the name of an XML attribute. ; An AttrValue is a String, ; representing the value associated with an XML attribute.
Complete the Data Design with templates and other requirements.
- Define the functions below. Some of them may be definable in terms of the others. (And some may already be given to you in the textbook.)
; xexpr-element? : Any -> Boolean ; Returns true of x is a valid XML element. (define (xexpr-element? x) ...) ; xexpr-tag : Xexpr -> Maybe<Tag> ; Returns the tag of element xe. (define (xexpr-tag xe) ...) ; xexpr-attributes : Xexpr -> ListOf<Attribute> ; Returns the attributes of the given XML element. (define (xexpr-attributes xe) ...) ; xexpr-content : Xexpr -> ListOf<Xexpr> ; Extracts the content of an XML element. ; An element's tag and attributes are not part of its content. (define (xexpr-content xe) ...) ; attribute-value : ListOf<Attribute> AttrName -> Maybe<AttrValue> ; Returns the value of first attribute in loa named aname. ; Returns #f if no attribute in loa has the name aname. (define (attribute-value loa aname) ...) ; get-value : Xexpr AttrName -> Maybe<AttrValue> ; Returns the value of the first attribute in xe named aname. (define (get-value xe aname) ...) ; xexpr-find : Xexpr AttrName -> ListOf<AttrValue> ; Searches xe and nested elements in xe for attributes named aname ; and returns all the values for these attributes. (define (xexpr-find xe aname) ...) ; xexpr-depth : Xexpr -> Natural ; Returns the depth of the deepest nested Xexpr. ; An Xexpr with no nested elements has depth 0. (define (xexpr-depth xe) ...) ; xexpr-elements : Xexpr Tag -> ListOf<Xexpr> ; Returns a list of all elements in xe whose tag is t. ; An element with tag t may be nested inside another element with ; the same tag and this function returns both. (define (xexpr-elements xe t) ...)
Finally, use the functions you wrote, and the read-xexpr/web function from the 2htdp/batch-io library to write a function that consumes a string url and scrapes and returns some interesting information from the web. (Use the Google Finance example from the textbook if you are struggling to come up with ideas.) This function should false if there is a problem retrieving content from the web. We will check what you did during your code walk.