Stemming, Part 19: Debugging

Before I leave the Porter Stemmer behind, I want to show you some of the tools
I used to debug the code as I went along.

There are some more modern options for debugging Clojure than what I’m
presenting here. (Search the mailing list for details.) Personally, I
generally use print statements for debugging. It’s primitive, but effective.
In some languages, it can also be painful. Fortunately, lisp languages take
much of the pain out of print-debugging.


One common way to debug programs is to follow when a function is called and
returns. This is called tracing, and this function and macro handle that.

(defn trace-call
  [f tag]
  (fn [& input]
    (print tag ":" input "-> ") (flush)
    (let [result (apply f input)]
      (println result) (flush)

trace-call returns a new function that prints the input arguments to a
function, calls the function, prints the result, and returns it. It takes the
function and a tag to identify what is being traced.

(defmacro trace
  `(def ~fn-name (trace-call ~fn-name '~fn-name)))

The trace macro is syntactic sugar on trace-call. It replaces the function
with a traced version of it that uses its own name as a tag. For example, this
creates and traces a function that upper-cases strings:

user=> (defn upper-case [string] (.toUpperCase string))
user=> (upper-case "name")
user=> (trace upper-case)
user=> (upper-case "name")
upper-case : (name) -> NAME

The debug Macro

Another common trick in print-debugging is to print the value of an
expression. The macro below evaluates an expression, prints both the
expression and the result, and returns the result.

(defmacro debug
  `(let [value# ~expr]
     (println '~expr "=>" value#)

For example:

user=> (debug (+ 1 2))
(+ 1 2) => 3

Lisp macros are especially helpful here, because they allow you to treat the
expression both as data to print and as code to evaluate.

The debug-stem Function

This function is a debugging version to stem. It uses binding to replace
all the major functions of the stemmer with traced versions of them.

(We’ll talk more about binding later, when we deal with concurrency. Right
now, just understand that binding changes the value of a top-level variable,
like a function name, with a new value. But the variable only has that value
for the duration of the binding. Afterward, it is returned to its former

(defn debug-stem
  (binding [stem (trace stem),
            make-stemmer (trace make-stemmer),
            step-1ab (trace step-1ab),
            step-1c (trace step-1c),
            step-2 (trace step-2),
            step-3 (trace step-3),
            step-4 (trace step-4),
            step-5 (trace step-5)]
    (stem word)))

That’s it. These were the main functions I used in debugging the stemmer as I
ported it from C and made it more Clojure-native.

Next up, we’ll create a concordance and look at other ways of presenting the
texts that we’re analyzing.

By the way, I’ve also finally updated the repository for sample code.

find the cost of your paper

BEANSTALKER and OTHER HILARIOUS SCARY TALES by Kiersten White / Book Review #BeanStalker

By: Kiersten White
Published by: Scholastic
Released on: July 25th, 2017
Ages: 8 & up
Purchase Links
Add it to Goodreads
Rating: 5 Owlets
An arc of this book was provided by the publisher in exchange for my honest review

What about, once upon a time, a bunch of fairy tales got twisted around to be completely hilarious, a tiny bit icky, and delightfully spooky scarytales; in other words, exactly what fairy tales were meant to be. Grab some flaming torches, maybe don’t accept that bowl of pease porridge, and get ready for a wickedly fun ride with acclaimed author Kiersten White and fairy tales like you’ve never heard them before.

Snow White is a vampire, Little Red Riding Hood is a zombie, and Cinderella is an arsonist — and that is only some of the mayhem the reader will find in this collection of fractured fairy tales.

A laugh out loud debut middle grade book from one of my favorite YA authors. Kiersten White has created my favorite mix of fractured fairytales and nursery rhymes to date! I loved the way she intertwined, and interconnected so many classics, and the spin she gave each one. If having vampires, zombies and stepmothers isn’t enough to entice you, the illustrations, and the narration will be. 

This is the perfect blend of fairytales and nursery rhymes. Who knew you could combine stories like Snow White, The Princess and the Pea, Jack & Jill, The Dish and The Spoon, Cinderella, Rapunzel, Jack Be Nimble, Jack and the Beanstalk, Little Red Riding Hood, and the Stepmother. White’s intertwining of these stories was awesome! Numerous times while reading this book I wondered how White was able to pull this off so well. 

The narration in this story is my favorite part of the entire book. Talk about sassy! The narrator definitely stole the show in this book. It’s what made this story so much fun to read. It’s not just their self awareness that makes the narrator so appealing either. The narrator would make a great language arts teacher. Numerous times in this story the narrator points out the homonym and homophone words that characters miss. Like The Princess and The Pea. Let’s just say it’s not, well, you wouldn’t want to sleep on that mattress. This narration definitely makes for the perfect, hilarious, read aloud. 

This book is a must read! It’s equal parts hilarious, and spooky, though it is way more hilarious than spooky. It’s spooky in the best way possible, because some of these characters are not the sweet, innocent characters we all grew up reading about. The spooky twists come from some of them being vampires and zombies. This may be written for middle grade readers, but it will definitely be appealing to all readers ages 8 and up. Including adults. It was part of my Halloween read up earlier this week, but this is one book that can be read all year long. 

Describing an interview-based assignment to writers

Recently a company contacted me to write an interview-based post for its blog. I’ve often done this for blog posts that show off the expertise of the company’s staff. However, what was unusual about this request was that I’d need to interview experts outside the company for the post. The need to find external experts makes an interview-based assignment more time-consuming and less attractive to writers. It’s more like writing a magazine article than a typical content marketing piece.

I learned later that the company’s marketing director had omitted an important piece of information when it described its interview-based assignment. It could have reduced my qualms about accepting an assignment requiring interviews of external experts. I describe it below.

The challenges of using external experts

Using external experts is challenging for two reasons.

First, it takes time to find and schedule them. If the writer doesn’t know relevant experts, a good deal of networking may be required to find them. That’s especially true if there’s no trade association or other group where such experts gather.

Scheduling can be more challenging than when working with a company’s internal experts. Internal experts are motivated to participate for the good of their employer (though they still can be challenging to schedule, but that’s another story). External experts don’t feel a pressing need for your company to succeed at its marketing.

Second, the experts may not wish to use their expertise on behalf of the company that’s your client. It’s generally less prestigious to appear on a corporate blog or in a corporate magazine than in a publication that’s perceived as independent. Also, the expert may worry about appearing to endorse the products or services offered by your client. On the other hand, some corporate publications don’t quote experts by name. That’s even worse because the expert gets no visibility in exchange for sharing insights.

The missing information

After I turned down the interview-based assignment, I learned that the marketing director had unwittingly withheld a piece of information that would have made it more attractive. He told me that he planned to find experts for the writer. That was potentially a big timesaver for the writer.

Of course, just naming experts isn’t enough. For the reasons mentioned above, experts may not want to help a corporate publication. However, if you’re a marketer assigning articles, and you can promise cooperative sources to your outside writers, that’s a big plus. Don’t hide that; feature it!

Of course, there’s other information that writers will seek, including:

  • Your topic, defined as specifically as possible
  • Pay
  • Word count
  • Place of publication
  • Target audience and why they’ll care about your topic
  • Your timeline and editing process

When you provide complete information up front, you’ll get a more realistic price from your writer. Also, the entire writing and editing process will go more smoothly.

The post Describing an interview-based assignment to writers appeared first on Susan Weiner's Blog on Investment Writing.