eGospodarka.pl
eGospodarka.pl poleca

eGospodarka.plGrupypl.comp.programmingVerona › Re: Verona
  • Path: news-archive.icm.edu.pl!news.icm.edu.pl!newsfeed.pionier.net.pl!3.eu.feeder.erj
    e.net!feeder.erje.net!border1.nntp.ams1.giganews.com!nntp.giganews.com!newsfeed
    .neostrada.pl!unt-exc-02.news.neostrada.pl!unt-spo-a-02.news.neostrada.pl!news.
    neostrada.pl.POSTED!not-for-mail
    Subject: Re: Verona
    Newsgroups: pl.comp.programming
    References: <5dee9c2f$0$17349$65785112@news.neostrada.pl>
    <5df2bdc0$0$17353$65785112@news.neostrada.pl>
    <5e28b6cf$0$550$65785112@news.neostrada.pl>
    From: Borneq <b...@a...hidden.pl>
    Date: Fri, 31 Jan 2020 19:43:51 +0100
    User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:68.0) Gecko/20100101
    Thunderbird/68.4.1
    MIME-Version: 1.0
    In-Reply-To: <5e28b6cf$0$550$65785112@news.neostrada.pl>
    Content-Type: text/plain; charset=utf-8; format=flowed
    Content-Language: en-US
    Content-Transfer-Encoding: 8bit
    Lines: 112
    Message-ID: <5e347568$0$539$65785112@news.neostrada.pl>
    Organization: Telekomunikacja Polska
    NNTP-Posting-Host: 37.47.6.248
    X-Trace: 1580496232 unt-rea-a-02.news.neostrada.pl 539 37.47.6.248:27547
    X-Complaints-To: a...@n...neostrada.pl
    Xref: news-archive.icm.edu.pl pl.comp.programming:214736
    [ ukryj nagłówki ]

    Czy może ktoś wyjasnić składnię, np:
    ----------------------------------------------------
    ------------
    // Copyright (c) Microsoft Corporation. All rights reserved.
    // Licensed under the MIT License.
    class Fib
    {
    /**
    * This example illustrates creating a lot of recursive work by
    calculating
    * fibonacci numbers top down.
    *
    * It uses promises to allow results to be reacted to.
    *
    * The compiler does not have syntax support for promises, and they
    are just
    * treated as a special type of cown at the moment. This will change
    but the
    * code illustrates roughly how they would be used.
    *
    * Cown's only currently wrap object types, not primitives, so the
    example
    * uses a U64Obj, that boxes a U64. This is not essential, and will be
    * addressed in the future.
    *
    * The idealised syntax we are aiming for is given below
    * fib(x: U64): promise[U64]
    {
    if (x < 2)
    {
    // Implicitely lifting a Value to a promise
    1
    }
    else
    {
    // When returns a promise for the value it evaluates to.
    // Thus nested when would require an implicit coercion from
    // promise[promise[U64]] to promise[U64]
    when ()
    {
    var p1 = Fib.fib(x - 1);
    var p2 = Fib.fib(x - 2);
    when (p1, p2) {
    p1 + p2
    }
    }
    }
    }
    */

    fib(x: U64 & imm): cown[U64Obj] & imm
    {
    var pw = Promise.create();
    var pr = (mut-view pw).wait_handle();

    if (x < 2)
    {
    pw.fulfill(U64Obj.create(1));
    }
    else
    {
    // `when` with no arguments used to start a new asynchronous task.
    // Better syntax may be needed for this.
    // This is required, so that the whole promise graph isn't
    constructed
    // sequentially.
    when ()
    {
    var p1 = Fib.fib(x - 1);
    var p2 = Fib.fib(x - 2);
    // When both computations complete, fulfill the result with the
    addition
    // of the two sub calls.
    when (p1, p2) {
    var r = U64Obj.create(p1.v + p2.v);
    pw.fulfill(r)
    }
    }
    };
    pr
    }
    }

    class Main
    {
    main()
    {
    when (var uo = Fib.fib(12))
    {
    // CHECK-L: result=233
    Builtin.print1("result={}\n", uo.v);
    }
    }
    }
    ----------------------------------------------------
    ------------
    kompiluje się, najpierw (po skompilowaniu kompilatora i interpretera):
    ~/veronac --output fib fib.verona
    potem
    ~/interpreter --cores 2 fib
    --cores nieobowiązkowe
    można zamiast interpretera od razu uruchamić przez kompilator, ale warto
    skompilować do kodu bajtowego.
    zamiast 12 mozna wpisać 24, lepiej nie wpisywać wię...szych wartości typu
    120 bo złożoność jest wykładnicza.
    co oznaczają
    1.Promise
    2.when
    3.mut-view
    4.fulfill
    szkoda że nie ma większego opisu, dokumentacji.



Podziel się

Poleć ten post znajomemu poleć

Wydrukuj ten post drukuj


Następne wpisy z tego wątku

Najnowsze wątki z tej grupy


Najnowsze wątki

Szukaj w grupach

Eksperci egospodarka.pl

1 1 1

Wpisz nazwę miasta, dla którego chcesz znaleźć jednostkę ZUS.

Wzory dokumentów

Bezpłatne wzory dokumentów i formularzy.
Wyszukaj i pobierz za darmo: