Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: bump prelude link #832

Merged
merged 2 commits into from
Jun 7, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/SUMMARY.md
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 97,7 @@
- [A - Keywords](appendix-01-keywords.md)
- [B - Operators and Symbols](appendix-02-operators-and-symbols.md)
- [C - Derivable Traits](appendix-03-derivable-traits.md)
- [D - Common Types & Traits and the Cairo Prelude](appendix-04-common-types-and-traits-and-cairo-prelude.md)
- [D - The Cairo Prelude](appendix-04-cairo-prelude.md)
- [E - Common Error Messages](appendix-05-common-error-messages.md)
- [F - Useful Development Tools](appendix-06-useful-development-tools.md)
- [G - Installing Cairo binaries](appendix-07-cairo-binaries.md)
Expand Down
33 changes: 33 additions & 0 deletions src/appendix-04-cairo-prelude.md
Original file line number Diff line number Diff line change
@@ -0,0 1,33 @@
# Appendix D - The Cairo Prelude

## Prelude

The Cairo prelude is a collection of commonly used modules, functions, data
types, and traits that are automatically brought into scope of every module in a
Cairo crate without needing explicit import statements. Cairo's prelude provides
the basic building blocks developers need to start Cairo programs and writing
smart contracts.

The core library prelude is defined in the _[lib.cairo](https://github.com/starkware-libs/cairo/blob/main/corelib/src/lib.cairo)_
file of the corelib crate and contains Cairo's primitive data types, traits,
operators, and utility functions. This includes:

- Data types: integers, bools, arrays, dicts, etc.
- Traits: behaviors for arithmetic, comparison, and serialization operations
- Operators: arithmetic, logical, bitwise
- Utility functions - helpers for arrays, maps, boxing, etc.

The core library prelude delivers the fundamental programming
constructs and operations needed for basic Cairo programs, without requiring the
explicit import of elements. Since the core library prelude is automatically
imported, its contents are available for use in any Cairo crate without explicit
imports. This prevents repetition and provides a better devX. This is what
allows you to use `ArrayTrait::append()` or the `Default` trait without bringing
them explicitly into scope.

You can choose which prelude to use. For example, adding `edition = "2023_11"` in the _Scarb.toml_ configuration file will load the prelude from November 2023. Note that when you create a new project using `scarb new` command, the _Scarb.toml_ file will automatically include `edition = "2023_11"`.

The compiler currently exposes 2 different versions of the prelude:

- A general version, with a lot of traits that are made available, corresponding to `edition = "2023_01"`.
- A restricted version, including the most essential traits needed for general Cairo programming, corresponding to `edition = 2023_11`.
54 changes: 0 additions & 54 deletions src/appendix-04-common-types-and-traits-and-cairo-prelude.md

This file was deleted.

6 changes: 3 additions & 3 deletions src/ch01-02-hello-world.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 82,7 @@ This file is in the [TOML][toml doc] (Tom’s Obvious, Minimal Language) format,

The first line, `[package]`, is a section heading that indicates that the following statements are configuring a package. As we add more information to this file, we’ll add other sections.

The next three lines set the configuration information Scarb needs to compile your program: the name of the package and the version of Scarb to use, and the edition of the prelude to use. The prelude is the collection of the most commonly used items that are automatically imported into every Cairo program. You can learn more about the prelude in [Appendix D][types, traits, and prelude].
The next three lines set the configuration information Scarb needs to compile your program: the name of the package and the version of Scarb to use, and the edition of the prelude to use. The prelude is the collection of the most commonly used items that are automatically imported into every Cairo program. You can learn more about the prelude in [Appendix D][prelude].

The last line, `[dependencies]`, is the start of a section for you to list any of your project’s dependencies. In Cairo, packages of code are referred to as crates. We won’t need any other crates for this project.

Expand Down Expand Up @@ -123,7 123,7 @@ If you started a project that doesn’t use Scarb, you can convert it to a proje
<span class="caption"> A sample Scarb project structure</span>

[toml doc]: https://toml.io/
[types, traits, and prelude]: ./appendix-04-common-types-and-traits-and-cairo-prelude.md
[prelude]: ./appendix-04-cairo-prelude.md
[starknet package]: https://docs.swmansion.com/scarb/docs/extensions/starknet/starknet-package.html

## Building a Scarb Project
Expand Down Expand Up @@ -200,7 200,7 @@ Fourth, we end the line with a semicolon (`;`), which indicates that this
expression is over and the next one is ready to begin. Most lines of Cairo code
end with a semicolon.

[devtools]: ./appendix-04-useful-development-tools.md
[devtools]: ./appendix-06-useful-development-tools.md
[macros]: ./ch11-05-macros.md

{{#quiz ../quizzes/ch01-02-hello-world.toml}}
Expand Down