Skip to content

Commit 2489748

Browse files
committed
Split introduction into shorter chapters and fix webpage bug
URL escaping stuff
1 parent c66dbf5 commit 2489748

File tree

5 files changed

+170
-169
lines changed

5 files changed

+170
-169
lines changed

Book/build.py

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77

88
import os
99
import shutil
10+
from urllib.parse import quote
1011
from subprocess import Popen, PIPE
1112

1213
def read_file(filepath):
@@ -54,7 +55,7 @@ def build_sections(sources):
5455
next_chap_name = "Table of contents"
5556
if (i + 1) < len(chapters):
5657
next_section, next_chap_name, _ = chapters[i + 1]
57-
next_chap_href = "../{}/{}.html".format(next_section, next_chap_name)
58+
next_chap_href = "../{}/{}.html".format(quote(next_section, safe=''), quote(next_chap_name, safe=''))
5859
if not os.path.exists(section):
5960
os.makedirs(section)
6061
chapter_path = "../../" + chapter_source
@@ -75,10 +76,11 @@ def build_sections(sources):
7576
"lhs-source-href": lhs_source_href,
7677
"lhs-source-name": lhs_source_name,
7778
})
78-
out_path = "{}/{}.html".format(section, chapter_name)
79+
out_path = "{}/{}.html".format(section, chapter_name)
80+
out_path_u = "{}/{}.html".format(quote(section, safe=''), quote(chapter_name, safe=''))
7981
write_string_to_file(chapter, out_path)
8082
copy_images(os.path.dirname(chapter_path), section)
81-
prev_chap_href = "../" + out_path
83+
prev_chap_href = "../" + out_path_u
8284
prev_chap_name = chapter_name
8385

8486
def build_index(sources):
@@ -88,7 +90,7 @@ def build_index(sources):
8890
toc += "<div>" + section_name + "</div>\n"
8991
toc += "<ul>\n"
9092
for (chapter_name, _) in chapter_sources:
91-
chapter_path = "{}/{}.html".format(section_name, chapter_name)
93+
chapter_path = "{}/{}.html".format(quote(section_name, safe=''), quote(chapter_name, safe=''))
9294
toc += "<li><a href=\"{}\">{}</a></li>\n".format(chapter_path, chapter_name)
9395
toc += "</ul>\n</li>\n"
9496
index_template = open_template("index")
@@ -97,7 +99,9 @@ def build_index(sources):
9799

98100
sources = [
99101
("Introduction", [
100-
(">> Start here <<", "Physics/src/Introduction/Introduction.lhs"),
102+
("About this book", "Physics/src/Introduction/About.lhs"),
103+
("So what's a DSL?", "Physics/src/Introduction/WhatIsADsl.lhs"),
104+
("Getting started", "Physics/src/Introduction/GettingStarted.lhs"),
101105
]),
102106
("Calculus", [
103107
("Introduction", "Physics/src/Calculus/Intro.lhs"),
@@ -124,7 +128,6 @@ def build_index(sources):
124128
# ("Gungbräda", "Physics/src/Examples/Gungbraeda.lhs"),
125129
# ("krafter på lådor", "Physics/src/Examples/krafter_pa_lador.lhs"),
126130
# ])
127-
128131
]
129132

130133
if not os.path.exists("build"):

Physics/src/Introduction/About.lhs

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
About this book
2+
======================================================================
3+
4+
You've arrived at **Learn You a Physics for Great Good**,
5+
the #1 stop for all your beginner-to-intermediate needs of learning
6+
**Physics** through the use of **Domain Specific Languages**
7+
(DSLs).
8+
9+
This book was written as a [BSc thesis
10+
project](https://github.com/DSLsofMath/BScProj2018) at Chalmers
11+
University of Technology as an offshoot of a bachelor's level elective
12+
course [*Domain Specific Languages of
13+
Mathematics*](https://github.com/DSLsofMath/DSLsofMath). The goal of
14+
the the project and the reason for the existence of this book, is to
15+
help (primarily CS) students learn physics better. We think that the use
16+
of domain specific languages to teach the subject will help set these
17+
students in the right mindset to learn physics efficiently and
18+
properly. An observed problem has been that students base their mental
19+
models completely or partially on intuition and incorrect assumptions,
20+
instead of on definitions and proved theorems where validity is
21+
ensured. This may be a bad habit stemming from the way math and
22+
physics is taught in earlier stages of the education, and we think
23+
that DSLs will inherently force students into the right mindset for
24+
learning this subject well! Further, many textbooks on physics are
25+
incredibly thick and boring, so we've decided to emulate the great and
26+
good [Learn You a Haskell for Great
27+
Good](http://learnyouahaskell.com/) in order to provide som comic
28+
relief in between all the dramatic definitions.
29+
30+
In this book, we will study physics through the lens of DSLs. We will
31+
need to pay close attention to definitions, throughly ponder any
32+
non-trivial syntax, and verify (via tests or proofs) that the things
33+
we do are actually correct. The areas covered include such things as:
34+
dimensional analysis, vectors, calculus, and more!
35+
36+
The book is aimed at you who have some knowledge of
37+
[Haskell](https://www.haskell.org/). If you know what a `class` and an
38+
`instance` is, you're probably good to go! Even if you don't we're
39+
sure you could pick it up as we go. We believe in you!
Lines changed: 41 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
2+
3+
4+
5+
What you need to dive in
6+
======================================================================
7+
8+
To just follow along and implement the same stuff we do, a single
9+
document loaded into GHCi will do. For this, you just need to install the
10+
[Haskell Platform](https://www.haskell.org/platform/).
11+
12+
If you want to automatically install any required dependencies, like
13+
[*Hatlab*](https://github.com/DSLsofMath/Hatlab) which will be used
14+
later on, install [Stack](https://haskellstack.org). Stack is a build
15+
system that will automatically get dependencies and build the project
16+
for you. If you want to build the code the same way we do, this is
17+
what you'll need. With Stack installed and [our repository
18+
cloned](https://github.com/DSLsofMath/BScProj2018), enter the
19+
`Physics` directory and type `stack build`. Stack should now download
20+
and compile all necessary dependencies, such that they are avaiable
21+
when you load a module in GHCi.
22+
23+
24+
25+
If you need to sharpen up your skills
26+
======================================================================
27+
28+
If you need to freshen up on your Haskell, [Learn You a Haskell for
29+
Great Good](http://learnyouahaskell.com/) is a great book that covers
30+
all the important stuff in a humorous manner that really holds your
31+
attention.
32+
33+
If you still don't really get what DSLs are all about, try reading the
34+
["notes" (almost a full book really) for the course on DSLs of math at
35+
Chalmers](https://github.com/DSLsofMath/DSLsofMath/tree/master/L/snapshots). If
36+
you're studying at Chalmers, it is even better to actually take the course!
37+
38+
If there's some part of the material that you still think is unclear
39+
(or maybe even wrong? Blasphemy!), please [open an issue on the github
40+
repo!](https://github.com/DSLsofMath/BScProj2018/issues). We'll look
41+
into it!

Physics/src/Introduction/Introduction.lhs

Lines changed: 0 additions & 163 deletions
This file was deleted.
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
So what's a DSL?
2+
======================================================================
3+
4+
In general, a domain specific language is simply a computer language
5+
for a specific domain. It's NOT a synonym for
6+
[jargon](http://www.catb.org/jargon/html/online-preface.html)! DSLs
7+
can be specialized for markup, like
8+
[*HTML*](https://en.wikipedia.org/wiki/HTML); for modelling, like
9+
[*EBNF*](https://en.wikipedia.org/wiki/Extended_Backus%E2%80%93Naur_form);
10+
for shell scripting, like
11+
[*Bash*](https://en.wikipedia.org/wiki/Bash_%28Unix_shell%29); and
12+
more.
13+
14+
The languages we will construct will mostly concern modelling of
15+
physics and mathematics. We will create data structures in Haskell to
16+
represent the same physics calculations that we write on paper, in
17+
such a way that we can write functions to, for example, analyze the
18+
expressions for validity.
19+
20+
Look, we'll demonstrate. Let's say we want to model a language that is
21+
a subset to the common algebra we're all familiar with. Our language
22+
will consist expressions of a single variable and addition. For
23+
example, the following three expressions are all valid in such a language:
24+
25+
$$x + x$$
26+
27+
$$x$$
28+
29+
$$(x + x) + (x + x)$$
30+
31+
When implementing a DSL, we typically start with modelling the
32+
syntax. Let's first declare a data type for the language
33+
34+
> data Expr
35+
36+
Then we interpret the textual description of the language. "Our
37+
language will consist of expressions of a single variable and
38+
addition". Ok, so an expression can be one of two things then: a
39+
single variable
40+
41+
> = X
42+
43+
or two expressions added together.
44+
45+
> | Add Expr Expr
46+
47+
And that's it, kind of! However, a DSL without any associated
48+
functions for validation, symbolic manipulation, evaluation, or
49+
somesuch, is really no DSL at all! We must DO something with it, or
50+
there is no point!
51+
52+
One thing we can do with expressions such as these, is compare whether
53+
two of them are equal. Even without using any numbers, we can test
54+
this by simply counting the $x$s! If both expressions contain the same
55+
number of $x$s, they will be equal!
56+
57+
> eq :: Expr -> Expr -> Bool
58+
> eq e1 e2 = count e1 == count e2
59+
> where count X = 1
60+
> count (Add e1 e2) = count e1 + count e2
61+
62+
We can now test whether our expressions are equal.
63+
64+
< ghci> eq (Add (Add X X) X) (Add X (Add X X))
65+
< True
66+
67+
And NOW that's it (if we want to stop here)! This is a completely
68+
valid (but boring) DSL. We've modelled the syntax, and added a function
69+
that operates symbolically on our language. This is a very small and
70+
simple DSL, and you've likely done something similar before without
71+
even realizing you were constructing a DSL. It can really be that
72+
simple
73+
74+
In other DSLs we may also look at evaluation and the semantics of a
75+
language, i.e. what is the actual type of the result when we
76+
*evaluate* or "compute" our expressions.
77+
78+
Throughout this book we'll construct and use DSLs in many different
79+
ways. Different parts of the physics we look at will require different
80+
DSL treatments, basically. There is no *one* model to use for all
81+
DSLs.

0 commit comments

Comments
 (0)