<?xml version="1.0" encoding="utf-8"?>
<!-- generator="FeedCreator 1.7.2-ppt DokuWiki" -->
<?xml-stylesheet href="https://ocw.cs.pub.ro/ppcarte/lib/exe/css.php?s=feed" type="text/css"?>
<rdf:RDF
    xmlns="http://purl.org/rss/1.0/"
    xmlns:rdf="http://www.w3.org/1999/02/22-rdf-syntax-ns#"
    xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
    xmlns:dc="http://purl.org/dc/elements/1.1/">
    <channel rdf:about="https://ocw.cs.pub.ro/ppcarte/feed.php">
        <title>books pp:2023:scala</title>
        <description></description>
        <link>https://ocw.cs.pub.ro/ppcarte/</link>
        <image rdf:resource="https://ocw.cs.pub.ro/ppcarte/lib/tpl/bootstrap3/images/favicon.ico" />
       <dc:date>2026-06-10T05:59:36+03:00</dc:date>
        <items>
            <rdf:Seq>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs02&amp;rev=1678883500&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs03&amp;rev=1678883564&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs04&amp;rev=1678883625&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs05&amp;rev=1678883720&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs06&amp;rev=1679501979&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs07&amp;rev=1680001578&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs08&amp;rev=1680094859&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:ide&amp;rev=1677662613&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l00&amp;rev=1677662463&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l01&amp;rev=1678899117&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l02&amp;rev=1680445704&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l03&amp;rev=1680445728&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l04&amp;rev=1680445842&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l05&amp;rev=1680724999&amp;do=diff"/>
                <rdf:li rdf:resource="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l06&amp;rev=1680929353&amp;do=diff"/>
            </rdf:Seq>
        </items>
    </channel>
    <image rdf:about="https://ocw.cs.pub.ro/ppcarte/lib/tpl/bootstrap3/images/favicon.ico">
        <title>books</title>
        <link>https://ocw.cs.pub.ro/ppcarte/</link>
        <url>https://ocw.cs.pub.ro/ppcarte/lib/tpl/bootstrap3/images/favicon.ico</url>
    </image>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs02&amp;rev=1678883500&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-15T14:31:40+03:00</dc:date>
        <title>pp:2023:scala:curs02</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs02&amp;rev=1678883500&amp;do=diff</link>
        <description>Curs 02. Functii de ordin superior


import scala.annotation.tailrec

val x = 0
&quot;Matei&quot;

val b = if (x &gt; 0) 1 else 0

var y = 0
def f(x: Int): Int = {
  var y = x
  y = y + 1
  y
}
// definitia unei functii
// care se numeste f
// si are un parametru de tip int, care se numeste x
// f intoarce un Int
// expresia la care se evalueaza f este x + 1

f(1)

def myAddition(x: Int, y: Int): Int = x + y
myAddition(2,3)

def inRange(start: Int, stop: Int, x: Int):Boolean =
  x &gt;= start &amp;&amp; x &lt;= stop


def…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs03&amp;rev=1678883564&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-15T14:32:44+03:00</dc:date>
        <title>pp:2023:scala:curs03</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs03&amp;rev=1678883564&amp;do=diff</link>
        <description>Curs 03. Functii de ordin superior


/*
Suppose we want to compute the sum of all integers from a range:
 */

def sumAll(start: Int, stop: Int): Int = {
  def loop (i: Int, crtSum: Int): Int =
    if (i &gt; stop) crtSum
    else loop(i+1,crtSum+i)
  loop(start,0)
}
//... as well as the sum x*x of all elements
def sumSquares(start: Int, stop: Int): Int = {
  def loop (i: Int, crtSum: Int): Int =
    if (i &gt; stop) crtSum
    else loop(i+1,crtSum+i*i)
  loop(start,0)
}
// we can see that the code is …</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs04&amp;rev=1678883625&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-15T14:33:45+03:00</dc:date>
        <title>pp:2023:scala:curs04</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs04&amp;rev=1678883625&amp;do=diff</link>
        <description>Curs 04. Tipuri de date functionale in Scala


/*

class Point (val x: Int, val y: Int) {

  def higher(p: Point): Boolean = p.x &gt; this.x

  // string interpolation
  override def toString: String = s&quot;(${x},${y})&quot;
}

new Point(1,2)
val p = new Point(1,2)
p.x

new Point(1,2) == new Point(1,2)
 */

trait Nat  // pt moment, acelasi lucru cu interface

case object Zero extends Nat
case class Succ(next: Nat) extends Nat

Succ(Succ(Succ(Zero)))
Succ(Zero) == Succ(Zero)

def add(n: Nat, m: Nat): Nat =
…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs05&amp;rev=1678883720&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-15T14:35:20+03:00</dc:date>
        <title>pp:2023:scala:curs05</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs05&amp;rev=1678883720&amp;do=diff</link>
        <description>Curs 5. Liste in Scala


// 1 + 2 * 3

trait Expr {
  def eval(): Int
}

case class Atom(x: Int) extends Expr {
  override def eval(): Int = x
}
case class Add(e1: Expr, e2: Expr) extends Expr {
  override def eval(): Int = e1.eval() + e2.eval()
}
case class Mult(e1: Expr, e2: Expr) extends Expr{
  override def eval(): Int = e1.eval() * e2.eval()
}

Add(Atom(1),Mult(Atom(2),Atom(3))).eval()


/*
   - calculeaza valoarea unei expresii
   - group:
     e1 * e2 + e1 * e3 = e1 * (e2 + e3)
 */
def gr…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs06&amp;rev=1679501979&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-22T18:19:39+03:00</dc:date>
        <title>pp:2023:scala:curs06</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs06&amp;rev=1679501979&amp;do=diff</link>
        <description>Curs 6. Aplicatii cu liste


/*
Avem un sir, care contine numere si whitespace.
  &quot;12 4 560 3&quot;

 Vrem sa realizam un split dupa whitespace al acestui sir:
 &quot;12&quot;, &quot;4&quot;, &quot;560&quot;, &quot;3&quot;
 */
type Sir = List[Char]




/*
Haide sa parsam un CSV.
a,b,c
d,e,f
g,h,i
 */


val csvContents: Sir =
  &quot;&quot;&quot;a,b,c
    |d,e,f
    |g,h,i
    |&quot;&quot;&quot;.stripMargin.toList

type Table = List[List[Sir]]

//split('\n')(csvContents)

//split('\n')(csvContents)
//  .map(split(','))

def readCSV(content: Sir): Table = {
  def split(…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs07&amp;rev=1680001578&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-28T14:06:18+03:00</dc:date>
        <title>pp:2023:scala:curs07</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs07&amp;rev=1680001578&amp;do=diff</link>
        <description>Curs 07. For expressions si companion objects


/*
  Ce facem azi? - diverse

 */

// Ranges
1.to(10)
val f: (Int,Int) =&gt; Range =
  (start,stop) =&gt; start.to(stop)

1.to(10) // nu neaparat natural
1 to 10 // acelasi lucru

/*
mai general:
&lt;object&gt;.&lt;method&gt;(&lt;p1&gt;, ... &lt;pn&gt;)
&lt;object&gt; &lt;method&gt; &lt;p1&gt; &lt;p2&gt; .... &lt;pn&gt;
 */

1 until 10
1 to 10 by 2

trait Nat {
  def +(other: Nat): Nat
  def -(other: Nat): Nat
}

case object Zero extends Nat {
  override def + (other: Nat): Nat = other
  override def - (oth…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs08&amp;rev=1680094859&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-29T16:00:59+03:00</dc:date>
        <title>pp:2023:scala:curs08</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:curs08&amp;rev=1680094859&amp;do=diff</link>
        <description>Curs 08. Covarianta tipurilor


trait Nat {
  def +(n: Nat): Nat
  def -(n: Nat): Nat  // difference over naturals, not integers
}

case object Zero extends Nat {
  override def + (n: Nat): Nat = n
  override def - (n: Nat): Nat = Zero
}

case class Succ(n: Nat) extends Nat {
  override def + (m: Nat): Nat = Succ(n + m)
  override def - (m: Nat): Nat =
    m match {
      case Zero =&gt; Succ(n)
      case Succ(mp) =&gt; n - mp
    }
}

/*
 Vreau sa iau o lista de intregi (Int) si sa o transform
 intr…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:ide&amp;rev=1677662613&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-01T11:23:33+03:00</dc:date>
        <title>pp:2023:scala:ide</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:ide&amp;rev=1677662613&amp;do=diff</link>
        <description>Scala setup

Installation

Scala can be downloaded and installed on either a Windows or NIX platform (e.g. Linux, OS-X) here. For this lecture you must install Scala 3, and we recommend installing it using Coursier (see the previous link)

IDE

One of the most widely used IDE (Integrated Development Environment) for Scala is:</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l00&amp;rev=1677662463&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-01T11:21:03+03:00</dc:date>
        <title>pp:2023:scala:l00</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l00&amp;rev=1677662463&amp;do=diff</link>
        <description>Scala setup

Installation

Scala can be downloaded and installed on either a Windows or NIX platform (e.g. Linux, OS-X) here. For this lecture you must install Scala 3, and we recommend installing it using Coursier (see the previous link)

IDE

One of the most widely used IDE (Integrated Development Environment) for Scala is:</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l01&amp;rev=1678899117&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-03-15T18:51:57+03:00</dc:date>
        <title>pp:2023:scala:l01</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l01&amp;rev=1678899117&amp;do=diff</link>
        <description>Lab 1. Introduction to Scala

 Objectives: 

	*  get yourself familiar with Scala syntax basics
	*  practice writing tail-recursive functions as an alternative to imperative loops 
	*  keep your code clean and well-structured.

 Create a new Scala worksheet to write your solutions $ n$$ 1 + 2^2 + 3^2 + \ldots + (n-1)^2 + n^2$$ x$$ x_0, x_1, \ldots, x_n$$ (\ldots((x - x_0) - x_1) - \ldots x_n)$$ x$$ x_0, x_1, \ldots, x_n$$ x_0 - (x_1 - \ldots - (x_n - x)\ldots)$$ \sqrt{a}$$ x_0 = 1$$ x_{n+1} = \d…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l02&amp;rev=1680445704&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-04-02T17:28:24+03:00</dc:date>
        <title>pp:2023:scala:l02</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l02&amp;rev=1680445704&amp;do=diff</link>
        <description>Lab 2. High order functions

Objectives:

	*  implement and use higher-order functions. A higher-order function takes other functions as parameter or returns them
	*  implement curry and uncurry functions, and how they should be properly used (review lecture).$ a_1, a_2, \ldots, a_k$$ f(a_1)\;op\;f(a_2)\;op\;\ldots f(a_k)$$ f(x) = a*x + b$$ \Delta y$$ \Delta x$</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l03&amp;rev=1680445728&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-04-02T17:28:48+03:00</dc:date>
        <title>pp:2023:scala:l03</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l03&amp;rev=1680445728&amp;do=diff</link>
        <description>Lab 3. Lists in Scala

Objectives:

	*  get familiar with pattern matching lists, as well as common list operations from Scala and how they work
	*  get familiar with common higher-order functions over lists (partition, map, foldRight, foldLeft, filter)</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l04&amp;rev=1680445842&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-04-02T17:30:42+03:00</dc:date>
        <title>pp:2023:scala:l04</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l04&amp;rev=1680445842&amp;do=diff</link>
        <description>Lab 4. Data types in Scala

Objectives:

	*  get familiar with algebraic data types
	*  get familiar with pattern matching and recursion with them

4.1 Natural Numbers

Given the following implementation of the natural numbers, solve the next few exercices.$  \displaystyle \left(\begin{array}{ccc} 1 &amp; 2 &amp; 3 \\ 4 &amp; 5 &amp; 6 \\ 7 &amp; 8 &amp; 9 \\ \end{array}\right)$$  \displaystyle 2 * \left(\begin{array}{ccc} 1 &amp; 2 &amp; 3 \\ 4 &amp; 5 &amp; 6 \\ 7 &amp; 8 &amp; 9 \\ \end{array}\right) = \left(\begin{array}{ccc} 2 &amp; 4 &amp; 6 \\…</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l05&amp;rev=1680724999&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-04-05T23:03:19+03:00</dc:date>
        <title>pp:2023:scala:l05</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l05&amp;rev=1680724999&amp;do=diff</link>
        <description>Lab 5. Polymorphism

5.1. Maps

Maps are collections of (key, value) pairs. Keys should be unique, and every key is associated with a value. 

Some of the fundamental operations on maps include:

	*  retrieving / updating the value associated with a key</description>
    </item>
    <item rdf:about="https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l06&amp;rev=1680929353&amp;do=diff">
        <dc:format>text/html</dc:format>
        <dc:date>2023-04-08T07:49:13+03:00</dc:date>
        <title>pp:2023:scala:l06</title>
        <link>https://ocw.cs.pub.ro/ppcarte/doku.php?id=pp:2023:scala:l06&amp;rev=1680929353&amp;do=diff</link>
        <description>Lab 6. Scala on steroids

5-Tic-Tac-Toe

Tic Tac Toe is usually played on a 3×3 board, marking positions by each player in rounds. Our game is slightly different (usually called 5-in-a-row):

	*  it can be played on a square board of any size larger or equal to 5</description>
    </item>
</rdf:RDF>
