Updated Introduction (markdown)

Calvin Rose 2018-05-18 21:43:03 -04:00
parent 0a71e64668
commit fa18463e10
1 changed files with 9 additions and 14 deletions

@ -1,12 +1,12 @@
# Hello, world!
Following tradition, a simple Dst program will simply print "Hello, world!".
Following tradition, a simple Dst program will print "Hello, world!".
```
(print "Hello, world!")
```
Put the following code in a file call `hello.dst`, and run `./dst hello.dst`.
Put the following code in a file named `hello.dst`, and run `./dst hello.dst`.
The words "Hello, world!" should be printed to the console, and then the program
should immediately exit. You now have a working dst program!
@ -15,8 +15,8 @@ or read eval print loop. This is a mode where Dst functions like a calculator,
reading some input from stdin, evaluating it, and printing out the result, all
in an inifinte loop. This is a useful mode for exploring or prototyping in Dst.
This is about the simplest program one can write, and consists of precisely
three elements. This first element is the `print` symbol. This is a function
This hello world program is about the simplest program one can write, and consists of only
a few pieces of syntax. This first element is the `print` symbol. This is a function
that simply prints its arguments to standard out. The second argument is the
string literal "Hello, world!", which is the one and only argument to the
print function. Lastly, the print symbol and the string literal are wrapped
@ -74,7 +74,7 @@ notation with a radix besides 10, use the `&` symbol to indicate the exponent ra
Besides the 5 main arithmetic functions, dst also supports a number of math functions
taken from the C libary `<math.h>`, as well as bitwise operators that behave like they
do in C or Java.
do in C or Java. Functions like `sin`, `cos`, `log`, and `exp` will behave as expected to a C programmer.
# Strings, Keywords and Symbols
@ -164,11 +164,8 @@ Functions can be defined with the `defn` macro, like so:
(* base height 0.5))
```
A function defined with `defn` has a number of parts. First, it has it's name, triangle-area. This
is just a symbol used to access the function later. Next is the list of parameters this function takes,
in this case two parameters named base and height. Lastly, a function made with defn has
a number of body statements, which get executed each time the function is called. The last
form in the body is what the function evaluates to, or returns.
A function defined with `defn` consists of a name, a number of optional flags for def, and
finally a function body. The example above is named triangle-area and takes two parameters named base and height. The body of the function will print a message and then evaluate to the area of the triangle.
Once a function like the above one is defined, the programmer can use the `triangle-area`
function just like any other, say `print` or `+`.
@ -183,15 +180,13 @@ nested inside a call to print), the inner function calls are evaluated first. Al
a function call are evaluated in order, from first argument to last argument).
Because functions are first-class values like numbers or strings, they can be passed
as arguments to other functions as well
as arguments to other functions as well.
```
(print triangle-area)
```
This prints the location in memory of the function triangle area. This idea can be used
to build some powerful constructs purely out of functions, or closures as they are known
in many contexts.
This prints the location in memory of the function triangle area.
Functions don't need to have names. The `fn` keyword can be used to introduce function
literals without binding them to a symbol.