Skip to content

Commit

Permalink
Merge branch 'develop' into branchedForIssue85
Browse files Browse the repository at this point in the history
  • Loading branch information
kulsoom2003 authored Oct 23, 2024
2 parents 6c7c2f5 + 02b4872 commit 8e8f743
Show file tree
Hide file tree
Showing 12 changed files with 20 additions and 31 deletions.
2 changes: 1 addition & 1 deletion book/src/pages/cycles/composition.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ dropShadow(star)

This shows how the composed function applies the output of the first function to the second function: we first mirror the star and then add a drop shadow.

Let's see how we can apply function composition to our examples of parametric curves. One limitation of the parametric cures we've created so far is that their size is fixed. For example when we defined `parametricCircle` we fixed the radius at 200.
Let's see how we can apply function composition to our examples of parametric curves. One limitation of the parametric curves we've created so far is that their size is fixed. For example when we defined `parametricCircle` we fixed the radius at 200.

```scala mdoc:silent
def parametricCircle(angle: Angle): Point =
Expand Down
2 changes: 1 addition & 1 deletion book/src/pages/expressions/02-starting.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Starting to Program

It's time to write our first program. For this we're going to use a Scala *worksheet*. Worksheets make is very easy to run short programs, so are ideal for our first adventures in programming. (For longer programs we usually write code a different way, but we'll worry about that when we get to it.)
It's time to write our first program. For this we're going to use a Scala *worksheet*. Worksheets make it very easy to run short programs, so are ideal for our first adventures in programming. (For longer programs we usually write code a different way, but we'll worry about that when we get to it.)

To create a worksheet:

Expand Down
2 changes: 1 addition & 1 deletion book/src/pages/expressions/04-types.md
Original file line number Diff line number Diff line change
Expand Up @@ -14,4 +14,4 @@ Types are worked out in a process known as a *type-checking*, which is part of *

Only programs that successfully compile can be run. We can think of compilation as being analogous to the rules of grammar in writing. The sentence "FaRf fjrmn;l df.fd" is syntactically incorrect in English. The arrangement of letters doesn't form any words. The sentence "dog flying a here no" is made out of valid words but their arrangement breaks the rules of grammar, which is analogous to the type checks that Scala performs.

It is important to remember that type checking is done before a program runs. If you have used a language like Python or Javascript, which are sometimes called "dynamically typed", there is no type checking done before a program runs. In a "statically typed" language like Scala the type checking catches some potential errors for us before we run the code. What is sometimes called a type in a dynamically typed language is *not* a type as we understand it here. Types, for us, exist at the time when a program is compiled, which we will call *compile time*. At time when a program runs, which we call *run time*, we have only values. Values may record some information about the type of the expression that created them. If they do we call these *tags*, or sometimes *boxes*. Not all values are tagged or boxed. Avoiding tagging, which is also called *type erasure*, allows for more efficient programs.
It is important to remember that type checking is done before a program runs. If you have used a language like Python or Javascript, which are sometimes called "dynamically typed", there is no type checking done before a program runs. In a "statically typed" language like Scala the type checking catches some potential errors for us before we run the code. What is sometimes called a type in a dynamically typed language is *not* a type as we understand it here. Types, for us, exist at the time when a program is compiled, which we will call *compile time*. At the time when a program runs, which we call *run time*, we have only values. Values may record some information about the type of the expression that created them. If they do we call these *tags*, or sometimes *boxes*. Not all values are tagged or boxed. Avoiding tagging, which is also called *type erasure*, allows for more efficient programs.
2 changes: 1 addition & 1 deletion book/src/pages/flowers/functions.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ import doodle.syntax.all._
import doodle.image.syntax.all._
```

Let's motivate functions by look at structural recursion over the natural numbers, and trying to capture in code the pattern we've used many times.
Let's motivate functions by looking at structural recursion over the natural numbers, and trying to capture in code the pattern we've used many times.

We have written a lot of structural recursions over the natural numbers. We started with code like

Expand Down
9 changes: 5 additions & 4 deletions book/src/pages/foreword-1.md
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ Firstly, we believe that functional programming is the future.
Since we're assuming you have little programming experience we won't go into the details of the differences between functional programming and object-oriented programming that you may have already experienced.
Suffice to say there are different ways to think about and write computer programs, and we've chosen the functional programming approach.

The reason for choosing functional programming are more interesting.
The reasons for choosing functional programming are more interesting.
It's common to teach programming by what we call the "bag of syntax" approach.
In this approach a programming language is taught a collection of syntactical features (variables, for loops, while loops, methods) and students are left to figure out on their own when to use each feature.
We've seen this method fail both when we were undergraduates learning programming, and as postgraduates teaching programming, as students simply have no systematic way to break down a problem and turn it into code.
Expand All @@ -27,7 +27,7 @@ The students that remained tended to, like us, already have extensive programmin

Let's think back to primary school maths, specifically column addition.
This is the basic way we're taught to add up numbers when they're too big to do in our head.
So, for example, adding up 266 + 385, we would line up the columns, carry the tens and so on.
So, for example, if we were adding up 266 + 385, we would line up the columns, carry the tens and so on.
Now maybe maths wasn't your favorite subject but there are some important lessons here.
The first is that we're given a systematic way to arrive at the solution.
We can *calculate* the solution once we realise this is a problem that requires column addition.
Expand All @@ -43,7 +43,7 @@ The code itself is not the interesting part.
We're teaching functional programming using Scala, but not Scala itself.
Scala is a language that is in demand right now.
Scala programmers can relatively easily get jobs in a variety of industries, and this is an important motivation for learning Scala.
One of the reasons for Scala's popularity is that is straddles object-oriented programming, the old way of programming, and functional programming.
One of the reasons for Scala's popularity is that it straddles object-oriented programming, the old way of programming, and functional programming.
There is a lot of code written in an object-oriented style, and a lot of programmers who are used to that style.
Scala gives a gentle way from object-oriented programming to functional programming.
However this means Scala is a large language, and the interaction between the object-oriented and functional parts can be confusing.
Expand All @@ -66,7 +66,8 @@ Scala textbooks out there, including our own [Essential Scala][essential-scala].

If you are working through the exercises on your own,
we highly recommend joining our [Discord server][creative-scala-discord]
to provide get help with the exercises and provide feedback on the book.
to get help with the exercises and provide feedback on the book.


The text of [Creative Scala][github-creative-scala] is open source,
as is the source code for the [Doodle][github-doodle]
Expand Down
2 changes: 1 addition & 1 deletion book/src/pages/foreword-2.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Compared to the first edition, the intention for the second edition of Creative
Many things will stay the same:

- a focus on fundamentals of programming language theory, such as models of evaluation, and the patterns behind programming, such as structural recursion; and
- a target audience of programmers who are new to coding and without a STEM background. This means some material on process that might be absent when targetting more experienced developers.
- a target audience of programmers who are new to coding and without a STEM background. This means some material on processes might be absent when targetting more experienced developers.

One more thing: the name may change as well! I'm not sure Creative Scala fits the book I'm aiming for.

Expand Down
2 changes: 1 addition & 1 deletion book/src/pages/fractals/auxillary-parameter.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,7 +76,7 @@ Now we've seen the auxiliary parameter method let's practice using it.

@:exercise(Gradient Boxes)

In this exercise we're going to draw a picture like that shown below
In this exercise we're going to draw a picture like that shown below.
We already know how to draw a line of boxes.
The challenge in this exercise is to make the color change at each step.

Expand Down
4 changes: 2 additions & 2 deletions book/src/pages/methods/writing-methods.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ Let's turn `boxes` up to eleven by making the color of the boxes change in a smo

To minimise the amount of code we have to write, implement this by writing *two* methods.
The first method, `box`, should accept a `Color` and an `Angle` and create a box with the color spun by the angle.
The second method, `graidentBoxes`, should accept a `Color` and return an `Image` of five boxes filled with a gradient starting from the given color and changing by `15.degrees` at each successive box. `gradientBoxes` should make use of `box`.
The second method, `gradientBoxes`, should accept a `Color` and return an `Image` of five boxes filled with a gradient starting from the given color and changing by `15.degrees` at each successive box. `gradientBoxes` should make use of `box`.
Remember to write out the method skeletons first.

@:figure{ img = "gradient-boxes.svg", key = "#fig:methods:gradient-boxes", caption = "Five boxes filled with a gradient starting from Royal Blue" }
Expand Down Expand Up @@ -92,7 +92,7 @@ def box(color: Color, spin: Angle): Image =
def gradientBoxes(color: Color): Image = {
box(color, 0.degrees) beside
box(color, 15.degrees) beside
box(color, 20.degrees) beside
box(color, 30.degrees) beside
box(color, 45.degrees) beside
box(color, 60.degrees)
}
Expand Down
2 changes: 1 addition & 1 deletion book/src/pages/part-one-introduction.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ In this first part of the book, which covers several chapters, we have four lear

1. to understand a basic model of how code runs, known as the substitution model of evaluation;
2. to apply structural recursion over the natural numbers;
3. tou understand composition and abstraction using functions; and
3. to understand composition and abstraction using functions; and
4. to get comfortable writing, running, and debugging code.

We'll do this by creating computer graphics, part of subfield of computing known as [creative coding](https://en.wikipedia.org/wiki/Creative_coding).
Expand Down
2 changes: 1 addition & 1 deletion book/src/pages/recursion/boxes.md
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,7 @@ All you to do is change `beside` to `above` in `boxes`.
def stackedBoxes(count: Int): Image =
count match {
case 0 => Image.empty
case n => aBox.beside(stackedBoxes(n-1))
case n => aBox.above(stackedBoxes(n-1))
}
```
@:@
9 changes: 4 additions & 5 deletions book/src/pages/setup/background.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ If you're not, this will hopefully give some useful context to the software we'l
Back when the world was young and computing was in its infancy, the common user interface of graphical windows, a cursor controlled by a mouse, and interaction by *direct manipulation* didn't exist.
Instead users typed in commands at a device called a *terminal*.
The direct manipulation interface is superior for most uses, but there are some cases for which the terminal or *command line* is preferable.
For example, if we wanted to work out how much space was used by all the files which names starting with `data` in Linux or OS X we can execute the command
For example, if we wanted to work out how much space was used by all the files with names starting with `data` in Linux or OS X we can execute the command

```bash
du -hs data*
Expand Down Expand Up @@ -58,10 +58,9 @@ As it does this it performs certain checks on the code.
If these checks don't pass the code won't be compiled and the compiler will print an error message instead.
We'll learn more about what the compiler can check and what it can't in the rest of this book.

When we said the compiler translates the code is something the computer can run, this is not the complete truth in the case of Scala.
When we said the compiler translates the code into something the computer can run, this is not the complete truth in the case of Scala.
The output of the compiler is something called bytecode, and another program, called the Java Virtual Machine (JVM), runs this code@:fnref(complications).


### Integrated Development Environments

Integrated development environments (IDEs) are an alternative approach that combine a text editor, a compiler, and several other programmer tools into a single program.
Expand All @@ -74,7 +73,7 @@ If you're already used to an IDE then IntelliJ IDEA is currently the best IDE fo

Version control is the final tool we'll use.
A version control system is a program that allows us to keep a record of all the changes that have been made to a group of files.
It's very useful for allowing multiple people to work on a project at the same time, and it ensures people don't accidentally overwrite each others changes.
It's very useful for allowing multiple people to work on a project at the same time, and it ensures people don't accidentally overwrite each other's changes.
This is not a huge concern in Creative Scala, but it is good to get some exposure to version control now.

The version control software we'll use is called Git.
Expand All @@ -91,4 +90,4 @@ Now that we've got some background, let's move on to installing the software we

@:footnote(complications)
This is not itself the entire truth! We usually run Scala code on the JVM, but we can compile Scala to three different formats. The first and most common is JVM bytecode. We can also compile to Javascript, another programming language, which allows us to run Scala code in a web browser. Finally, Scala Native will compile Scala to something a computer *can* run directly without requiring the JVM.
@:@
@:@
13 changes: 1 addition & 12 deletions book/src/pages/setup/terminal.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ cd creative-scala-template
sbt
```

sbt should start. Within sbt type `run` and an image should appear. It it does you have everything correctly installed!
sbt should start. Within sbt type `run` and an image should appear. If it does you have everything correctly installed!

The final step is to load Visual Studio Code and use it to open `Example.scala`, which you can find in `src/main/scala`.

Expand All @@ -79,17 +79,6 @@ After installing [Coursier][coursier]:
git clone https://github.com/creativescala/creative-scala-template.git
```

@:callout(info)
#### Sharing Your Work

There is an alternative setup that involves first forking the Creative Scala template project, and then cloning it to your computer.
This is the setup to choose if you want to share your work with other people; for example you might be taking Creative Scala with a remote instructor or you might just (quite rightfully) be proud of your work.

In this setup you first *fork* the Creative Scala template.
Then you make a clone of *your* fork.
This alternative setup is described in more detail in the section on GitHub later in this chapter.
@:@

5. Open a normal command-prompt. Click on the Windows icon on the bottom left of the screen. In the search box enter "cmd" and run the program it finds. In the window that is opened up type

```bash
Expand Down

0 comments on commit 8e8f743

Please sign in to comment.