DEV Community

Cover image for Javascript Poem
SethRAH
SethRAH

Posted on

Javascript Poem

Recently, I've read through "If Hemingway Wrote JavaScript" by Angus Croll. The book has five "Programming Assignments" and then the solutions that various notable authors would have came up with if they wrote java script.

The authors range from Earnest Hemingway and Virginia Woolf to David Foster Wallace and Tupac Shakur. The book also does a good job of giving a summary of the author before their submission and then an explanation afterwards of why the submission follows their style of writing.

One of the coolest things was how the solutions played with form to imbue their character into the solution. While maybe not always the best for maintainability/readibility, there was definitely something in these code poems that I thought was missing from my every day coding, so I took one of the assignments from the book and made my own response. I'm not super proud of the end (I think I have more comments than actual code) response but it was fun to do.

Assignment

Write a chainable function that accepts one word per function call but, when called without arguments, will report back all the previously passed words in order

In the below poem, the recall function will achieve the assignment results and can be called like recall('hello')('world')(); which will print hello world

words=/*Are but for recollection but what does that entail*/[];

/*To*/recall=/*just a */function/*of the*/(word){
  /*but how does one*/return word ?
  /*Simply by*/retain/*ing*/(word/*s*/)
  :/*then*/regurgitate(/*ing*/);
}

/*To*/retain=/*a*/function/*of*/(word){/*whence*/words.push(word);
  /*Towards words worthy to*/return/*and*/recall;}

/*To*/regurgitate=/*a*/function/*of*/(word){
  /*where*/recollection=/*of*/words.join(/*ed*/' ');/*are summoned forth*/
  words=[/*to be spent*/];
  return/*the*/recollection/*for substance went*/;
}

Latest comments (0)