summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
-rw-r--r--LICENSE.txt359
-rw-r--r--bf.html.markdown8
-rw-r--r--cairo.html.markdown864
-rw-r--r--de-de/yaml-de.html.markdown2
-rw-r--r--hjson.html.markdown2
-rw-r--r--images/cairo/build.pngbin0 -> 20768 bytes
-rw-r--r--images/cairo/connect.pngbin0 -> 62073 bytes
-rw-r--r--images/cairo/connect2.pngbin0 -> 66962 bytes
-rw-r--r--images/cairo/declare.pngbin0 -> 74011 bytes
-rw-r--r--images/cairo/deploy.pngbin0 -> 99481 bytes
-rw-r--r--lbstanza.html.markdown6
-rw-r--r--mips.html.markdown6
-rw-r--r--openscad.html.markdown2
-rw-r--r--python.html.markdown4
-rw-r--r--r.html.markdown2
-rw-r--r--raku.html.markdown2
-rw-r--r--rust.html.markdown2
-rw-r--r--set-theory.html.markdown2
-rw-r--r--zh-cn/clojure-macro-cn.html.markdown2
-rw-r--r--zig.html.markdown52
20 files changed, 1273 insertions, 42 deletions
diff --git a/LICENSE.txt b/LICENSE.txt
new file mode 100644
index 00000000..604209a8
--- /dev/null
+++ b/LICENSE.txt
@@ -0,0 +1,359 @@
+Creative Commons Legal Code
+
+Attribution-ShareAlike 3.0 Unported
+
+ CREATIVE COMMONS CORPORATION IS NOT A LAW FIRM AND DOES NOT PROVIDE
+ LEGAL SERVICES. DISTRIBUTION OF THIS LICENSE DOES NOT CREATE AN
+ ATTORNEY-CLIENT RELATIONSHIP. CREATIVE COMMONS PROVIDES THIS
+ INFORMATION ON AN "AS-IS" BASIS. CREATIVE COMMONS MAKES NO WARRANTIES
+ REGARDING THE INFORMATION PROVIDED, AND DISCLAIMS LIABILITY FOR
+ DAMAGES RESULTING FROM ITS USE.
+
+License
+
+THE WORK (AS DEFINED BELOW) IS PROVIDED UNDER THE TERMS OF THIS CREATIVE
+COMMONS PUBLIC LICENSE ("CCPL" OR "LICENSE"). THE WORK IS PROTECTED BY
+COPYRIGHT AND/OR OTHER APPLICABLE LAW. ANY USE OF THE WORK OTHER THAN AS
+AUTHORIZED UNDER THIS LICENSE OR COPYRIGHT LAW IS PROHIBITED.
+
+BY EXERCISING ANY RIGHTS TO THE WORK PROVIDED HERE, YOU ACCEPT AND AGREE
+TO BE BOUND BY THE TERMS OF THIS LICENSE. TO THE EXTENT THIS LICENSE MAY
+BE CONSIDERED TO BE A CONTRACT, THE LICENSOR GRANTS YOU THE RIGHTS
+CONTAINED HERE IN CONSIDERATION OF YOUR ACCEPTANCE OF SUCH TERMS AND
+CONDITIONS.
+
+1. Definitions
+
+ a. "Adaptation" means a work based upon the Work, or upon the Work and
+ other pre-existing works, such as a translation, adaptation,
+ derivative work, arrangement of music or other alterations of a
+ literary or artistic work, or phonogram or performance and includes
+ cinematographic adaptations or any other form in which the Work may be
+ recast, transformed, or adapted including in any form recognizably
+ derived from the original, except that a work that constitutes a
+ Collection will not be considered an Adaptation for the purpose of
+ this License. For the avoidance of doubt, where the Work is a musical
+ work, performance or phonogram, the synchronization of the Work in
+ timed-relation with a moving image ("synching") will be considered an
+ Adaptation for the purpose of this License.
+ b. "Collection" means a collection of literary or artistic works, such as
+ encyclopedias and anthologies, or performances, phonograms or
+ broadcasts, or other works or subject matter other than works listed
+ in Section 1(f) below, which, by reason of the selection and
+ arrangement of their contents, constitute intellectual creations, in
+ which the Work is included in its entirety in unmodified form along
+ with one or more other contributions, each constituting separate and
+ independent works in themselves, which together are assembled into a
+ collective whole. A work that constitutes a Collection will not be
+ considered an Adaptation (as defined below) for the purposes of this
+ License.
+ c. "Creative Commons Compatible License" means a license that is listed
+ at https://creativecommons.org/compatiblelicenses that has been
+ approved by Creative Commons as being essentially equivalent to this
+ License, including, at a minimum, because that license: (i) contains
+ terms that have the same purpose, meaning and effect as the License
+ Elements of this License; and, (ii) explicitly permits the relicensing
+ of adaptations of works made available under that license under this
+ License or a Creative Commons jurisdiction license with the same
+ License Elements as this License.
+ d. "Distribute" means to make available to the public the original and
+ copies of the Work or Adaptation, as appropriate, through sale or
+ other transfer of ownership.
+ e. "License Elements" means the following high-level license attributes
+ as selected by Licensor and indicated in the title of this License:
+ Attribution, ShareAlike.
+ f. "Licensor" means the individual, individuals, entity or entities that
+ offer(s) the Work under the terms of this License.
+ g. "Original Author" means, in the case of a literary or artistic work,
+ the individual, individuals, entity or entities who created the Work
+ or if no individual or entity can be identified, the publisher; and in
+ addition (i) in the case of a performance the actors, singers,
+ musicians, dancers, and other persons who act, sing, deliver, declaim,
+ play in, interpret or otherwise perform literary or artistic works or
+ expressions of folklore; (ii) in the case of a phonogram the producer
+ being the person or legal entity who first fixes the sounds of a
+ performance or other sounds; and, (iii) in the case of broadcasts, the
+ organization that transmits the broadcast.
+ h. "Work" means the literary and/or artistic work offered under the terms
+ of this License including without limitation any production in the
+ literary, scientific and artistic domain, whatever may be the mode or
+ form of its expression including digital form, such as a book,
+ pamphlet and other writing; a lecture, address, sermon or other work
+ of the same nature; a dramatic or dramatico-musical work; a
+ choreographic work or entertainment in dumb show; a musical
+ composition with or without words; a cinematographic work to which are
+ assimilated works expressed by a process analogous to cinematography;
+ a work of drawing, painting, architecture, sculpture, engraving or
+ lithography; a photographic work to which are assimilated works
+ expressed by a process analogous to photography; a work of applied
+ art; an illustration, map, plan, sketch or three-dimensional work
+ relative to geography, topography, architecture or science; a
+ performance; a broadcast; a phonogram; a compilation of data to the
+ extent it is protected as a copyrightable work; or a work performed by
+ a variety or circus performer to the extent it is not otherwise
+ considered a literary or artistic work.
+ i. "You" means an individual or entity exercising rights under this
+ License who has not previously violated the terms of this License with
+ respect to the Work, or who has received express permission from the
+ Licensor to exercise rights under this License despite a previous
+ violation.
+ j. "Publicly Perform" means to perform public recitations of the Work and
+ to communicate to the public those public recitations, by any means or
+ process, including by wire or wireless means or public digital
+ performances; to make available to the public Works in such a way that
+ members of the public may access these Works from a place and at a
+ place individually chosen by them; to perform the Work to the public
+ by any means or process and the communication to the public of the
+ performances of the Work, including by public digital performance; to
+ broadcast and rebroadcast the Work by any means including signs,
+ sounds or images.
+ k. "Reproduce" means to make copies of the Work by any means including
+ without limitation by sound or visual recordings and the right of
+ fixation and reproducing fixations of the Work, including storage of a
+ protected performance or phonogram in digital form or other electronic
+ medium.
+
+2. Fair Dealing Rights. Nothing in this License is intended to reduce,
+limit, or restrict any uses free from copyright or rights arising from
+limitations or exceptions that are provided for in connection with the
+copyright protection under copyright law or other applicable laws.
+
+3. License Grant. Subject to the terms and conditions of this License,
+Licensor hereby grants You a worldwide, royalty-free, non-exclusive,
+perpetual (for the duration of the applicable copyright) license to
+exercise the rights in the Work as stated below:
+
+ a. to Reproduce the Work, to incorporate the Work into one or more
+ Collections, and to Reproduce the Work as incorporated in the
+ Collections;
+ b. to create and Reproduce Adaptations provided that any such Adaptation,
+ including any translation in any medium, takes reasonable steps to
+ clearly label, demarcate or otherwise identify that changes were made
+ to the original Work. For example, a translation could be marked "The
+ original work was translated from English to Spanish," or a
+ modification could indicate "The original work has been modified.";
+ c. to Distribute and Publicly Perform the Work including as incorporated
+ in Collections; and,
+ d. to Distribute and Publicly Perform Adaptations.
+ e. For the avoidance of doubt:
+
+ i. Non-waivable Compulsory License Schemes. In those jurisdictions in
+ which the right to collect royalties through any statutory or
+ compulsory licensing scheme cannot be waived, the Licensor
+ reserves the exclusive right to collect such royalties for any
+ exercise by You of the rights granted under this License;
+ ii. Waivable Compulsory License Schemes. In those jurisdictions in
+ which the right to collect royalties through any statutory or
+ compulsory licensing scheme can be waived, the Licensor waives the
+ exclusive right to collect such royalties for any exercise by You
+ of the rights granted under this License; and,
+ iii. Voluntary License Schemes. The Licensor waives the right to
+ collect royalties, whether individually or, in the event that the
+ Licensor is a member of a collecting society that administers
+ voluntary licensing schemes, via that society, from any exercise
+ by You of the rights granted under this License.
+
+The above rights may be exercised in all media and formats whether now
+known or hereafter devised. The above rights include the right to make
+such modifications as are technically necessary to exercise the rights in
+other media and formats. Subject to Section 8(f), all rights not expressly
+granted by Licensor are hereby reserved.
+
+4. Restrictions. The license granted in Section 3 above is expressly made
+subject to and limited by the following restrictions:
+
+ a. You may Distribute or Publicly Perform the Work only under the terms
+ of this License. You must include a copy of, or the Uniform Resource
+ Identifier (URI) for, this License with every copy of the Work You
+ Distribute or Publicly Perform. You may not offer or impose any terms
+ on the Work that restrict the terms of this License or the ability of
+ the recipient of the Work to exercise the rights granted to that
+ recipient under the terms of the License. You may not sublicense the
+ Work. You must keep intact all notices that refer to this License and
+ to the disclaimer of warranties with every copy of the Work You
+ Distribute or Publicly Perform. When You Distribute or Publicly
+ Perform the Work, You may not impose any effective technological
+ measures on the Work that restrict the ability of a recipient of the
+ Work from You to exercise the rights granted to that recipient under
+ the terms of the License. This Section 4(a) applies to the Work as
+ incorporated in a Collection, but this does not require the Collection
+ apart from the Work itself to be made subject to the terms of this
+ License. If You create a Collection, upon notice from any Licensor You
+ must, to the extent practicable, remove from the Collection any credit
+ as required by Section 4(c), as requested. If You create an
+ Adaptation, upon notice from any Licensor You must, to the extent
+ practicable, remove from the Adaptation any credit as required by
+ Section 4(c), as requested.
+ b. You may Distribute or Publicly Perform an Adaptation only under the
+ terms of: (i) this License; (ii) a later version of this License with
+ the same License Elements as this License; (iii) a Creative Commons
+ jurisdiction license (either this or a later license version) that
+ contains the same License Elements as this License (e.g.,
+ Attribution-ShareAlike 3.0 US)); (iv) a Creative Commons Compatible
+ License. If you license the Adaptation under one of the licenses
+ mentioned in (iv), you must comply with the terms of that license. If
+ you license the Adaptation under the terms of any of the licenses
+ mentioned in (i), (ii) or (iii) (the "Applicable License"), you must
+ comply with the terms of the Applicable License generally and the
+ following provisions: (I) You must include a copy of, or the URI for,
+ the Applicable License with every copy of each Adaptation You
+ Distribute or Publicly Perform; (II) You may not offer or impose any
+ terms on the Adaptation that restrict the terms of the Applicable
+ License or the ability of the recipient of the Adaptation to exercise
+ the rights granted to that recipient under the terms of the Applicable
+ License; (III) You must keep intact all notices that refer to the
+ Applicable License and to the disclaimer of warranties with every copy
+ of the Work as included in the Adaptation You Distribute or Publicly
+ Perform; (IV) when You Distribute or Publicly Perform the Adaptation,
+ You may not impose any effective technological measures on the
+ Adaptation that restrict the ability of a recipient of the Adaptation
+ from You to exercise the rights granted to that recipient under the
+ terms of the Applicable License. This Section 4(b) applies to the
+ Adaptation as incorporated in a Collection, but this does not require
+ the Collection apart from the Adaptation itself to be made subject to
+ the terms of the Applicable License.
+ c. If You Distribute, or Publicly Perform the Work or any Adaptations or
+ Collections, You must, unless a request has been made pursuant to
+ Section 4(a), keep intact all copyright notices for the Work and
+ provide, reasonable to the medium or means You are utilizing: (i) the
+ name of the Original Author (or pseudonym, if applicable) if supplied,
+ and/or if the Original Author and/or Licensor designate another party
+ or parties (e.g., a sponsor institute, publishing entity, journal) for
+ attribution ("Attribution Parties") in Licensor's copyright notice,
+ terms of service or by other reasonable means, the name of such party
+ or parties; (ii) the title of the Work if supplied; (iii) to the
+ extent reasonably practicable, the URI, if any, that Licensor
+ specifies to be associated with the Work, unless such URI does not
+ refer to the copyright notice or licensing information for the Work;
+ and (iv) , consistent with Ssection 3(b), in the case of an
+ Adaptation, a credit identifying the use of the Work in the Adaptation
+ (e.g., "French translation of the Work by Original Author," or
+ "Screenplay based on original Work by Original Author"). The credit
+ required by this Section 4(c) may be implemented in any reasonable
+ manner; provided, however, that in the case of a Adaptation or
+ Collection, at a minimum such credit will appear, if a credit for all
+ contributing authors of the Adaptation or Collection appears, then as
+ part of these credits and in a manner at least as prominent as the
+ credits for the other contributing authors. For the avoidance of
+ doubt, You may only use the credit required by this Section for the
+ purpose of attribution in the manner set out above and, by exercising
+ Your rights under this License, You may not implicitly or explicitly
+ assert or imply any connection with, sponsorship or endorsement by the
+ Original Author, Licensor and/or Attribution Parties, as appropriate,
+ of You or Your use of the Work, without the separate, express prior
+ written permission of the Original Author, Licensor and/or Attribution
+ Parties.
+ d. Except as otherwise agreed in writing by the Licensor or as may be
+ otherwise permitted by applicable law, if You Reproduce, Distribute or
+ Publicly Perform the Work either by itself or as part of any
+ Adaptations or Collections, You must not distort, mutilate, modify or
+ take other derogatory action in relation to the Work which would be
+ prejudicial to the Original Author's honor or reputation. Licensor
+ agrees that in those jurisdictions (e.g. Japan), in which any exercise
+ of the right granted in Section 3(b) of this License (the right to
+ make Adaptations) would be deemed to be a distortion, mutilation,
+ modification or other derogatory action prejudicial to the Original
+ Author's honor and reputation, the Licensor will waive or not assert,
+ as appropriate, this Section, to the fullest extent permitted by the
+ applicable national law, to enable You to reasonably exercise Your
+ right under Section 3(b) of this License (right to make Adaptations)
+ but not otherwise.
+
+5. Representations, Warranties and Disclaimer
+
+UNLESS OTHERWISE MUTUALLY AGREED TO BY THE PARTIES IN WRITING, LICENSOR
+OFFERS THE WORK AS-IS AND MAKES NO REPRESENTATIONS OR WARRANTIES OF ANY
+KIND CONCERNING THE WORK, EXPRESS, IMPLIED, STATUTORY OR OTHERWISE,
+INCLUDING, WITHOUT LIMITATION, WARRANTIES OF TITLE, MERCHANTIBILITY,
+FITNESS FOR A PARTICULAR PURPOSE, NONINFRINGEMENT, OR THE ABSENCE OF
+LATENT OR OTHER DEFECTS, ACCURACY, OR THE PRESENCE OF ABSENCE OF ERRORS,
+WHETHER OR NOT DISCOVERABLE. SOME JURISDICTIONS DO NOT ALLOW THE EXCLUSION
+OF IMPLIED WARRANTIES, SO SUCH EXCLUSION MAY NOT APPLY TO YOU.
+
+6. Limitation on Liability. EXCEPT TO THE EXTENT REQUIRED BY APPLICABLE
+LAW, IN NO EVENT WILL LICENSOR BE LIABLE TO YOU ON ANY LEGAL THEORY FOR
+ANY SPECIAL, INCIDENTAL, CONSEQUENTIAL, PUNITIVE OR EXEMPLARY DAMAGES
+ARISING OUT OF THIS LICENSE OR THE USE OF THE WORK, EVEN IF LICENSOR HAS
+BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
+
+7. Termination
+
+ a. This License and the rights granted hereunder will terminate
+ automatically upon any breach by You of the terms of this License.
+ Individuals or entities who have received Adaptations or Collections
+ from You under this License, however, will not have their licenses
+ terminated provided such individuals or entities remain in full
+ compliance with those licenses. Sections 1, 2, 5, 6, 7, and 8 will
+ survive any termination of this License.
+ b. Subject to the above terms and conditions, the license granted here is
+ perpetual (for the duration of the applicable copyright in the Work).
+ Notwithstanding the above, Licensor reserves the right to release the
+ Work under different license terms or to stop distributing the Work at
+ any time; provided, however that any such election will not serve to
+ withdraw this License (or any other license that has been, or is
+ required to be, granted under the terms of this License), and this
+ License will continue in full force and effect unless terminated as
+ stated above.
+
+8. Miscellaneous
+
+ a. Each time You Distribute or Publicly Perform the Work or a Collection,
+ the Licensor offers to the recipient a license to the Work on the same
+ terms and conditions as the license granted to You under this License.
+ b. Each time You Distribute or Publicly Perform an Adaptation, Licensor
+ offers to the recipient a license to the original Work on the same
+ terms and conditions as the license granted to You under this License.
+ c. If any provision of this License is invalid or unenforceable under
+ applicable law, it shall not affect the validity or enforceability of
+ the remainder of the terms of this License, and without further action
+ by the parties to this agreement, such provision shall be reformed to
+ the minimum extent necessary to make such provision valid and
+ enforceable.
+ d. No term or provision of this License shall be deemed waived and no
+ breach consented to unless such waiver or consent shall be in writing
+ and signed by the party to be charged with such waiver or consent.
+ e. This License constitutes the entire agreement between the parties with
+ respect to the Work licensed here. There are no understandings,
+ agreements or representations with respect to the Work not specified
+ here. Licensor shall not be bound by any additional provisions that
+ may appear in any communication from You. This License may not be
+ modified without the mutual written agreement of the Licensor and You.
+ f. The rights granted under, and the subject matter referenced, in this
+ License were drafted utilizing the terminology of the Berne Convention
+ for the Protection of Literary and Artistic Works (as amended on
+ September 28, 1979), the Rome Convention of 1961, the WIPO Copyright
+ Treaty of 1996, the WIPO Performances and Phonograms Treaty of 1996
+ and the Universal Copyright Convention (as revised on July 24, 1971).
+ These rights and subject matter take effect in the relevant
+ jurisdiction in which the License terms are sought to be enforced
+ according to the corresponding provisions of the implementation of
+ those treaty provisions in the applicable national law. If the
+ standard suite of rights granted under applicable copyright law
+ includes additional rights not granted under this License, such
+ additional rights are deemed to be included in the License; this
+ License is not intended to restrict the license of any rights under
+ applicable law.
+
+
+Creative Commons Notice
+
+ Creative Commons is not a party to this License, and makes no warranty
+ whatsoever in connection with the Work. Creative Commons will not be
+ liable to You or any party on any legal theory for any damages
+ whatsoever, including without limitation any general, special,
+ incidental or consequential damages arising in connection to this
+ license. Notwithstanding the foregoing two (2) sentences, if Creative
+ Commons has expressly identified itself as the Licensor hereunder, it
+ shall have all rights and obligations of Licensor.
+
+ Except for the limited purpose of indicating to the public that the
+ Work is licensed under the CCPL, Creative Commons does not authorize
+ the use by either party of the trademark "Creative Commons" or any
+ related trademark or logo of Creative Commons without the prior
+ written consent of Creative Commons. Any permitted use will be in
+ compliance with Creative Commons' then-current trademark usage
+ guidelines, as may be published on its website or otherwise made
+ available upon request from time to time. For the avoidance of doubt,
+ this trademark restriction does not form part of the License.
+
+ Creative Commons may be contacted at https://creativecommons.org/.
diff --git a/bf.html.markdown b/bf.html.markdown
index 5ede0546..adc58f02 100644
--- a/bf.html.markdown
+++ b/bf.html.markdown
@@ -4,12 +4,13 @@ filename: bf.bf
contributors:
- ["Prajit Ramachandran", "http://prajitr.github.io/"]
- ["Mathias Bynens", "http://mathiasbynens.be/"]
+ - ["rilysh", "https://github.com/rilysh"]
---
Brainfuck (not capitalized except at the start of a sentence) is an extremely
minimal Turing-complete programming language with just 8 commands.
-You can try brainfuck on your browser with [brainfuck-visualizer](https://brainfuck-visualizer.herokuapp.com).
+You can try brainfuck on your browser with [brainfuck-online](https://copy.sh/brainfuck/).
```bf
Any character not "><+-.,[]" (excluding quotation marks) is ignored.
@@ -80,3 +81,8 @@ And that's brainfuck. Not that hard, eh? For fun, you can write your own
brainfuck programs, or you can write a brainfuck interpreter in another
language. The interpreter is fairly simple to implement, but if you're a
masochist, try writing a brainfuck interpreter… in brainfuck.
+
+## Further Reading
+ * [esolang-wiki](https://esolangs.org/wiki/Brainfuck)
+ * [learn brainfuck](http://cydathria.com/bf/brainfuck.html)
+ * [other resources](http://www.muppetlabs.com/~breadbox/bf/)
diff --git a/cairo.html.markdown b/cairo.html.markdown
new file mode 100644
index 00000000..dd3ca036
--- /dev/null
+++ b/cairo.html.markdown
@@ -0,0 +1,864 @@
+---
+language: Cairo
+filename: learnCairo.sol
+contributors:
+ - ["Darlington Nnam", "https://github.com/Darlington02"]
+---
+
+# Cairo
+
+Cairo is a Turing-complete language that allows you write provable programs
+(where one party can prove to another that a certain computation was executed
+correctly) on StarkNet.
+
+## StarkNet
+
+StarkNet is a decentralized ZK-rollup that operates as an Ethereum layer 2
+chain.
+
+In this document, we are going to be going in-depth into understanding Cairo's
+syntax and how you could create and deploy a Cairo smart contract on StarkNet.
+
+**NB: As at the time of this writing, StarkNet is still at v0.10.3, with Cairo
+1.0 coming soon. The ecosystem is young and evolving very fast, so you might
+want to check the [official docs](https://www.cairo-lang.org/docs) to confirm
+this document is still up-to-date. Pull requests are welcome!**
+
+## Setting Up A Development Environment
+
+Before we get started writing codes, we will need to setup a Cairo development
+environment, for writing, compiling and deploying our contracts to StarkNet.
+For the purpose of this tutorial we are going to be using the
+[Protostar Framework](https://github.com/software-mansion/protostar).
+Installation steps can be found in the docs
+[here](https://docs.swmansion.com/protostar/docs/tutorials/installation).
+Note that Protostar supports just Mac and Linux OS, Windows users might need to
+use WSL, or go for other alternatives such as the Official
+[StarkNet CLI](https://www.cairo-lang.org/docs/quickstart.html) or
+[Nile from Openzeppelin](https://github.com/OpenZeppelin/nile)
+
+Once you're done with the installations, run the command `protostar -v` to
+confirm your installation was successful. If successful, you should see your
+Protostar version displayed on the screen.
+
+## Initializing a new project
+
+Protostar similar to Truffle for solidity development can be installed once and
+used for multiple projects. To initialize a new Protostar project, run the
+following command:
+
+```
+protostar init
+```
+
+It would then request the project's name and the library's directory name,
+you'd need to fill in this, and a new project will be initialized successfully.
+
+## Compiling, Declaring, Deploying and Interacting with StarkNet Contracts
+
+Within the `src` folder you'll find a boilerplate contract that comes with
+initializing a new Protostar project, `main.cairo`. We are going to be
+compiling, declaring and deploying this contract.
+
+### Compiling Contracts
+
+To compile a Cairo contract using Protostar, ensure a path to the contract is
+specified in the `[contracts]` section of the `protostar.toml` file. Once
+you've done that, open your terminal and run the command:
+
+```
+protostar build
+```
+
+And you should get an output similar to what you see below, with a `main.json`
+and `main_abi.json` files created in the `build` folder.
+<img src="./images/cairo/build.png" alt="building your contract">
+
+### Declaring Contracts
+
+With the recent StarkNet update to 0.10.3, the DEPLOY transaction was
+deprecated and no longer works. To deploy a transaction, you must first declare
+a Contract to obtain the class hash, then deploy the declared contract using the
+[Universal Deployer Contract](https://community.starknet.io/t/universal-deployer-contract-proposal/1864).
+
+Before declaring or deploying your contract using Protostar, you should set the
+private key associated with the specified account address in a file, or in the
+terminal. To set your private key in the terminal, run the command:
+
+```
+export PROTOSTAR_ACCOUNT_PRIVATE_KEY=[YOUR PRIVATE KEY HERE]
+```
+
+Then to declare our contract using Protostar run the following command (for
+visual clarity, the backslash sign symbolizes the continuing line):
+
+```
+protostar declare ./build/main.json \
+ --network testnet \
+ --account 0x0691622bBFD29e835bA4004e7425A4e9630840EbD11c5269DE51C16774585b16 \
+ --max-fee auto
+```
+
+where `network` specifies the network we are deploying to, `account` specifies
+account whose private key we are using, `max-fee` specifies the maximum fee to
+be paid for the transaction. You should get the class hash outputted as seen
+below:
+<img src="./images/cairo/declare.png" alt="declaring your contract">
+
+### Deploying Contracts
+
+After obtaining our class hash from declaring, we can now deploy using the
+command below:
+
+```
+protostar \
+ deploy 0x02a5de1b145e18dfeb31c7cd7ff403714ededf5f3fdf75f8b0ac96f2017541bc \
+ --network testnet \
+ --account 0x0691622bBFD29e835bA4004e7425A4e9630840EbD11c5269DE51C16774585b16 \
+ --max-fee auto
+```
+
+where `0x02a5de1b145e18dfeb31c7cd7ff403714ededf5f3fdf75f8b0ac96f2017541bc` is
+the class hash of our contract.
+<img src="./images/cairo/deploy.png" alt="deploying your contract">
+
+### Interacting with Contracts
+
+To interact with your deployed contract, we will be using `Argent X`
+(alternative: `Braavos`), and `Starkscan` (alternative: `Voyager`). To install
+and setup `Argent X`, see this
+[guide](https://www.argent.xyz/learn/how-to-create-an-argent-x-wallet/).
+
+Copy your contract address, displayed on screen from the previous step, and
+head over to [Starkscan](https://testnet.starkscan.co/) to search for the
+contract. Once found, you can make write calls to the contract in the following
+sequence:
+
++ click on the "connect wallet" button,
+ <img src="./images/cairo/connect.png" alt="connect wallet">
++ select `Argent X` and approve the connection
+ <img src="./images/cairo/connect2.png" alt="connect to argentX">
++ you can now make read and write calls easily.
+
+## Let's learn Cairo
+
+First let's look at a default contract that comes with Protostar which allows
+you to set balance on deployment, increase, and get the balance.
+
+```
+// Language directive - instructs compiler its a StarkNet contract
+%lang starknet
+
+// Library imports from the Cairo-lang library
+from starkware.cairo.common.math import assert_nn
+from starkware.cairo.common.cairo_builtins import HashBuiltin
+
+// @dev Storage variable that stores the balance of a user.
+// @storage_var is a decorator that instructs the compiler the function
+// below it is a storage variable.
+@storage_var
+func balance() -> (res: felt) {}
+
+// @dev Constructor writes the balance variable to 0 on deployment
+// Constructors sets storage variables on deployment. Can accept arguments too.
+@constructor
+func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}() {
+ balance.write(0);
+ return();
+}
+
+// @dev increase_balance updates the balance variable
+// @param amount the amount you want to add to balance
+// @external is a decorator that specifies the func below it is an external
+// function.
+@external
+func increase_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(amount: felt){
+ with_attr error_message("Amount must be positive. Got: {amount}.") {
+ assert_nn(amount);
+ }
+
+ let (res) = balance.read();
+ balance.write(res + amount);
+ return ();
+}
+
+// @dev returns the balance variable
+// @view is a decorator that specifies the func below it is a view function.
+@view
+func get_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}() -> (res: felt) {
+ let (res) = balance.read();
+ return (res,);
+}
+```
+
+Before proceeding to the main lessons, try to build, deploy and interact with
+this contract.
+NB: You should be at `main.cairo` if you are using Protostar.
+
+### 1. The Felt data type
+
+Unlike solidity, where you have access to various data types, Cairo comes with
+just a single data type `..felts`. Felts stands for Field elements, and are a
+252 bit integer in the range `0<=x<=P` where `P` is a prime number. You can
+create a `Uint256` in Cairo by utlizing a struct of two 128 bits felts.
+
+```
+struct Uint256 {
+ low: felt, // The low 128 bits of the value.
+ high: felt, // The high 128 bits of the value.
+}
+```
+
+To avoid running into issues with divisions, it's safer to work with the
+`unsigned_div_rem` method from Cairo-lang's library.
+
+### 2. Lang Directive and Imports
+
+To get started with writing a StarkNet contract, you must specify the directive:
+
+```
+%lang starknet
+```
+
+This directive informs the compiler you are writing a contract and not a
+program. The difference between both is contracts have access to StarkNet's
+storage, programs don't and as such are stateless.
+
+There are important functions you might need to import from the official
+Cairo-lang library or Openzeppelin's, e.g.
+
+```
+from starkware.cairo.common.cairo_builtins import HashBuiltin
+from cairo_contracts.src.openzeppelin.token.erc20.library import ERC20
+from starkware.cairo.common.uint256 import Uint256
+from starkware.cairo.common.bool import TRUE
+```
+
+### 3. Data Structures
+
++ Storage variables: Cairo's storage is a map with `2^251` slots, where each
+ slot is a felt which is initialized to `0`. You create one using the
+ `@storage_var` decorator.
+
+ ```
+ @storage_var
+ func names() -> (name: felt) {}
+ ```
+
++ Storage mappings: Unlike Solidity where mappings have a separate keyword, in
+ Cairo you create mappings using storage variables.
+
+ ```
+ @storage_var
+ func names(address: felt) -> (name: felt) {}
+ ```
+
++ Structs: are a means to create custom data types in Cairo. A `struct` has a
+ size, which is the sum of the sizes of its members. The size can be
+ retrieved using `MyStruct.SIZE`. You create a struct in Cairo using the
+ `struct` keyword.
+
+ ```
+ struct Person {
+ name: felt,
+ age: felt,
+ address: felt,
+ }
+ ```
+
++ Constants: Constants are fixed and as such can't be altered after being set.
+ They evaluate to an integer (field element) at compile time. To create a
+ constant in Cairo, you use the `const` keyword. It's proper practice to
+ capitalize constant names.
+
+ ```
+ const USER = 0x01C6cfC1DB2ae90dACEA243F0a8C2F4e32560F7cDD398e4dA2Cc56B733774E9b
+ ```
+
++ Arrays: Arrays can be defined as a `pointer(felt*)` to the first element of
+ the array. As an array is populated, its elements take up contigous memory
+ cells. The `alloc` keyword can be used to dynamically allocate a new memory
+ segment, which can be used to store an array:
+
+ ```
+ let (myArray: felt*) = alloc ();
+ assert myArray[0] = 1;
+ assert myArray[1] = 2;
+ assert myArray[3] = 3;
+ ```
+
+ You can also use the `new` operator to create fixed-size arrays using
+ tuples. The new operator is useful as it enables you allocate memory and
+ initialize the object in one instruction
+
+ ```
+ func foo() {
+ tempvar arr: felt* = new (1, 1, 2, 3, 5);
+ assert arr[4] = 5;
+ return ();
+ }
+ ```
+
++ Tuples: A tuple is a finite, ordered, unchangeable list of elements. It is
+ represented as a comma-separated list of elements enclosed by parentheses.
+ Their elements may be of any combination of valid types.
+
+ ```
+ local tuple0: (felt, felt, felt) = (7, 9, 13);
+ ```
+
++ Events: Events allows a contract emit information during the course of its
+ execution, that can be used outside of StarkNet. An event can be created,
+ subsequently emitted:
+
+ ```
+ @event
+ func name_stored(address, name) {}
+
+ name_stored.emit(address, name);
+ ```
+
+### 4. Constructors, External and View functions
+
++ Constructors: Constructors are a way to intialize state variables on
+ contract deployment. You create a constructor using the `@constructor`
+ decorator.
+
+ ```
+ @constructor
+ func constructor{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+ range_check_ptr}(_name: felt) {
+ let (caller) = get_caller_address();
+ names.write(caller, _name);
+ return ();
+ }
+ ```
+
++ External functions: External functions are functions that modifies the state
+ of the network. You create an external function using the `@external`
+ decorator:
+
+ ```
+ @external
+ func store_name{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+ range_check_ptr}(_name: felt){
+ let (caller) = get_caller_address();
+ names.write(caller, _name);
+ stored_name.emit(caller, _name);
+ return ();
+ }
+ ```
+
++ View functions: View functions do not modify the state of the blockchain.
+ You can create a view function using the `@view` decorator.
+
+ ```
+ @view
+ func get_name{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+ range_check_ptr}(_address: felt) -> (name: felt){
+ let (name) = names.read(_address);
+ return (name,);
+ }
+ ```
+
+ NB: Unlike Solidity, Cairo supports just External and View function types.
+ You can alternatively also create an internal function by not adding any
+ decorator to the function.
+
+### 5. Decorators
+
+All functions in Cairo are specified by the `func` keyword, which can be
+confusing. Decorators are used by the compiler to distinguish between these
+functions.
+
+Here are the most common decorators you'll encounter in Cairo:
+
++ `@storage_var` — used for specifying state variables.
++ `@constructor` — used for specifying constructors.
++ `@external` — used for specifying functions that write to a state variable.
++ `@event` — used for specifying events
++ `@view` — used to specify functions reading from a state variable
++ `@contract_interface` — used for specifying function interfaces.
++ `@l1_handler` — used for specifying functions that processes message sent from
+ an L1 contract in a messaging bridge.
+
+### 6. BUILTINS, HINTS & IMPLICIT Arguments
+
++ `BUILTINS` are predefined optimized low-level execution units, which are
+ added to Cairo’s CPU board. They help perform predefined computations like
+ pedersen hashing, bitwise operations etc, which are expensive to perform in
+ Vanilla Cairo. Each builtin in Cairo is assigned a separate memory location,
+ accessible through regular Cairo memory calls using implicit parameters. You
+ specify them using the `%builtins` directive
+
+ Here is a list of available builtins in Cairo:
+
+ + `output` — the output builtin is used for writing program outputs
+ + `pedersen` — the pedersen builtin is used for pedersen hashing
+ computations
+ + `range_check` — This builtin is mostly used for integer comparisons,
+ and facilitates check to confirm that a field element is within a range
+ `[0, 2^128)`
+ + `ecdsa` — the ecdsa builtin is used for verifying ECDSA signatures
+ + `bitwise` — the bitwise builtin is used for carrying out bitwise
+ operations on felts
+
++ `HINTS` are pieces of Python codes, which contains instructions that only
+ the prover sees and executes. From the point of view of the verifier these
+ hints do not exist. To specify a hint in Cairo, you need to encapsulate it
+ within `%{` and `%}`. It is good practice to avoid using hints as much as
+ you can in your contracts, as hints are not added to the bytecode, and thus
+ do not count in the total number of execution steps.
+
+ ```
+ %{
+ # Python hint goes here
+ %}
+ ```
+
++ `IMPLICIT ARGUMENTS` are not restricted to the function body, but can be
+ inherited by other functions calls that require them. Implicit arguments are
+ passed in between curly bracelets, like you can see below:
+
+ ```
+ func store_name{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+ range_check_ptr}(_name: felt){
+ let (caller) = get_caller_address();
+ names.write(caller, _name);
+ stored_name.emit(caller, _name);
+ return ();
+ }
+ ```
+
+### 7. Error Messages and Access Controls
+
+You can create custom errors in Cairo which is outputted to the user upon failed
+execution. This can be very useful for implementing checks and proper access
+control mechanisms. An example is preventing a user to call a function except
+user is `admin`.
+
+```
+// imports
+from starkware.starknet.common.syscalls import get_caller_address
+
+// create an admin constant
+const ADMIN = 0x01C6cfC1DB2ae90dACEA243F0a8C2F4e32560F7cDD398e4dA2Cc56B733774E9b
+
+// implement access control
+with_attr error_message("You do not have access to make this action!"){
+ let (caller) = get_caller_address();
+ assert ADMIN = caller;
+}
+
+// using an assert statement throws if condition is not true, thus
+// returning the specified error.
+```
+
+### 8. Contract Interfaces
+
+Contract interfaces provide a means for one contract to invoke or call the
+external function of another contract. To create a contract interface, you use
+the `@contract_interface` keyword:
+
+```
+@contract_interface
+ namespace IENS {
+ func store_name(_name: felt) {
+ }
+
+ func get_name(_address: felt) -> (name: felt) {
+ }
+ }
+```
+
+Once a contract interface is specified, any contract can make calls to that
+contract passing in the contract address as the first parameter like this:
+
+```
+IENS.store_name(contract_address, _name);
+```
+
+Note that Interfaces exclude the function body/logic and the implicit
+arguments.
+
+### 9. Recursions
+
+Due to the unavailability of loops, Recursion is the go-to for similar
+operations. In simple terms, a recursive function is one which calls itself
+repeatedly.
+
+A good example to demonstrate this is writing a function for getting the nth
+fibonacci number:
+
+```
+@external
+func fibonacci{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(n : felt) -> (result : felt){
+ alloc_locals;
+ if (n == 0){
+ return (0);
+ }
+ if (n == 1){
+ return (1);
+ }
+ let (local x) = fibonacci(n - 1);
+ let (local y) = fibonacci(n - 2);
+ return (result=(x + y));
+}
+```
+
+The nth fibonacci term is the sum of the `nth - 1` and the `nth - 2` numbers,
+that's why we get these two as `(x,y)` using recursion.
+
+NB: when implementing recursive functions, always remember to implement a base
+case (`n==0`, `n==1` in our case), to prevent stack overflows.
+
+### 10. Registers
+
+Registers holds values that may change over time. There are 3 major types of
+registers:
+
++ `ap` (allocation pointer) points to a yet unused memory. Temporary variables
+ created using `let`, `tempvar` are held here, and thus susceptible to being
+ revoked.
++ `fp` (frame pointer) points to the frame of the current function. The address
+ of all the function arguments and local variables are relative to this
+ register and as such can never be revoked.
++ `pc` (program counter) points to the current instruction.
+
+### 11. Revoked References
+
+Revoked references occur when there is a call instruction to another function,
+between the definition of a reference variable that depends on `ap` (temp
+variables) and its usage. This occurs as the compiler may not be able to compute
+the change of `ap` (as one may jump to the label from another place in the
+program, or call a function that might change ap in an unknown way).
+
+Here is an example to demonstrate what I mean:
+
+```
+@external
+func get_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}() -> (res: felt) {
+ return (res=100);
+}
+
+@external
+func double_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}() -> (res: felt) {
+ let multiplier = 2;
+ let (balance) = get_balance();
+ let new_balance = balance * multiplier;
+ return (res=new_balance);
+}
+```
+
+If you run that code, you'll run into the revoked reference error as we are
+trying to access the `multiplier` variable after calling the `get_balance`
+function.
+
+In simple cases you can resolve revoked references by adding the keyword
+`alloc_locals` within function scopes. In more complex cases you might need to
+create a local variable to resolve it.
+
+```
+// resolving the `double_balance` function:
+@external
+func double_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}() -> (res: felt) {
+ alloc_locals;
+ let multiplier = 2;
+ let (balance) = get_balance();
+ let new_balance = balance * multiplier;
+ return (res=new_balance);
+}
+```
+
+### 12. Understanding Cairo's Punctuations
+
++ `;` (semicolon). Used at the end of each instruction
++ `()` (parentheses). Used in a function declaration, if statements, and in a
+ tuple declaration
++ `{}` (curly braces). Used in a declaration of implicit arguments and to define
+ code blocks.
++ `[]` (square brackets). Standalone brackets represent the value at a
+ particular address location (such as the allocation pointer, `[ap]`). Brackets
+ following a pointer or a tuple act as a subscript operator, where `x[2]`
+ represents the element with index `2` in `x`.
++ `*` (single asterisk). Refers to the pointer of an expression.
++ `%` (percent sign). Appears at the start of a directive, such as `%builtins`
+ or `%lang`.
++ `%{` and `%}` represent Python hints.
++ `_` (underscore). A placeholder to handle values that are not used, such as an
+ unused function return value.
+
+## Full Contract Example
+
+Below is a simple automated market maker contract example that implements most
+of what we just learnt! Re-write, deploy, have fun!
+
+```
+%lang starknet
+
+from starkware.cairo.common.cairo_builtins import HashBuiltin
+from starkware.cairo.common.hash import hash2
+from starkware.cairo.common.alloc import alloc
+from starkware.cairo.common.math import (assert_le, assert_nn_le,
+ unsigned_div_rem)
+from starkware.starknet.common.syscalls import (get_caller_address,
+ storage_read, storage_write)
+
+
+// CONSTANTS
+//
+// @dev the maximum amount of each token that belongs to the AMM
+const BALANCE_UPPER_BOUND = 2 ** 64;
+
+const TOKEN_TYPE_A = 1;
+const TOKEN_TYPE_B = 2;
+
+// @dev Ensure the user's balances are much smaller than the pool's balance
+const POOL_UPPER_BOUND = 2 ** 30;
+const ACCOUNT_BALANCE_BOUND = 1073741; // (2 ** 30 / 1000)
+
+
+// STORAGE VARIABLES
+//
+// @dev A map from account and token type to corresponding balance
+@storage_var
+func account_balance(account_id: felt, token_type: felt) -> (balance: felt) {}
+
+// @dev a map from token type to corresponding pool balance
+@storage_var
+func pool_balance(token_type: felt) -> (balance: felt) {}
+
+
+// GETTERS
+//
+// @dev returns account balance for a given token
+// @param account_id Account to be queried
+// @param token_type Token to be queried
+@view
+func get_account_token_balance{syscall_ptr: felt*, pedersen_ptr:
+HashBuiltin*, range_check_ptr}(
+ account_id: felt, token_type: felt
+ ) -> (balance: felt) {
+ return account_balance.read(account_id, token_type);
+}
+
+// @dev return the pool's balance
+// @param token_type Token type to get pool balance
+@view
+func get_pool_token_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(
+ token_type: felt
+ ) -> (balance: felt) {
+ return pool_balance.read(token_type);
+}
+
+
+// EXTERNALS
+//
+// @dev set pool balance for a given token
+// @param token_type Token whose balance is to be set
+// @param balance Amount to be set as balance
+@external
+func set_pool_token_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(
+ token_type: felt, balance: felt
+ ) {
+ with_attr error_message("exceeds maximum allowed tokens!"){
+ assert_nn_le(balance, BALANCE_UPPER_BOUND - 1);
+ }
+
+ pool_balance.write(token_type, balance);
+ return ();
+}
+
+// @dev add demo token to the given account
+// @param token_a_amount amount of token a to be added
+// @param token_b_amount amount of token b to be added
+@external
+func add_demo_token{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(
+ token_a_amount: felt, token_b_amount: felt
+ ) {
+ alloc_locals;
+ let (account_id) = get_caller_address();
+
+ modify_account_balance(account_id=account_id, token_type=TOKEN_TYPE_A,
+ amount=token_a_amount);
+ modify_account_balance(account_id=account_id, token_type=TOKEN_TYPE_B,
+ amount=token_b_amount);
+
+ return ();
+}
+
+// @dev intialize AMM
+// @param token_a amount of token a to be set in pool
+// @param token_b amount of token b to be set in pool
+@external
+func init_pool{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(
+ token_a: felt, token_b: felt
+ ) {
+ with_attr error_message("exceeds maximum allowed tokens!"){
+ assert_nn_le(token_a, POOL_UPPER_BOUND - 1);
+ assert_nn_le(token_b, POOL_UPPER_BOUND - 1);
+ }
+
+ set_pool_token_balance(token_type=TOKEN_TYPE_A, balance=token_a);
+ set_pool_token_balance(token_type=TOKEN_TYPE_B, balance=token_b);
+
+ return ();
+}
+
+
+// @dev swaps token between the given account and the pool
+// @param token_from token to be swapped
+// @param amount_from amount of token to be swapped
+// @return amount_to the token swapped to
+@external
+func swap{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*, range_check_ptr}(
+ token_from: felt, amount_from: felt
+ ) -> (amount_to: felt) {
+ alloc_locals;
+ let (account_id) = get_caller_address();
+
+ // verify token_from is TOKEN_TYPE_A or TOKEN_TYPE_B
+ with_attr error_message("token not allowed in pool!"){
+ assert (token_from - TOKEN_TYPE_A) * (token_from - TOKEN_TYPE_B) = 0;
+ }
+
+ // check requested amount_from is valid
+ with_attr error_message("exceeds maximum allowed tokens!"){
+ assert_nn_le(amount_from, BALANCE_UPPER_BOUND - 1);
+ }
+
+ // check user has enough funds
+ let (account_from_balance) =
+ get_account_token_balance(account_id=account_id, token_type=token_from);
+ with_attr error_message("insufficient balance!"){
+ assert_le(amount_from, account_from_balance);
+ }
+
+ let (token_to) = get_opposite_token(token_type=token_from);
+ let (amount_to) = do_swap(account_id=account_id, token_from=token_from,
+ token_to=token_to, amount_from=amount_from);
+
+ return (amount_to=amount_to);
+}
+
+
+// INTERNALS
+//
+// @dev internal function that updates account balance for a given token
+// @param account_id Account whose balance is to be modified
+// @param token_type Token type to be modified
+// @param amount Amount Amount to be added
+func modify_account_balance{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(
+ account_id: felt, token_type: felt, amount: felt
+ ) {
+ let (current_balance) = account_balance.read(account_id, token_type);
+ tempvar new_balance = current_balance + amount;
+
+ with_attr error_message("exceeds maximum allowed tokens!"){
+ assert_nn_le(new_balance, BALANCE_UPPER_BOUND - 1);
+ }
+
+ account_balance.write(account_id=account_id, token_type=token_type,
+ value=new_balance);
+ return ();
+}
+
+// @dev internal function that swaps tokens between the given account and
+// the pool
+// @param account_id Account whose tokens are to be swapped
+// @param token_from Token type to be swapped from
+// @param token_to Token type to be swapped to
+// @param amount_from Amount to be swapped
+func do_swap{syscall_ptr: felt*, pedersen_ptr: HashBuiltin*,
+range_check_ptr}(
+ account_id: felt, token_from: felt, token_to: felt, amount_from: felt
+ ) -> (amount_to: felt) {
+ alloc_locals;
+
+ // get pool balance
+ let (local amm_from_balance) = get_pool_token_balance(token_type =
+ token_from);
+ let (local amm_to_balance) = get_pool_token_balance(token_type=token_to);
+
+ // calculate swap amount
+ let (local amount_to, _) = unsigned_div_rem((amm_to_balance *
+ amount_from), (amm_from_balance + amount_from));
+
+ // update token_from balances
+ modify_account_balance(account_id=account_id, token_type=token_from,
+ amount=-amount_from);
+ set_pool_token_balance(token_type=token_from, balance=(amm_from_balance
+ + amount_from));
+
+ // update token_to balances
+ modify_account_balance(account_id=account_id, token_type=token_to,
+ amount=amount_to);
+ set_pool_token_balance(token_type=token_to, balance=(amm_to_balance -
+ amount_to));
+
+ return (amount_to=amount_to);
+}
+
+
+// @dev internal function to get the opposite token type
+// @param token_type Token whose opposite pair needs to be gotten
+func get_opposite_token(token_type: felt) -> (t: felt) {
+ if(token_type == TOKEN_TYPE_A) {
+ return (t=TOKEN_TYPE_B);
+ } else {
+ return (t=TOKEN_TYPE_A);
+ }
+}
+```
+
+## Additional Resources
+
++ [Official documentation](https://www.cairo-lang.org/docs/)
++ [Starknet EDU](https://medium.com/starknet-edu)
++ [Journey through Cairo](https://medium.com/@darlingtonnnam/journey-through-cairo-i-setting-up-protostar-and-argentx-for-local-development-ba40ae6c5524)
++ [Demystifying Cairo whitepaper](https://medium.com/@pban/demystifying-cairo-white-paper-part-i-b71976ad0108)
++ [Learn about StarkNet with Argent](https://www.argent.xyz/learn/tag/starknet/)
+
+## Development Frameworks
+
++ [Protostar](https://docs.swmansion.com/protostar/docs/tutorials/installation)
++ [Nile](https://github.com/OpenZeppelin/nile)
++ [StarkNet CLI](https://www.cairo-lang.org/docs/quickstart.html)
+
+## Helpful Libraries
+
++ [Cairo-lang](https://github.com/starkware-libs/cairo-lang)
++ [Openzeppelin](https://github.com/OpenZeppelin/cairo-contracts)
+
+## Educational Repos
+
++ [StarkNet Cairo 101](https://github.com/starknet-edu/starknet-cairo-101)
++ [StarkNet ERC721](https://github.com/starknet-edu/starknet-erc721)
++ [StarkNet ERC20](https://github.com/starknet-edu/starknet-erc20)
++ [L1 -> L2 Messaging](https://github.com/starknet-edu/starknet-messaging-bridge)
++ [StarkNet Debug](https://github.com/starknet-edu/starknet-debug)
++ [StarkNet Accounts](https://github.com/starknet-edu/starknet-accounts)
++ [Min-Starknet](https://github.com/Darlington02/min-starknet)
+
+## Security
+
++ [Amarna static analysis for Cairo programs](https://blog.trailofbits.com/2022/04/20/amarna-static-analysis-for-cairo-programs/)
++ [Cairo and StarkNet security by Ctrl03](https://ctrlc03.github.io/)
++ [How to hack almost any Cairo smart contract](https://medium.com/ginger-security/how-to-hack-almost-any-starknet-cairo-smart-contract-67b4681ac0f6)
++ [Analyzing Cairo code using Armana](https://dic0de.substack.com/p/analyzing-cairo-code-using-amarna?sd=pf)
+
+## Future TO-DOs
+
+Update tutorial to fit Cairo 1.0
diff --git a/de-de/yaml-de.html.markdown b/de-de/yaml-de.html.markdown
index 0332c912..00e4fd94 100644
--- a/de-de/yaml-de.html.markdown
+++ b/de-de/yaml-de.html.markdown
@@ -112,7 +112,7 @@ python_komplexe_Zahlen: !!python/komplex 1+2j
####################
# Strings und Zahlen sind nicht die einzigen Skalare, welche YAML versteht.
-# ISO-formatierte Datumsangaben and Zeiangaben können ebenso geparsed werden.
+# ISO-formatierte Datumsangaben and Zeitangaben können ebenso geparsed werden.
DatumZeit: 2001-12-15T02:59:43.1Z
DatumZeit_mit_Leerzeichen: 2001-12-14 21:59:43.10 -5
Datum: 2002-12-14
diff --git a/hjson.html.markdown b/hjson.html.markdown
index b9b35062..6b3cc3ed 100644
--- a/hjson.html.markdown
+++ b/hjson.html.markdown
@@ -15,7 +15,7 @@ to read and edit before passing the JSON data to the machine.
Let's take a look at examples to see the key syntax differences!
-```hjson
+```
{
# Comments are totally supported!
diff --git a/images/cairo/build.png b/images/cairo/build.png
new file mode 100644
index 00000000..7cadb9ad
--- /dev/null
+++ b/images/cairo/build.png
Binary files differ
diff --git a/images/cairo/connect.png b/images/cairo/connect.png
new file mode 100644
index 00000000..86146353
--- /dev/null
+++ b/images/cairo/connect.png
Binary files differ
diff --git a/images/cairo/connect2.png b/images/cairo/connect2.png
new file mode 100644
index 00000000..08b00a81
--- /dev/null
+++ b/images/cairo/connect2.png
Binary files differ
diff --git a/images/cairo/declare.png b/images/cairo/declare.png
new file mode 100644
index 00000000..5b5196ce
--- /dev/null
+++ b/images/cairo/declare.png
Binary files differ
diff --git a/images/cairo/deploy.png b/images/cairo/deploy.png
new file mode 100644
index 00000000..bdb7e53c
--- /dev/null
+++ b/images/cairo/deploy.png
Binary files differ
diff --git a/lbstanza.html.markdown b/lbstanza.html.markdown
index 06a38aef..90e7b7e5 100644
--- a/lbstanza.html.markdown
+++ b/lbstanza.html.markdown
@@ -8,7 +8,7 @@ contributors:
LB Stanza (or Stanza for short) is a new optionally-typed general purpose programming language from the University of California, Berkeley. Stanza was designed to help programmers tackle the complexity of architecting large programs and significantly increase the productivity of application programmers across the entire software development life cycle.
-```stanza
+```
; this is a comment
;<A>
This is a block comment
@@ -268,7 +268,7 @@ is-there = any?({_ == 2.0}, numbers)
doc: \<doc>
# Document Strings
- ```stanza
+ ```
val you-can = "include code snippets, too"
```
@@ -279,4 +279,4 @@ doc: \<doc>
```
\<doc>
defn docfn () : false
-``` \ No newline at end of file
+```
diff --git a/mips.html.markdown b/mips.html.markdown
index 31f735b0..3add0c5b 100644
--- a/mips.html.markdown
+++ b/mips.html.markdown
@@ -162,7 +162,7 @@ gateways and routers.
blt $t0, $t1, t0_gt_t1 # Branches when $t0 < $t1
ble $t0, $t1, t0_gte_t1 # Branches when $t0 <= $t1
bltz $t0, t0_lt0 # Branches when $t0 < 0
- slt $s0, $t0, $t1 # Instruction that sends a signal
+ slt $s0, $t0, $t1 # "Set on Less Than"
# when $t0 < $t1 with result in $s0
# (1 for true)
@@ -186,6 +186,7 @@ gateways and routers.
# else
# max = c;
# else
+ # if (b > c)
# max = b;
# else
# max = c;
@@ -212,8 +213,9 @@ gateways and routers.
# instruction to continue its execution
li $t0, 0
while:
- bgt $t0, 10, end_while # While $t0 is less than 10,
+ bgt $t0, 9, end_while # While $t0 is less than 10,
# keep iterating
+ #actual loop content would go here
addi $t0, $t0, 1 # Increment the value
j while # Jump back to the beginning of
# the loop
diff --git a/openscad.html.markdown b/openscad.html.markdown
index e09b5109..63570cbe 100644
--- a/openscad.html.markdown
+++ b/openscad.html.markdown
@@ -7,7 +7,7 @@ contributors:
Draw 3D models with code using [OpenSCAD](https://openscad.org/).
-```openscad
+```
// Comments look like this
// 3D Primitives
diff --git a/python.html.markdown b/python.html.markdown
index 175f17ec..d9eda60c 100644
--- a/python.html.markdown
+++ b/python.html.markdown
@@ -10,6 +10,7 @@ contributors:
- ["Roberto Fernandez Diaz", "https://github.com/robertofd1995"]
- ["caminsha", "https://github.com/caminsha"]
- ["Stanislav Modrak", "https://stanislav.gq"]
+ - ["John Paul Wohlscheid", "https://gitpi.us"]
filename: learnpython.py
---
@@ -84,7 +85,7 @@ False - 5 # => -5
# Comparison operators look at the numerical value of True and False
0 == False # => True
-1 == True # => True
+2 > True # => True
2 == True # => False
-5 != False # => True
@@ -1045,7 +1046,6 @@ print(say(say_please=True)) # Can you buy me a beer? Please! I am poor :(
### Free Online
* [Automate the Boring Stuff with Python](https://automatetheboringstuff.com)
-* [Ideas for Python Projects](http://pythonpracticeprojects.com)
* [The Official Docs](https://docs.python.org/3/)
* [Hitchhiker's Guide to Python](https://docs.python-guide.org/en/latest/)
* [Python Course](https://www.python-course.eu)
diff --git a/r.html.markdown b/r.html.markdown
index 2746d1eb..a063cc2f 100644
--- a/r.html.markdown
+++ b/r.html.markdown
@@ -12,7 +12,7 @@ R is a statistical computing language. It has lots of libraries for uploading an
```r
-# Comments start with number symbols.
+# Comments start with hash signs, also known as number symbols (#).
# You can't make multi-line comments,
# but you can stack multiple comments like so.
diff --git a/raku.html.markdown b/raku.html.markdown
index 53404f58..39bc0e51 100644
--- a/raku.html.markdown
+++ b/raku.html.markdown
@@ -122,7 +122,7 @@ say @array; # OUTPUT: «a 6 b␤»
# context, and any duplicated keys are deduplicated.
my %hash = 'a' => 1, 'b' => 2;
-# Keys get auto-quoted when the fat comman (`=>`) is used. Trailing commas are
+# Keys get auto-quoted when the fat comma (`=>`) is used. Trailing commas are
# okay.
%hash = a => 1, b => 2, ;
diff --git a/rust.html.markdown b/rust.html.markdown
index 9e07e005..c677ed96 100644
--- a/rust.html.markdown
+++ b/rust.html.markdown
@@ -223,7 +223,7 @@ fn main() {
type FunctionPointer = fn(u32) -> u32;
let fib : FunctionPointer = fibonacci;
- println!("Fib: {}", fib(4));
+ println!("Fib: {}", fib(4)); // 5
/////////////////////////
// 3. Pattern matching //
diff --git a/set-theory.html.markdown b/set-theory.html.markdown
index d55ab7d5..f89345c0 100644
--- a/set-theory.html.markdown
+++ b/set-theory.html.markdown
@@ -17,7 +17,7 @@ Set theory is a branch of mathematics that studies sets, their operations, and t
* the cross operator, `×`, means "the Cartesian product of".
### Qualifiers
-* the colon qualifier, `:`, means "such that";
+* the colon, `:`, or the vertical bar `|` qualifiers are interchangeable and mean "such that";
* the membership qualifier, `∈`, means "belongs to";
* the subset qualifier, `⊆`, means "is a subset of";
* the proper subset qualifier, `⊂`, means "is a subset of but is not equal to".
diff --git a/zh-cn/clojure-macro-cn.html.markdown b/zh-cn/clojure-macro-cn.html.markdown
index 23b2f203..85b966e9 100644
--- a/zh-cn/clojure-macro-cn.html.markdown
+++ b/zh-cn/clojure-macro-cn.html.markdown
@@ -131,7 +131,7 @@ lang: zh-cn
; 然而,如果我们希望它在编译期执行,就需要创建宏
(defmacro inline-2 [form]
- (inline-2-helper form)))
+ (inline-2-helper form))
(macroexpand '(inline-2 (1 + (3 / 2) - (1 / 2) + 1)))
; -> (+ (- (+ 1 (/ 3 2)) (/ 1 2)) 1)
diff --git a/zig.html.markdown b/zig.html.markdown
index 82c6b994..f8c866e5 100644
--- a/zig.html.markdown
+++ b/zig.html.markdown
@@ -39,7 +39,7 @@ Prior knowledge of C is recommended.
## Zig language
-```zig
+```
//! Top-level documentation.
/// Documentation comment.
@@ -49,7 +49,7 @@ Prior knowledge of C is recommended.
### Hello world.
-```zig
+```
// Import standard library, reachable through the "std" constant.
const std = @import("std");
@@ -67,7 +67,7 @@ pub fn main() void {
```
### Booleans, integers and float.
-```zig
+```
// Booleans.
// Keywords are preferred to operators for boolean operations.
print("{}\n{}\n{}\n", .{
@@ -109,7 +109,7 @@ i <<| 8 == 255 // u8: won't go higher than 255
```
### Arrays.
-```zig
+```
// An array is a well-defined structure with a length attribute (len).
// 5-byte array with undefined content (stack garbage).
@@ -156,7 +156,7 @@ try some_integers[i]; // Runtime error 'index out of bounds'.
```
### Multidimensional arrays.
-```zig
+```
const mat4x4 = [4][4]f32{
[_]f32{ 1.0, 0.0, 0.0, 0.0 },
@@ -177,7 +177,7 @@ for (mat4x4) |row, row_index| {
```
### Strings.
-```zig
+```
// Simple string constant.
const greetings = "hello";
@@ -195,7 +195,7 @@ print("string: {s}\n", .{greetings});
```
### Slices.
-```zig
+```
// A slice is a pointer and a size, an array without compile-time known size.
// Slices have runtime out-of-band verifications.
@@ -206,7 +206,7 @@ const slice = array[0..array.len]; // "slice" represents the whole array.
```
### Pointers.
-```zig
+```
// Pointer on a value can be created with "&".
const x: i32 = 1;
@@ -223,7 +223,7 @@ const foo = pointer.?; // Get the pointed value, otherwise crash.
```
### Optional values (?<type>).
-```zig
+```
// An optional is a value than can be of any type or null.
// Example: "optional_value" can either be "null" or an unsigned 32-bit integer.
@@ -239,7 +239,7 @@ if (x) |value| {
```
### Errors.
-```zig
+```
// Zig provides an unified way to express errors.
// Errors are defined in error enumerations, example:
@@ -299,7 +299,7 @@ var value = try some_function();
### Control flow.
-```zig
+```
// Conditional branching.
if (condition) {
@@ -384,7 +384,7 @@ const result = for (items) |value| {
```
### Labels.
-```zig
+```
// Labels are a way to name an instruction, a location in the code.
// Labels can be used to "continue" or "break" in a nested loop.
@@ -434,7 +434,7 @@ const result = for (items) |value| { // First: loop.
```
### Switch.
-```zig
+```
// As a switch in C, but slightly more advanced.
// Syntax:
@@ -461,7 +461,7 @@ const bar = switch (foo) {
```
### Structures.
-```zig
+```
// Structure containing a single value.
const Full = struct {
@@ -564,7 +564,7 @@ print("p.y: {}\n", .{p.y}); // 30
```
### Tuples.
-```zig
+```
// A tuple is a list of elements, possibly of different types.
const foo = .{ "hello", true, 42 };
@@ -572,7 +572,7 @@ const foo = .{ "hello", true, 42 };
```
### Enumerations.
-```zig
+```
const Type = enum { ok, not_ok };
@@ -606,7 +606,7 @@ const x = switch (direction) {
```
### Unions.
-```zig
+```
const Bar = union {
boolean: bool,
@@ -622,7 +622,7 @@ const foo: Bar = .{ .int = 42 };
```
### Tagged unions.
-```zig
+```
// Unions can be declared with an enum tag type, allowing them to be used in
// switch expressions.
@@ -653,7 +653,7 @@ switch (nay) {
```
### Defer and errdefer.
-```zig
+```
// Make sure that an action (single instruction or block of code) is executed
// before the end of the scope (function, block of code).
@@ -712,7 +712,7 @@ However, here are some examples, to get an idea of what you can expect:
Very simple way of avoiding leaks.
A first example.
-```zig
+```
// "!void" means the function doesn't return any value except for errors.
// In this case we try to allocate memory, and this may fail.
fn foo() !void {
@@ -735,7 +735,7 @@ fn foo() !void {
```
### Memory allocation combined with error management and defer.
-```zig
+```
fn some_memory_allocation_example() !void {
// Memory allocation may fail, so we "try" to allocate the memory and
@@ -759,7 +759,7 @@ fn some_memory_allocation_example() !void {
```
### Memory allocators: a taste of the standard library.
-```zig
+```
// Allocators: 4 main functions to know
// single_value = create (type)
@@ -846,7 +846,7 @@ fn gpa_arena_allocator_fn() !void {
```
### Comptime.
-```zig
+```
// Comptime is a way to avoid the pre-processor.
// The idea is simple: run code at compilation.
@@ -883,7 +883,7 @@ list.items[0] = 10;
```
### Conditional compilation.
-```zig
+```
const available_os = enum { OpenBSD, Linux };
const myos = available_os.OpenBSD;
@@ -905,7 +905,7 @@ const myprint = switch(myos) {
```
### Testing our functions.
-```zig
+```
const std = @import("std");
const expect = std.testing.expect;
@@ -936,7 +936,7 @@ There are more than a hundred built-ins, allowing very low-level stuff:
- etc.
Example: enums aren't integers, they have to be converted with a built-in.
-```zig
+```
const Value = enum { zero, stuff, blah };
if (@enumToInt(Value.zero) == 0) { ... }
if (@enumToInt(Value.stuff) == 1) { ... }