Giter VIP home page Giter VIP logo

scala-tcd-funcprog's Introduction

Scala Module for TCD Functional Programming Course

Lab0 - Setup

This repo will allow you to set yourself up for the Scala Module of the TCD Functional Programming Course.

Please install git on your laptop and clone the repo ...

> git clone https://github.com/rolandtritsch/scala-tcd-funcprog.git

... to <location of your choice>.

Please install sbt on your laptop and compile the setup by typing (below is for Mac OS) ...

> cd <location of your choice>/scala-tcd-funcprog
> mkdir <your first name>.<your last name>
> cp -R roland.tritsch/0.setup <your firstname>.<your lastname>
> cd <your firstname>.<your lastname>/0.setup
> sbt "compile"

... and you should see a successful compile. You can then try to run it ...

> sbt "run"

... and should see the familiar "Hello World" output. You can then try to test it ...

> sbt "test"

... which should fail.

Homework

  1. Make the test pass. Change the source code in src/test/scala and run > sbt test again.
  2. Change Hello.scala to look at the first argument and make it print "Hello " + firstArg. Note: To run it you need to put the arg into quotes with the run (e.g. > sbt "run world").
  3. Bonus: Get a github account, send me an email ([email protected]), so that I can add you as a collaborator and commit/push your source code to the repo (to figure out how to do that is a an excerise for the reader :)).

Resources

Lab1 - Rewriting a Java program in Scala - Josephus Problem

With Lab1 we want to rewrite a Java program in Scala. The program is an implementation of a solution to Josephus problem. To make it work you need to ...

> cd <location of your choice>/scala-tcd-funcprog
> cp -R roland.tritsch/1.rewrite <your firstname>.<your lastname>
> cd <your firstname>.<your lastname>/1.rewrite/java
> sbt "run 41 3"

... and you should see the solution of 31 (means you need to be soldier 31 to survive).

Please take a look at the Java source code to understand the solution.

You then need to ...

> cd <your firstname>.<your lastname>/1.rewrite/scala
> sbt "run 41 3"
> sbt "test"

... and both will fail. Please flesh out the code in Josephus.scala to make the program work and the test pass.

Hints

  • Use the source code from the Java solution as a template.
  • Use the provided RingIterator to implement the solution.
  • Use > sbt console to start a repl and play with RingIterator to understand how it works and behaves.
  • Use the source code from Hello.scala as a template for the main.

Lab2 - Write a Scala program that uses Java

Java integrates very well with Scala (or (depending on your point of view) the other way around). With Lab2 we want to show how to use Java from Scala. The aim is to rewrite the solution from Lab1 using Java collection types, namely ...

  • List and LinkedList from java.util and
  • LoopingListIterator from org.apache.commons.collections.iterators

Hints

  • Use mvnrepository.com to find out how to update the build.sbt with the library dependency for the Apache common collections lib.
  • Use the import ...{Original => Now} syntax to rename the classes.
  • Use asInstanceOf[T] to cast java.lang.Object into something that you want/need.

LabN - Thinks to do, when you are getting bored

  • Help others with their implementation.
  • Rewrite the solution and use recursion instead of iteration to find the solution.
  • Extend RingIterator with Logged and add logging. Test it with the ConsoleLogger.

scala-tcd-funcprog's People

Contributors

kieranmanning avatar lmcguinn avatar tom-curran avatar bobjflong avatar martinpdd8 avatar fitzpasd avatar walsha41 avatar hooperk avatar

Watchers

Adam Willoughby-Knox avatar James Cloos avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.