aleix's blog

The Law of Car

10 April 2013 8:18 am (scheme | guile)

In The Little Schemer, The Law of Car is defined as:

The primitive car is defined only for non-empty lists.

In the implementation given for (firsts l), it seems to me that the law is broken:

(define firsts
  (lambda (l)
    (cond
      ((null? l) '())
      (else (cons (car (car l))
                  (firsts (cdr l)))))))

As (firsts '()) is '(). So, this would actually fail (in guile):

$ (firsts '((a b) () (e f)))
In procedure firsts:
In procedure car: Wrong type argument in position 1 (expecting pair): ()

I think a correct implementation would be (note that there's no need to write the second cond as the first cond could take multiple clauses):

(define (firsts l)
  (cond
   ((null? l) '())
   (else (cond
          ((null? (car l)) (firsts (cdr l)))
          (else
           (cons (car (car l))
                 (firsts (cdr l))))))))

in which we take care of the non-empty list before getting the first typical element (car (car l)). This would result in:

$ (firsts '((a b) () (e f)))
(a e)

31 responses

  1. assignment writing service says:

    Thank you for your post. I think this post definitely will help students ,especially for programing students.I hope students will easily catch your ideas so that it would become the step by step blog.

  2. Sociology Online Assignment Help says:

    Your blog is filled with unique good articles! I was impressed how well you express your thoughts and sharing your experiences.I never regretted any moment that came to your blog! :)

  3. MyAssignmentHelp review says:

    Cool blog! Thanks for sharing this material, never knew about Law of Cars. I only started to learn to code, so that was very useful for me.

  4. WaltonWilliam says:

    This is by and by related with the undertaking of sizes and courses of action to programming-tongue sorts. Another solidly related point is deforming. Calling conventions, sort portrayals, Buy custom Essays and name desolating are all piece of what is known as an application twofold interface.

  5. Stats Assignment help says:

    Things are very open and intensely clear explanation of issues. was truly information. Your website is very beneficial.

  6. 项目写作帮助 says:

    事情是非常开放和强烈清楚的解释问题。是真正的信息。你的网站是非常有益的。

  7. Write My Essay For Me says:

    Saved as a favorite, I love your web site!

  8. Write My College Paper For Me says:

    Aw, this was a really nice post. Spending some time and actual effort to generate a great article but what can I say… I put things off a whole lot and don't seem to get anything done.

  9. Star Wars Han Solo Jacket Buy Movie Jackets says:

    Car wellbeing is the examination and routine with regards to plan, development, hardware and direction to limit the event and outcomes of car accidents. Street activity wellbeing all the more comprehensively incorporates roadway outline.
    One of the main formal scholarly examinations into enhancing vehicle security was by Cornell Aeronautical Laboratory of Buffalo, New York. The primary finish of their broad report is the essential significance of safety belts and cushioned dashboards.

  10. Amanda says:

    That's some smart way of presenting the law of car with the implementation of coding. Help With Assignment Writing thinks of now new ways to present other laws.

  11. Evelyn Roger says:

    Actually I was looking for someone to teach me the law of car and finally here I have found it, pay someone to do my assignment but still some more laws I want to know so kindly please share it with me...

  12. Evie Walsh says:

    Before driving car its compulsory in the law of almost every country of the world to understand the law of car without knowing it coursework writing service uk, it can be dangerous for your life and also others..

  13. Julia Simmons says:

    Sometimes I wish I could make the right decisions in the right manner, then you need to make the correct things in order to get the best results. Assignment Hub - Economics Assignment

  14. Tyler Burn says:

    Everything in this World have some particular rules and guidelines to follow, but unfortunately we never accept that rules.. If you follow the rules so its your profit like if you follow law of car so who's benefit in that ?? Obviously its your's benefit... Custom Essay

  15. Ghost Rider Jacket says:

    Engine Vehicle Defects Law is a piece of shopper insurance law that arrangements with autos, trucks, cruisers, and different vehicles. Each vehicle producer and dealership warrants to its buyers that the autos they offer are protected to drive.

  16. lukenlow says:

    I like how you solved this problem, a very unusual and creative way of thinking 192.168.l.l

  17. Professional Essay Writers UK says:

    In Wild and Wonderful West Virginia, there may be a regulation regarding parking on private assets and even blocking off get right of entry to to a private drive. We are one of the Professional Essay Writers UK and can deliver quality work on time.

  18. https://casestudyaid.com says:

    This is great information for students. This article is very helpful i really like this blog thanks. I also have some information relevant for online dissertation help.

  19. Pay You to Do my Essay says:

    This is by using and with the aid of related to the venture of sizes and guides of action to programming-tongue types. Avenue pastime nicely being all the more comprehensively includes roadway outline. Pay You to Do my Essay The primary finish in their large record is the critical significance of safety belts and cushioned dashboards.

  20. Essay Help Pros says:

    Aw, this changed into a truly satisfactory submit. automobile wellbeing is the exam and routine with regards to plan, development, hardware, and the path to limit the event and results of automobile injuries. road pastime well-being all of the greater comprehensively contains roadway outline. things are very open and extremely clear rationalization of issues.

  21. TrueEssayHelp.co.uk says:

    Thank you for your submit. I suppose this publish sincerely will help college students. Your weblog is packed with unique excellent articles! this is by way of and via associated with the undertaking of sizes and courses of motion to programming-tongue sorts.

  22. Dissertation writers says:

    I really appreciate the way of your teaching regarding if else clauses are tremendous. As programmer and web developer I do recommend to all the young students keep trying to learn this clauses. Because it is so necessary for a programmer.

  23. Write My Essay says:

    Motor Vehicle Defects Law is a bit of customer protection law that courses of action with automobiles, trucks, cruisers, and distinctive vehicles. Every vehicle maker and dealership warrants to its purchasers that the cars they offer are secured to drive.

  24. Do my Assignment for me says:

    Indeed unquestionably it ought to be made necessary in each nation to offer chance to the lady with the goal that they can become famous.

  25. WritingEssay says:

    This is before long related to the endeavor of sizes and approaches to programming-tongue sorts. Another positively related point is disfiguring. Calling traditions, sort depictions, Buy custom Essays and name destroying are all bit of what is known as an application twofold interface.

  26. Assignment INC says:

    Really i appreciate the effort you made to share the knowledge. This is really a great stuff for sharing. Keep it up . Thanks for sharing.

  27. assignment writer says:

    Aw, this changed into a really acceptable submit. car prosperity is the exam and routine with respect to design, advancement, equipment, and the way to constrain the occasion and consequences of car wounds. street leisure activity prosperity the greater part of the more noteworthy exhaustively contains roadway diagram. things are exceptionally open and to a great degree clear defense of issues.

  28. Danny says:

    I’ve read the topic with great interest and definitely will stick your blog routinely for other great posts. Literature Review Paraphrasing Help Thank you for sharing this valuable and great article.

  29. Online Essay Help says:

    Your weblog is stuffed with special astounding articles! this is by method for and by means of related with the endeavor of sizes and courses of movement to programming-tongue sorts. This is extraordinary data for understudies. This article is exceptionally useful I extremely like this blog much obliged. I additionally have some data significant for online exposition help.

  30. Essay Service UK says:

    Much obliged to you for your submit. I assume this distribute truly will help understudies.

  31. Australia Assignment Help says:

    The leading assignment help UK firm offers state of the art services to its clients with a promise of delivering all the required work well within the deadline.

Leave a Reply