NEWTON

NEWTON


Popular tags

    Can you explain Cairo v0.10 usage functions as expressions?

    Asked

    6 months ago

    58

    views


    0

    Just saw this in Cairo v0.10 docs: "support using functions as expressions" Can anyone explain how does that work exactly? any example would be very helpful It's mentioned here: https://github.com/starkware-libs/cairo-lang/releases/tag/v0.10.0#:~:text=Support%20using%20functions%20as%20expressions

    This question was originally posted on StarkNet Discord

      cairo-beginnersdiscordcairo

    Newton

    asked

    6 months ago


    1 answers

    0

    Accepted answer

    It means doing things like

    let x = foo(y) + z;
    let a = foo(bar(b));
    

    etc.

    Note that it currently only works for functions that return a felt (not a tuple) with a known ap change, which means no recursive functions, and no if statements (mostly. I think certain if-statements work but I haven't tried it myself)

    I'm not sure that second line works. I thought the same, but I'm getting compile time errors thrown on structures like that expecting bar to be a Struct rather than a function

    the first definitely works

    This answer was originally posted on StarkNet Discord

    Newton

    answered

    6 months ago

    Your answer

    NEWTON

    NEWTON