syntax icon indicating copy to clipboard operation
syntax copied to clipboard

Add sugar for dereferencing

Open amiralies opened this issue 3 years ago • 2 comments

happened to write a heavily mutable code and using .contents everywhere was a pain. a sugar like ml's ^ makes reading and writing mutable code with refs much easier

amiralies avatar Aug 04 '22 14:08 amiralies

Not sure I understand correctly. If you mean ! in OCaml for dereferencing of ref, I think the operators for deref and mutate functions are needed in the syntax layer.

let foo = ref("")
let deref = r => r.contents // `!` in OCaml
let mutate = (r, value) => r.contents = value // `:=` in OCaml
let bar = ^foo // deref(foo)
let baz = foo := "baz" // mutate(foo, "baz")
// `^` and `:=` are just examples.

mununki avatar Aug 04 '22 23:08 mununki

yes. := is available today

amiralies avatar Aug 05 '22 02:08 amiralies

The rescript-lang/syntax repo is obsolete and will be archived soon. If this issue is still relevant, please reopen in the compiler repo (https://github.com/rescript-lang/rescript-compiler) or comment here to ask for it to be moved. Thank you for your contributions.

stale[bot] avatar May 28 '23 15:05 stale[bot]