aeternity / aesophia

Stand alone compiler for the Sophia smart contract language
https://docs.aeternity.com/aesophia
ISC License
52 stars 19 forks source link

Pointwise state modifications #416

Open radrow opened 2 years ago

radrow commented 2 years ago

This would be a syntactic sugar that would possibly make it nicer to modify state fields (if it is a record, which is mostly the case).

record r = {val : int}
record state = {x : int, y : r}
stateful function f() =
  state.x = 21
  state.y.val = 37

which would desugar to

put(state{x = 21})
put(state{y = state.y{val = 37}})

and ideally to

put(state{x = 21, y = state.y{val = 37}})
radrow commented 2 years ago

Note that state modifications are still explicit, as one needs to refer to the state as lvalue.

brainiacfive commented 2 years ago

+1

I thought the compiler optimizes multiple puts into one at any rate.

marc0olo commented 2 years ago

oh yeah, I like this one! :)