Document not found (404)
-This URL is invalid, sorry. Please use the navigation bar or search to continue.
- -diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..5dc4382 --- /dev/null +++ b/.gitignore @@ -0,0 +1,2 @@ +book +docs \ No newline at end of file diff --git a/book.toml b/book.toml index 2a08676..d3f090f 100644 --- a/book.toml +++ b/book.toml @@ -5,7 +5,4 @@ multilingual = false src = "src" [output.html] -git-repository-url = "https://github.com/Caleb-o/c3-cookbook" - -[build] -build-dir = "docs" \ No newline at end of file +git-repository-url = "https://github.com/Caleb-o/c3-cookbook" \ No newline at end of file diff --git a/docs/.nojekyll b/docs/.nojekyll deleted file mode 100644 index f173110..0000000 --- a/docs/.nojekyll +++ /dev/null @@ -1 +0,0 @@ -This file makes sure that Github Pages doesn't process mdBook's output. diff --git a/docs/404.html b/docs/404.html deleted file mode 100644 index c2e1b6b..0000000 --- a/docs/404.html +++ /dev/null @@ -1,221 +0,0 @@ - - -
- - -This URL is invalid, sorry. Please use the navigation bar or search to continue.
- -Let's write the classic example, Hello World! But before that, we have two options with how to proceed:
- -Creating a project is quite simple in C3. We can use the c3c
executable to initialise, build and run our project.
Let's create a new project:
-$ c3c init myproject
-$ cd myproject
-
-We now have a new project directory and this would have created a few directories within it, a license, a project.json
and a readme. This includes the build
directory, which is where your project will be compiled into. In C3 we use the src
directory and this is where you will find the main.c3
file. You can see more details about project structure in the C3 guide.
Let's open the main file src/main.c3
in your editor and write this code:
module myproject;
-import std::io;
-
-fn void main() {
- io::printn("Hello, World!");
-}
-
-We can now run this code with:
-$ c3c run
-
-This should then print to the console
-Program linked to executable 'myproject'.
-Launching ./myproject
-Hello, World!
-Program completed with exit code 0.
-
-
-We can create a new file with the .c3
extension. Then we can write this code:
module myproject;
-import std::io;
-
-fn void main() {
- io::printn("Hello, World!");
-}
-
-We will use the compiler to build, run and then dispose of the executable:
-$ c3c compile-run --run-once main.c3
-
-This should then print to the console
-Program linked to executable 'myproject'.
-Launching ./myproject
-Hello, World!
-Program completed with exit code 0.
-
-You can also just compile the file and run the executable directly:
-$ c3c compile main.c3 -o hello
-$ ./hello
-
-Hello, World!
-
-You have now written your first C3 program. Let's break down what is happening in our code. We can start with the first line:
-module myproject;
-
-Every file must start with a module name. We can think of a module like a namespace, as each file that has the same module name is considered the same module. Module names are not tied to files or the directory they are in, so it is up to you to name them correctly. To avoid clashing, we must use longer and/or more detailed names. This could be something like projectname::foo::bar::baz
.
import std::io;
-
-Next is our import. This is how we import modules in C3. One thing that might confuse people who might be used to namespaces, is that this is actually a sub-namespace/module within std
. However, as described above, this is just a name. You cannot create sub-modules as you might expect from other languages, but this is just a naming style to keep things organised logically.
fn void main() {
- io::printn("Hello, World!");
-}
-
-Functions in C3 use the fn
keyword to denote a function declaration. It is then followed by the return type (void) and then a function name and its parameters. This should look pretty familiar for anyone who's used a C-style language. The interesting thing here is our io::printn
. If you tried to remove the io::
prefix, you will see this error:
Error: Functions from other modules must be prefixed with the module name.
-
-Any function that comes from a different module, must be prefixed with its module name. This helps the reader also understand where this function comes from. We will see this often later, when it comes to types as well.
---There is another way we can write this function. This will be familiar for those who have used JavaScript:
--fn void main() => io::printn("Hello, World!"); -
It is possible to write a single expression function, using the
-=>
arrow syntax. > This is useful for writing simple functions that return a value.
This was probably quite a long explanation of Hello World, but this is essentially how this book should be structured. We will write an example, then give an explanation on the hows and why. Hopefully this can help give better understanding of the code written and leaves you both curious for more and with questions answered.
- -"C3 is a programming language that builds on the syntax and semantics of the C language, with the goal of evolving it while still retaining familiarity for C programmers."
---This book is being written with 0.6.x in mind. It may include nightly releases that have fixed problems with 0.6.2. -If an example doesn't quite work with 0.6.2, try using the latest compiler.
-
This was inspired by the Zig Cookbook which displays common and more idiomatic ways to use Zig around certain problems. I wanted to create a community driven book, that would do the same for C3. I believe it is something that can help developers pickup C3, as it provides another source to browse.
-I have used new languages where documentation and community driven media was scarce, which made it very hard to get an understanding of the language in a more practical manner. Hopefully this book can help with this issue and get some more people into C3.
-Since I'm writing this as a newbie to C3, there are bound to be issues or better ways to achieve things.
-Use one of the following sources to download or build the C3 compiler from source:
-There is a work in progress LSP that can be found here.
-"C3 is a programming language that builds on the syntax and semantics of the C language, with the goal of evolving it while still retaining familiarity for C programmers."
---This book is being written with 0.6.x in mind. It may include nightly releases that have fixed problems with 0.6.2. -If an example doesn't quite work with 0.6.2, try using the latest compiler.
-
This was inspired by the Zig Cookbook which displays common and more idiomatic ways to use Zig around certain problems. I wanted to create a community driven book, that would do the same for C3. I believe it is something that can help developers pickup C3, as it provides another source to browse.
-I have used new languages where documentation and community driven media was scarce, which made it very hard to get an understanding of the language in a more practical manner. Hopefully this book can help with this issue and get some more people into C3.
-Since I'm writing this as a newbie to C3, there are bound to be issues or better ways to achieve things.
-Use one of the following sources to download or build the C3 compiler from source:
-There is a work in progress LSP that can be found here.
-