awesome-tact icon indicating copy to clipboard operation
awesome-tact copied to clipboard

Add https://learnxinyminutes.com/docs/tact

Open anton-trunov opened this issue 1 year ago • 5 comments

We might want to refurbish https://learnxinyminutes.com/docs/tact a bit

anton-trunov avatar Mar 13 '24 07:03 anton-trunov

Yeah, it's definitely needs correction in many places

image

novusnota avatar Mar 13 '24 18:03 novusnota

For the future reference, this counter contract may be used to showcase Tact at the beginning of the page, then proceed with explanations. Or, this can be put to some later parts, once every detail is explained prior.

import "@stdlib/deploy"; // one of the standard libraries

// Defining a new Message type, which consists of two fields
message Add {
    queryId: Int as uint64; // unsigned integer value stored in 8 bytes
    amount: Int as uint32; // unsigned integer value stored in 4 bytes
}

// Defining a contract with the Deployable trait from @stdlib/deploy:
contract SimpleCounter with Deployable {
    // Persistent state variables of the contract:
    id: Int as uint32;
    counter: Int as uint32;

    // This gets run when the contract is deployed.
    // All state variables have to be initialized with either of:
    // 1. default values in their definition above
    // 2. assignments in the init()
    init(id: Int) { // <- you can pass values for deployment
        self.id = id;     // <- store the id passed on deployment
        self.counter = 0; // <- reset the counter
    }

    // Register a receiver of messages from other contracts.
    // Messages in Tact can be one of the two:
    // 1. Message type, as defined above
    // 2. String type, like "I am the message!"
    receive(msg: Add) {
        self.counter += msg.amount; // <- increase the counter
    }

    // This is a getter function, which are special external interface functions
    // that allow users to query information from the contract.
    get fun counter(): Int {
        return self.counter; // <- return the counter value
    }

    // Another getter function, but for the id:
    get fun id(): Int {
        return self.id; // <- return the id value
    }
}

novusnota avatar Mar 14 '24 07:03 novusnota

Just checked X in Y recently and didn't find the Tact there. Turns out (found it by running git log --all -1 -- tact.html.markdown in the repo) that the Tact and some other programming languages got removed on April 29th.

See the commit: https://github.com/adambard/learnxinyminutes-docs/commit/d2efe1c0f929c0186b1489e71f2882649bc79961 And the motivation behind it: https://github.com/adambard/learnxinyminutes-docs/pull/4912

Therefore, I don't think it's feasible to expect Tact there. So we should just continue to improve the docs. Perhaps, the "primer" ("tour" or "overview", to be determined) page is to be introduced there to mimic the nice idea of "learn X in Y minutes" scenic tour. I'm thinking to put it under Book→Cheatsheets may be reasonable.

As an aside, Bitcoin uses https://en.bitcoin.it/wiki/Script, which is a Forth-like stack-based programming language (albeit without loops), so I thought it may have some research on optimizations in it. May help with our future transition to Fift or TVM backends from the current FunC one

novusnota avatar May 05 '24 00:05 novusnota

Therefore, I don't think it's feasible to expect Tact there. So we should just continue to improve the docs. Perhaps, the "primer" ("tour" or "overview", to be determined) page is to be introduced there to mimic the nice idea of "learn X in Y minutes" scenic tour. I'm thinking to put it under Book→Cheatsheets may be reasonable

Excellent idea! Let's move this stuff there. Could you please open an issue in tact-docs for that?

anton-trunov avatar May 05 '24 07:05 anton-trunov

Could you please open an issue in tact-docs for that?

Sure, here it is: https://github.com/tact-lang/tact/issues/1161

novusnota avatar May 05 '24 12:05 novusnota

Closing this, since we have the corresponding issue in tact-docs

anton-trunov avatar Jun 21 '24 17:06 anton-trunov