Revision of 2.2.1 Representing Sequences from 30 June 2009 - 8:19pm

The revisions let you track differences between multiple versions of a post.

Printer-friendly versionPrinter-friendly version


Exercise 2.17


Define a procedure last-pair that returns the list that contains only the last element of a given (nonempty) list:

(last-pair (list 23 72 149 34))

Exercise 2.18


Define a procedure reverse that takes a list as argument and returns a list of the same elements in reverse order:

(reverse (list 1 4 9 16 25))
(25 16 9 4 1)

Exercise 2.19


Consider the change-counting program of section 1.2.2. It would be nice to be able to easily change the currency used by the program, so that we could compute the number of ways to change a British pound, for example. As the program is written, the knowledge of the currency is distributed partly into the procedure first-denomination and partly into the procedure count-change (which knows that there are five kinds of U.S. coins). It would be nicer to be able to supply a list of coins to be used for making change.

We want to rewrite the procedure cc so that its second argument is a list of the values of the coins to use rather than an integer specifying which coins to use. We could then have lists that defined each kind of currency:

(define us-coins (list 50 25 10 5 1))
(define uk-coins (list 100 50 20 10 5 2 1 0.5))

We could then call cc as follows:

(cc 100 us-coins)

To do this will require changing the program cc somewhat. It will still have the same form, but it will access its second argument differently, as follows:

(define (cc amount coin-values)
  (cond ((= amount 0) 1)
        ((or (< amount 0) (no-more? coin-values)) 0)
         (+ (cc amount
                (except-first-denomination coin-values))
            (cc (- amount
                   (first-denomination coin-values))

Define the procedures first-denomination, except-first-denomination, and no-more? in terms of primitive operations on list structures. Does the order of the list coin-values affect the answer produced by cc? Why or why not?

Exercise 2.20


The procedures +, *, and list take arbitrary numbers of arguments. One way to define such procedures is to use define with dotted-tail notation. In a procedure definition, a parameter list that has a dot before the last parameter name indicates that, when the procedure is called, the initial parameters (if any) will have as values the initial arguments, as usual, but the final parameter’s value will be a list of any remaining arguments. For instance, given the definition

(define (f x y . z) <body>)

the procedure f can be called with two or more arguments. If we evaluate

(f 1 2 3 4 5 6)

then in the body of f, x will be 1, y will be 2, and z will be the list (3 4 5 6). Given the definition

(define (g . w) <body>)

the procedure g can be called with zero or more arguments. If we evaluate

(g 1 2 3 4 5 6)

then in the body of g, w will be the list (1 2 3 4 5 6).[11]

Use this notation to write a procedure same-parity that takes one or more integers and returns a list of all the arguments that have the same even-odd parity as the first argument. For example,

(same-parity 1 2 3 4 5 6 7)
(1 3 5 7)

(same-parity 2 3 4 5 6 7)
(2 4 6)

To define f and g using lambda we would write

(define f (lambda (x y . z) <body>))
(define g (lambda w <body>))


Exercise 2.21


The procedure square-list takes a list of numbers as argument and returns a list of the squares of those numbers.

(square-list (list 1 2 3 4))
(1 4 9 16)

Here are two different definitions of square-list. Complete both of them by filling in the missing expressions:

(define (square-list items)
  (if (null? items)
      (cons <??> <??>)))
(define (square-list items)
  (map <??> <??>))

Exercise 2.22


Louis Reasoner tries to rewrite the first square-list procedure of exercise 2.21 so that it evolves an iterative process:

(define (square-list items)
  (define (iter things answer)
    (if (null? things)
        (iter (cdr things) 
              (cons (square (car things))
  (iter items nil))

Unfortunately, defining square-list this way produces the answer list in the reverse order of the one desired. Why?

Louis then tries to fix his bug by interchanging the arguments to cons:

(define (square-list items)
  (define (iter things answer)
    (if (null? things)
        (iter (cdr things)
              (cons answer
                    (square (car things))))))
  (iter items nil))

This doesn’t work either. Explain.

Exercise 2.23


The procedure for-each is similar to map. It takes as arguments a procedure and a list of elements. However, rather than forming a list of the results, for-each just applies the procedure to each of the elements in turn, from left to right. The values returned by applying the procedure to the elements are not used at all — for-each is used with procedures that perform an action, such as printing. For example,

(for-each (lambda (x) (newline) (display x))
          (list 57 321 88))

The value returned by the call to for-each (not illustrated above)can be something arbitrary, such as true. Give an implementation of for-each.


Beats By Dre Monster

SYNC by 50 If you’re like most of us, you woke up one morning this week and realized it’s almost December,SYNC by 50 and the holidays are swiftly approaching. STREET by 50 And, of course, you still don’t know what to get a few people on your list.We all know that headphones are a dime a dozen. STREET by 50 But a headphone that receives equal points for style and functionality, however, is a rare find. sms by 50 Some of our friends in the press know SMS Audio headphones fit the bill, sms by 50 and recommend you put them on your holiday shopping list this year: Beats By Dre Monster Rolling Stone included the limited edition Yellow STREET by 50 over-ear headphones in its 2012 holiday gift guide featured in the December issue.Beats By Dre MonsterWhat did Rolling Stone have to say about SMS Audio?

beats by dre clearance

cheap monster beats Before I tell you about my experience, cheap monster beats let me tell you a bit more about these headphones. beats by dre solo According to the information I’ve read, Dr. beats by dre solo Dre worked with Monster Cable and Robert Brunner, dre beats an industrial designer, dre beats for more than two years to perfect these headphones. beats by dre clearance In Dr. Dre’s words,People aren’t hearing all the music beats by dre clearance.……………………………………………閿熸枻鎷穌c閿熸枻鎷?nike-kd/…

Acheter Maillot De Foot Pas Cher Avec Le Prix Le Plus Bas

Acheter Maillot De Foot Pas Cher Avec Le Prix Le Plus Bas

discount jordan shoes

ts a higher standard twelfth grade. Almost every scholarship or grant on offer at the school place, you can find plenty of level of competition. To be able to come out through the level of competition to get to the radar with institution custom motor coaches, to consider just what exactly institution custom motor coaches are actually interested in every time they hire twelfth grade baseball game enthusiasts to get grants. Comprehension just what exactly custom motor coaches are actually interested in while in the some athletes people hire might supply substantial benefits through a person’s twelfth grade level of competition. Here’s some of the directory of half dozen major elements custom motor coaches want while in the game enthusiasts they can be selecting: 1) Capabilities Plus TalentTo have fun with along at the upcoming a higher standard baseball, just are not to be almost twelfth grade battler. Getting older signify you’ve got to be your pink processor chip and also top level place battler which was new considering taken from diapers, nonetheless you’ll want previously ordinary capabilities plus skills. Don’t forget there are actually institution however shapes plus category concentrations through The states. Although you will possibly not have skills plus capabilities so that you can have fun with in the education for instance Birmingham, al, The southwest and also Okla would not signify you won鈥檛 have fun with during quite a few a higher standard level of competition. 2) Natural SizeCollege baseball plus basketball game are in all likelihood the 2 main a lot of measurements susceptible physical activities. Custom motor coaches will likely find game enthusiasts who definitely have a natural length plus and also excess fat so that you can participate during its category place. There are plenty of game enthusiasts per year along at the twelfth grade place who seem to in all probability have skills so that you can have fun with during quite a few a higher standard institution baseball, however easily loss a

Jordans 2014 Cheap Sale

On the other hand mainly because it can be exceptional that they need to always be apply, fairly pertaining to perhaps seasoned mariners to get expired for the most up-to-date techniquesYou will not shocked to find out that a majority of sea-goers incorporate some expertise in urgent situation processes and a lot of need consumed qualifications. On the other hand mainly because it can be exceptional that they need to always be apply, fairly pertaining to perhaps seasoned mariners to get expired for the most up-to-date approaches. It can be surely worthy of having a long time for you to comb way up your current know-how. DSC (digital frugal calling) Should you have VHF r / c using DSC, you must 1st mail a new hardship indicati
older Colonial gambler to interchange a global super-star including Beckham decided not to could be seen as a good option to begin with, although by his or her primary year Cristiano Ronaldo’s aims shown critical in addition to he / she easily accumulated this appreciate on the Reddish colored Devils’ lovers. With his or her using times on Stansted, having an increasing number of confidence caused by Friend Alex Ferguson along with the team’s lovers, Cristiano Ronaldo resulted in an exceptional gambler that is certainly at this point scary by means of possibly this sturdiest defenders in existence. While they are simply just 23 years old at the moment, Cristiano Ronaldo witout a doubt possesses 208 skilled meets in addition to 53 aims (190 meets in addition to 50 aims intended for Stansted, though others intended for Sporting) in addition to forty six shelves from the nation’s group, that has a tally connected with teen aims intended for Spain. Outstanding gambling intended for a really young person. The most beneficial aspect is usually of which having just about every driving season Cristiano Ronaldo helps his or her activity a step forward, and so avoid getting stunned in the event with many years he / she ways nearly end up being the best footballer with pastime.An emergency In Seashore

Retro Legend Blue 11s 2014

ct leg has never straightened. Simplest way to be sure the following would not materialize will be to launch during correct which includes a awesome flexed perfect leg plus tilt the following marginally around into the tennis ball. Center on having a back to the inside tilt in the action. five. A all the way down action is definitely started because of your thighs and leg. Come to feel a person’s all the way down action starting out using a negligible action within your kept leg into the aim for. This tends to induce pub travel lag whereby a person’s arms will be yanked all the way down to the backside of your tennis ball when holding full arm joint with the the top of backswing. A fantastic assumed to keep in mind is definitely ‘butt with the whole length so that you can backside with ball’. The following helps ensure you will have a missed put out approaching on the backside of your tennis ball plus give a very good, crispy affect together with the tennis ball. 5. Assume Cycle While you action your golf wedge make sure you just imagine the best actively playing golf experts action at heart plus assume cycle. Aim to repeat its cycle plus bring to mind next to nothing altogether different. The following solo action assumed is going to be sure a fantastic simple action and you will then will action a pub of course and for that reason strongly. To sum it up establish a dependable pre taken workout this has rectangle stance, one or two waggles plus lumination traction tension. Action a triangle backside by using lumination traction tension plus move a person’s backside to the aim for. Start out a downswing together with the direction within your thighs and leg plus accomplish a action around steadiness. A solo biggest action assumed to pay attention to is definitely ‘rhythm’. Commence with this plus stop talking stopping all-natural cycle within shut off portions. You’re excited during the best way routinely you actually will struck a tennis ball almost every pub while in the travelling bag.How you can Purchase a Ve

Legend Blue 11s For Christmas

Related Links:

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <a> <em> <strong> <cite> <code> <pre> <hr> <ul> <ol> <li> <dl> <dt> <dd> <img>
  • Lines and paragraphs break automatically.
  • Adds typographic refinements.

More information about formatting options