• 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Devaka Cooray
  • Paul Clapham
Sheriffs:
  • Tim Cooke
  • Knute Snortum
  • Bear Bibeault
Saloon Keepers:
  • Ron McLeod
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Ganesh Patekar
Bartenders:
  • Frits Walraven
  • Carey Brown
  • Tim Holloway

Kata exercise: Code classifier

 
Sheriff
Posts: 4633
300
IntelliJ IDE Clojure Java
  • Mark post as helpful
  • send pies
  • 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
Sheriff
Posts: 4633
300
IntelliJ IDE Clojure Java
  • Mark post as helpful
  • send pies
  • 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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!