Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Both sides previous revision Previous revision
sesiuni:scala:lab5 [2016/07/01 17:02]
dciocirlan [Practice]
sesiuni:scala:lab5 [2016/07/01 17:03] (current)
dciocirlan [Practice]
Line 23: Line 23:
 </​code>​ </​code>​
  
-  - Write a simple function that uses pattern matching and converts an ''​Expr''​ to a String:\\ <code scala>​def show(e: Expr): String </​code>​+  - Write a simple function that uses pattern matching and converts an ''​Expr''​ to a human readable ​String, e.g. ''​1 + 2''​:\\ <code scala>​def show(e: Expr): String </​code>​
   - Add a new case class for products, call it ''​Prod''​.\\ Modify your function to show the correct String representation,​ with the correct precedence shown by parentheses.\\ Try to minimize the number of parentheses.\\ For example ''​Sum(Prod(Number(2),​ Number(1)), Number(3)).show''​ should return ''"​2 * 1 + 3"''​.\\ But''​Prod(Sum(Number(2),​ Number(1)), Number(3)).show''​ should return ''"​(2 + 1) * 3"''​.   - Add a new case class for products, call it ''​Prod''​.\\ Modify your function to show the correct String representation,​ with the correct precedence shown by parentheses.\\ Try to minimize the number of parentheses.\\ For example ''​Sum(Prod(Number(2),​ Number(1)), Number(3)).show''​ should return ''"​2 * 1 + 3"''​.\\ But''​Prod(Sum(Number(2),​ Number(1)), Number(3)).show''​ should return ''"​(2 + 1) * 3"''​.
   - Let's complicate this a bit.\\ Create a new Case class for variables, call it ''​Var''​ which takes a String as a parameter.\\ This will denote a variable in a mathematical expression.\\ Incorporate this into the ''​show''​ function you have just created.   - Let's complicate this a bit.\\ Create a new Case class for variables, call it ''​Var''​ which takes a String as a parameter.\\ This will denote a variable in a mathematical expression.\\ Incorporate this into the ''​show''​ function you have just created.
sesiuni/scala/lab5.txt · Last modified: 2016/07/01 17:03 by dciocirlan