Re: [m-users.] Global variables that are local to the thread
"Zoltan Somogyi" <[email protected]> Mon, 06 Nov 2023 22:40:18 +1100 (AEDT)
| Newsgroups | gmane.comp.lang.mercury.general |
|---|---|
| Message-ID | <[email protected]> |
On 2023-11-06 22:20 +11:00 AEDT, "Sean Charles (emacstheviking)" <[email protected]> wrote: > I have never used anything but state passing with my Mercury code, sometimes it feels like more work up front but it always pays back in the end. > > On that front, I was reading the docs for 'io' and noted that the 'globals' field is now obselete! The comment says: > > % The globals field is obsolete. A mutable declaration will provide > % the same functionality with better type safety. > % > > But I wasn't sure that that actually means, who provides the mutable and where etc ? The globals part of the I/O state used to provide a single value, which had to be converted from univ to the expected type (which is a semidet operation) on every read access. When you define a mutable and attach it to the I/O state, you can specify the type of the value in the mutable, and get predicate of the mutable returns that value without runtime type checking (so the access is faster), with the get operation being det (so it does not need an if-then-else around it, making writing, and *reading*, the code faster. As for where, you pick a module in your program, based on what code will need access to the value in that mutable. By the way, can you guys please delete from your reply emails the parts of the original email that you are *not* responding to? Thanks in advance. Zoltan. _______________________________________________ users mailing list [email protected] https://lists.mercurylang.org/listinfo/users