• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • paul wheaton
  • Ron McLeod
  • Devaka Cooray
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Piet Souris
Bartenders:

Kata exercise: Code classifier

 
Marshal
Posts: 5950
407
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This evening was time for our monthly Functional Kats {Belfast} (<-- shameless plug) event that a buddy and I organise. It's in partnership with our namesake group down in Dublin and we usually connect with them over Skype for a group exercise, or watch a presentation if they have one on. Tonight we had connectivity issues so went rogue with a fun Kata of our own. It was a good one, worthy of sharing. So here it is. Feel free to play along.

The challenge is to write a program that will take in some source code and classify the elements of the language. For example, given a snippet of this made up language as input:

Your program will yield the following output:

The exact format of the output can vary depending on your solution style, but in essence it must be an ordered list of key value pairs. The Functional Kats group adds a secondary stipulation that the solution be in a functional style, and we saw partial solutions in Clojure, Scala, Elixir, and Javascript.

You may use any language you wish, and use any programming paradigm you wish (functional, object oriented, whatever)
 
Tim Cooke
Marshal
Posts: 5950
407
IntelliJ IDE Python TypeScript Java Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
As a starting point, I'm going to only deal with the much simpler code snippet of:

Here's my first round attempt, written in Clojure:

Which when called:

Yields the desired output of:

So far so good. Now, on to the next part.
 
Consider Paul's rocket mass heater.
reply
    Bookmark Topic Watch Topic
  • New Topic