Win a copy of 97 Things Every Java Programmer Should Know this week in the Java in General forum!
  • 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
  • Paul Clapham
  • Jeanne Boyarsky
  • Junilu Lacar
  • Henry Wong
Sheriffs:
  • Ron McLeod
  • Devaka Cooray
  • Tim Cooke
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Frits Walraven
  • Tim Holloway
  • Carey Brown
Bartenders:
  • Piet Souris
  • salvin francis
  • fred rosenberger

Kata exercise: Code classifier

 
Sheriff
Posts: 4868
317
IntelliJ IDE Python Java Linux
  • 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: 4868
317
IntelliJ IDE Python Java Linux
  • 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.
 
But how did the elephant get like that? What did you do? I think all we can do now is read this tiny ad:
Devious Experiments for a Truly Passive Greenhouse!
https://www.kickstarter.com/projects/paulwheaton/greenhouse-1
    Bookmark Topic Watch Topic
  • New Topic