Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7897505
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T08:11:00+00:00 2026-06-03T08:11:00+00:00

These days I have took Peter Norvig’s Udacity course CS212: DESIGN OF COMPUTER PROGRAMS.

  • 0

These days I have took Peter Norvig’s Udacity course CS212: DESIGN OF COMPUTER PROGRAMS.
Unfortunately, the course is all in Python so, for the sake of learning, I wrote the equivalent code in Racket for regex compiler given in unit 3 of that course.

You can see my code here: http://codepad.org/8x0rMXOi

Now, what’s bothering me is that Mr. Norvig’s original code in Python is somewhat shorter than mine. 🙁 But ok, I’m just beginner in Racket, and that is expected. But I wonder if some Racket expert can shorten my code, so that Racket code become shorter than original Norvig’s Python code?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-03T08:11:01+00:00Added an answer on June 3, 2026 at 8:11 am

    Here are a few tips.

    The ormap-expression in:

     (define (in-chars? c chars)
       (ormap (lambda (ch) (equal? c ch)) (string->list chars))) 
    

    can be written as

       (memv c (string->list chars)) 
    

    The if-epression in

    (define (match pattern text)
      (define remainders (pattern text))
      (if (not (set-empty? remainders))
          (substring text 0 (- (string-length text)
                               (string-length (argmin string-length 
                                                      (set->list remainders)))))
          #f))
    

    can be written as

     (and (not (set-empty? remainders))
          (substring ...)
    

    However your function are small and to the point, so I wouldn’t change much.

    A more convenient syntax for manipulating strings would make
    it easier to read and write string manipulation programs. Some years ago I made an attempt and wrote a concat macro.

    I used it to implement Norvig’s spelling checker (his original article might interest you). The resulting spelling checker and the concat macro is explained here

    http://blog.scheme.dk/2007/04/writing-spelling-corrector-in-plt.html

    Update: I have written an updated version of the spell checker.
    The concat macro is makes simple string manipulation shorter.

    https://github.com/soegaard/this-and-that/blob/master/spell-checker.rkt

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Have been hearing all around ArrayList getting obsolete these days. But I do have
Although ASP.NET MVC seems to have all the hype these days, WebForms are still
I'm working at Windows Phone application these days and have faced the problem with
I like that, these days, we have an option for how we get our
I have been trying PyMC these days, and I wrote a very simple mcmceasy.py.
I have been reading a lot about MVC these days and I think I
I have been seeing a lot of html slides these days. They falls into
Playing around with Google Maps these days, with some directions. I have a map
These days I have learned some basic usage of C#. I think that because
Hi I am a java developer and these days I have also started working

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.