diff --git a/adt/adt.html b/adt/adt.html index b3fc3575..6065a4af 100644 --- a/adt/adt.html +++ b/adt/adt.html @@ -24,7 +24,7 @@
-</div>
diff --git a/adt/turtle.html b/adt/turtle.html index 2db4f2ee..db5852af 100644 --- a/adt/turtle.html +++ b/adt/turtle.html @@ -24,9 +24,9 @@ -Turtles that can make random choices can lead to more organic images. Can you implement this?
</div>
diff --git a/animation/reactor.html b/animation/reactor.html index 32794025..853a6bb7 100644 --- a/animation/reactor.html +++ b/animation/reactor.html @@ -24,9 +24,9 @@ -Remember you will need to import doodle.reactor._
to make the reactor library available.
Let's see what we can do with these sequences.
diff --git a/collections/index.html b/collections/index.html index 7945ab27..e85ff68e 100644 --- a/collections/index.html +++ b/collections/index.html @@ -24,9 +24,9 @@ -Lists
,
which are without a doubt the best known data type in functional programming.
diff --git a/collections/paths.html b/collections/paths.html
index 9b965aaf..c5aaea6d 100644
--- a/collections/paths.html
+++ b/collections/paths.html
@@ -24,7 +24,7 @@
- </div>
diff --git a/collections/take-home-points.html b/collections/take-home-points.html index 2ea2fe2f..d914de99 100644 --- a/collections/take-home-points.html +++ b/collections/take-home-points.html @@ -26,7 +26,7 @@true
.
----------------------------------------------------------------------------------
The terminology "instance" and "constructor" comes from the field of object-oriented programming.
diff --git a/data/data.html b/data/data.html index dfdda90a..2e40daf0 100644 --- a/data/data.html +++ b/data/data.html @@ -24,7 +24,7 @@ -</div>
diff --git a/declarations/index.html b/declarations/index.html index 769a57e4..cee44895 100644 --- a/declarations/index.html +++ b/declarations/index.html @@ -24,9 +24,9 @@ -</div>
diff --git a/expanding-expressions/02-literals.html b/expanding-expressions/02-literals.html index 5430e65d..dacf59a6 100644 --- a/expanding-expressions/02-literals.html +++ b/expanding-expressions/02-literals.html @@ -106,62 +106,65 @@The first function is
(x: Int) => x * x
-// res10: Function1[Int, Int] = repl.MdocSession$MdocApp0$$Lambda$15718/0x00000001040ca040@6952ddc0
+// res10: Function1[Int, Int] = repl.MdocSession$MdocApp0$$Lambda$14307/0x0000000103cc9840@39be6178
The second is
(c: Color) => c.spin(15.degrees)
-// res11: Function1[Color, HSLA] = repl.MdocSession$MdocApp0$$Lambda$15719/0x00000001040c9040@ee1630
+// res11: Function1[Color, HSLA] = repl.MdocSession$MdocApp0$$Lambda$14308/0x0000000103cca840@5059bfe0
The third is
(image: Image) =>
image.beside(image.rotate(90.degrees))
.beside(image.rotate(180.degrees))
.beside(image.rotate(270.degrees))
.beside(image.rotate(360.degrees))
-// res12: Function1[Image, Image] = repl.MdocSession$MdocApp0$$Lambda$15720/0x00000001040c8840@48d558be
+// res12: Function1[Image, Image] = repl.MdocSession$MdocApp0$$Lambda$14309/0x0000000103ccb040@17b89bb8
</div>
diff --git a/fp/index.html b/fp/index.html index 7d9ed61b..1546b80a 100644 --- a/fp/index.html +++ b/fp/index.html @@ -24,9 +24,9 @@ -</div>
diff --git a/generative/flatmap.html b/generative/flatmap.html index 670b40c6..e91362fb 100644 --- a/generative/flatmap.html +++ b/generative/flatmap.html @@ -26,7 +26,7 @@which makes it clearer that we're generating three different circles. </div>
@@ -390,7 +393,7 @@</div>
diff --git a/generative/for.html b/generative/for.html index b0f6c933..0b4215ef 100644 --- a/generative/for.html +++ b/generative/for.html @@ -24,9 +24,9 @@ -math.random
-// res0: Double = 0.4530569431409891
+// res0: Double = 0.9954682060549414
math.random
-// res1: Double = 0.9303856742653402
+// res1: Double = 0.10521421072837789
Given math.random
we could produce a method that returns a random Angle
like so.
def randomAngle: Angle =
math.random.turns
randomAngle
-// res2: Angle = Angle(5.496265207806127)
+// res2: Angle = Angle(3.1392956029090726)
randomAngle
-// res3: Angle = Angle(0.4046476703016074)
+// res3: Angle = Angle(3.100518546215859)
Why might we not want to do this? What principle does this break?
<div class="solution"> Generating random numbers in this way breaks substitution. Remember substitution says wherever we see an expression we should be able to substitute the value it evaluates to without changing the meaning of the program. Concretely, this means
val result1 = randomAngle
-// result1: Angle = Angle(4.3599342001383565)
+// result1: Angle = Angle(2.405108659444256)
val result2 = randomAngle
-// result2: Angle = Angle(3.8324639060700396)
+// result2: Angle = Angle(1.5214969602359836)
and
val result1 = randomAngle
-// result1: Angle = Angle(5.666935389592784)
+// result1: Angle = Angle(3.586178430801598)
val result2 = result1
-// result2: Angle = Angle(5.666935389592784)
+// result2: Angle = Angle(3.586178430801598)
should be the same program and clearly they are not. </div>
What should we do? Suffer the slings and arrows of outrageous computational models, or take arms against a sea of side-effects, and by opposing end them! There's really only one choice.
We've gone from very structured to very random pictures. It would be nice to find a middle ground that incorporates elements of randomness and structure.
diff --git a/generative/random.html b/generative/random.html index 368d1396..61e7c589 100644 --- a/generative/random.html +++ b/generative/random.html @@ -24,9 +24,9 @@ -No random numbers are actually created until we call the run
method.
randomDouble.run
-// res0: Double = 0.1252702864238293
+// res0: Double = 0.9382616821759079
The type Random[Double]
indicates we have something that will produce a random Double
when we run
it. Just like with Image
and draw
, substitution holds with Random
up until the point we call run
.
Table Table generative:random shows some of the ways to construct Random
values.
When we run
RandomAngle
we can generate randomly created Angle
randomAngle.run
-// res1: Angle = Angle(3.402457195315217)
+// res1: Angle = Angle(5.874329205605681)
randomAngle.run
-// res2: Angle = Angle(3.795544571755059)
+// res2: Angle = Angle(5.0618043742186725)
</div>
diff --git a/index.html b/index.html index 9b76df0c..8838bb20 100644 --- a/index.html +++ b/index.html @@ -106,62 +106,65 @@blah blah blah blah blah
diff --git a/links.html b/links.html index 1d732d8e..4bff96c8 100644 --- a/links.html +++ b/links.html @@ -24,9 +24,9 @@ -We'll start our exploration of data science by looking at climate data. Climate data is readily available and climate is a topical issue.
+To start we'll need some data. ... data location ... HadCRUT5 temperature anomaly data. + Description.
+HadCRUT.5 data were obtained from http://www.metoffice.gov.uk/hadobs/hadcrut5 on 27 October 2023 and are © British Crown Copyright, Met Office 2021, provided under an Open Government License, http://www.nationalarchives.gov.uk/doc/open-government-licence/version/3/
+This data set has one reading for each month from 1850 to 2023, making 2084 readings. This gives us enough data that working with it will be interesting but not so much that it's overwhelming.
+If we look at the file we see it looks like the following:
+Time,Anomaly (deg C),Lower confidence limit (2.5%),Upper confidence limit (97.5%)
+1850-01,-0.67456436,-0.98177195,-0.3673568
+1850-02,-0.333416,-0.700901,0.034069024
+1850-03,-0.59132266,-0.9339191,-0.2487262
+1850-04,-0.58872116,-0.8982594,-0.27918297
+ This type of file is known as comma separated values (CSV). + Each line, except the first, consists of values, otherwise known as fields. + Each field is separated by a comma. + The first line, the heading, gives names for the fields. + So we can see that the fields are, in order, time, temperature anomaly, and lower and upper confidence bounds on the anomaly.
+If we look at the first line
+1850-01,-0.67456436,-0.98177195,-0.3673568
+ we can see that the time is 1850-01
, the anomaly -0.67456436
, the lower confidence bound -0.98177195
, and the upper confidence bound -0.3673568
.
Now we understand the data format, let's see how to load it into Scala. + This will take several stages:
+String
;It seems a lot but we'll take it step-by-step and get there soon enough, and along the way we'll learn lots of interesting Scala programming techniques.
+ +scala.io.Source
Source.getLines().toList
Ravi Chugh looks at the intersection of human-computer interaction and programming languages. I find his work really inspiring for imagining a different, yet attainable, way of working with computers. Going further afield, Chris Martens looks at the intersection of programming languages and games.
If you have decided you can't live without more creative computing in your life, and the above don't slake your thirst, Kadenze is probably the premier source for online courses. For even more creative computing, many universities now offer degree programs in the field. Notable examples are the Creative Computing Institute in London, and the Tisch School of Art in New York City, but there are many others.
diff --git a/part-one-introduction.html b/part-one-introduction.html index a8c1a273..53d4da06 100644 --- a/part-one-introduction.html +++ b/part-one-introduction.html @@ -106,62 +106,65 @@map
, filter
, flatMap
, foldLeft
, etc.Exploratory data analysis + - loading and cleaning data + - Regular expressions + - Source or fs2 data or something else... + - scatter and line plots + -
+ +</div>
diff --git a/sequences/lists.html b/sequences/lists.html index ddbd86e5..5b180187 100644 --- a/sequences/lists.html +++ b/sequences/lists.html @@ -26,7 +26,7 @@</div>
diff --git a/sequences/map.html b/sequences/map.html index d540e6b6..47aeab71 100644 --- a/sequences/map.html +++ b/sequences/map.html @@ -24,9 +24,9 @@ -</div>
</div>
diff --git a/sequences/stars.html b/sequences/stars.html index b4511f85..74ad1865 100644 --- a/sequences/stars.html +++ b/sequences/stars.html @@ -24,9 +24,9 @@ -</div>
diff --git a/setup/background.html b/setup/background.html index 05e2f12b..362fab5d 100644 --- a/setup/background.html +++ b/setup/background.html @@ -106,62 +106,65 @@<div class="solutions"> </div>
diff --git a/substitution/conclusions.html b/substitution/conclusions.html index f300c5ba..ab85e265 100644 --- a/substitution/conclusions.html +++ b/substitution/conclusions.html @@ -106,62 +106,65 @@In this exercise we want you to use your creativity to construct a picture of a natural object using your L-system implementation. You've seen many examples already that you can use an inspriation.
Using turtle graphics and another concept, known as an L-system, we can create images that mimic nature such as the plant in Figure turtles:plant.
map
we cannot change the number of elements in a list. Therefore mapping 1 to n
, as we did int the code above, won't work. We could map over 1 to (n*2)
, and on, say, odd numbers move forward and on even numbers turn, but this is rather inelegant. It seems it would be simpler if we had an abstraction like map
that allowed us to change the number of elements in the list as well as transform the individual elements.
</div>