zksecurity / noname

Noname: a programming language to write zkapps
https://zksecurity.github.io/noname/
181 stars 47 forks source link

Clone function? #6

Open mimoo opened 2 years ago

mimoo commented 2 years ago

Currently everything is passed by reference in the language. There is no such thing as passing by value.

You can mutate local variables if there's the keyword mut.

When you pass a variable to a function, I believe it can mutate the variable eventhough it might not be mutable... we need to change that. Perhaps functions should annotate what args they might want to modify?

mimoo commented 2 years ago

Also. If I want to copy/clone a var, it should be easy.

Perhaps let x = y is enough.

Create the number of necessary internal var and wire them?

Do I need to wire them? Perhaps I don't because things are indeed passed by value lol

What does reassign do again?

mimoo commented 2 years ago

Ok proposition: dont allow mutation of arguments of functions in general. Like that if someone tried they get an error. Easy

mimoo commented 2 years ago

It also sounds like let x = y should already work, as we would reassign vars on x and not y if we try to mutate x!

mimoo commented 2 years ago

Everything is actually copy on write!

mimoo commented 2 years ago

If var is mutable, pass by pointer, otherwise pass by cvar

A var is in noname A cvar is internal A fvar is a field ellement or cellvar

mimoo commented 2 years ago

Call it reference not pointer. Or even better "mutable reference"