Download presentation
Presentation is loading. Please wait.
1
1 Gentle Introduction to Programming Tirgul 2: Scala “hands on” in the lab
2
2 Today Understanding compiler messages Debugger Self work - recursion Home work
3
3 Understanding Compiler Messages Open the interpreter, try the following lines of code, and try to understand what the compiler means, and how to solve it val x = 5 x = 6 Println(“123”) val f = (x : Int => x + 1) if x > f(x) x = 9 val f = (x : int) => x + 1
4
4 And In Eclipse Select and copy a program of your choice to Eclipse How are compilation errors marked in Eclipse? Perform compilation errors purposely and see how the compiler’s errors look like: Change an upper-case letter to lower case Remove a closing brackets Where are the compiled files?
5
5 Today Understanding compiler messages Debugger Self work - recursion Home work
6
6 The Debugger Use the program you used earlier Set a break point and start following your program step by step Step in to a function and out from it Make sure you take a look at the program’s stack and variables’ state Here are the technical instructions
7
7 Debugger – Add Breakpoint Right click on the desired line “Toggle Breakpoint”
8
8 Debugger – Start Debugging breakpoint debug
9
9 Debugger – Debug Perspective
10
10 Debugger – Debugging Current state Current location Back to Scala perspective
11
11 Today Understanding compiler messages Debugger Self work - recursion Home work
12
Decimal Binary We want to print the binary representation of a decimal number Examples: 0 -> 0 8 -> 1000 12 -> 1100 31 -> 11111
13
Decimal Binary Recursively The conversion of a number d from decimal to binary: If d is 0 or 1 – write d to the left and stop, else: If d is even, write ‘0’ to the left If d is odd, write ‘1’ to the left Repeat recursively with floor(d/2)
14
Example: d = 14 d Output at the end of stage Action at the end of stage 140 Insert 0 to left of output; divide d by 2 710 Insert 1 to left of output; divide d by 2 and round down 3110 Insert 1 to left of output; divide d by 2 and round down 11110 Insert 1 to left of output; return.
15
Solution Dec2Bin.scala
16
16 Today Understanding compiler messages Debugger Self work - recursion Home work
17
Exercise Write a function that simulates print on positive integers The function should print one digit at time Example: printRec(1234) 1234
Similar presentations
© 2025 SlidePlayer.com Inc.
All rights reserved.