# Explicit denotation of variability and immutability

**URL:** <https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686>\
**Category:** Internals & Design\
**Tags:** proposal\
**Created:** [January 30, 2018, 10:16am UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686 "2018-01-30T10:16:36Z")\
**Posts on this page:** 18\
**Page:** 5

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [February 15, 2018, 2:38pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/82 "2018-02-15T14:38:44Z")

</div>

> [@StefanKarpinski](#):
>
> On the whole, this blog post seems to be an essay about how much this guy likes Haskell. Which is cool, but not all that helpful when designing other languages with very different target audiences and design constraints.

I found a number of points in the blog that I think are relevant to Julia design (what follows is meant as constructive criticism, I think these issues can be addressed in the future, maybe during 1.x, maybe at 2.0, Julia is already wonderful, but nothing in this world is perfect):

> The language must try really hard to catch programming mistakes, especially the mundane ones that happen to everyone all the time. When it finds a mistake, it must point to the true reason for it, preferably with an error message that humans understand.

Julia does have problems with rather inscrutable error messages, and that is something that can be improved at any time during the release cycle. Also, many times a full stack trace is shown, that is not that relevant (and may be rather scary) to most Julian programmers (the technical/scientist/mathematician types who use Julia instead of R / Matlab / Python) (maybe the verbosity could be controlled, so that you can get the full stack when you are actually tracking down the problem in question)

> Should programming bugs be discovered by the programmer or by the user? The answer seems pretty clear. Therefore, a language should be designed so that as many programming errors as possible are discovered early on, that is before the program is sent to the user. In fact, in order to speed up development (remember that the development time is expensive) the programmer should be told about errors without having to run the program and directing its execution to the place where the latest code change actually gets executed.

Better support for `Lint.jl` maybe would be helpful here?  
More support in the language for indicating what should be part of the public API of a package or module, even when a name is not exported, might also be helpful.

On the whole though, I feel that the blog actually vindicates a lot of the design of Julia, so kudos to all of the people who have been involved in that, from the original creators to all the people (like Tim and Matt among others) who’ve extended it in important ways (Holy traits for example).

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [February 15, 2018, 2:40pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/83 "2018-02-15T14:40:50Z")

</div>

So, learn Julia to the point where you _do_ have the know-how.  
I feel it would be time well spent! 🤓

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [February 15, 2018, 2:49pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/84 "2018-02-15T14:49:45Z")

</div>

Will take heed of that advice. 😅

---

<div class="post-metadata">

**Author:** ![NaOH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naoh/32/5632_2.png) [@NaOH](https://discourse.julialang.org/u/NaOH)\
**Post date:** [February 15, 2018, 3:15pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/85 "2018-02-15T15:15:56Z")

</div>

> [@SepandMeenu](#):
>
> The point is that I have not sufficient know-how to devise a new parser (or modify the current one).  
> Is there a place/person to get help to build up such an experimental Julia parser?

I would advise you to wait until both Julia and JuliaParser stabilizes (both are version 1.0 at least), I have been planning on making a Spanish version of Julia AKA Julieta, this way, that would aid me in teaching programming to non native English speaking children, specially for those that have already experience with Scratch and want to go beyond.

You could study JuliaParser source code, it’s 100% Julia, no Scheme (Femtolisp) knowledge needed, and you could probably meta program most of your changes.

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 15, 2018, 3:43pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/86 "2018-02-15T15:43:59Z")

</div>

JuliaParser is very outdated. Use [https://github.com/ZacLN/CSTParser.jl](https://github.com/ZacLN/CSTParser.jl) instead.

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [February 15, 2018, 4:02pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/87 "2018-02-15T16:02:18Z")

</div>

Thanks for the note. The point is that I am not familiar with the _general_ principles/methods of parsing – regardless of the specific language.  
I have to find a simple & concise tutorial, “Parsing for Dummies”.

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [February 15, 2018, 4:04pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/88 "2018-02-15T16:04:54Z")

</div>

You mean `JuliaParser` is not under active development, and instead, `CSTParser` is active?

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [February 15, 2018, 4:08pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/89 "2018-02-15T16:08:07Z")

</div>

Could I refer to you, @ScottPJones , @NaOH , or @kristoffer.carlsson , @improbable22 , via private messages if I had questions on parsing?

---

<div class="post-metadata">

**Author:** ![kristoffer.carlsson](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/kristoffer.carlsson/32/22_2.png) [@kristoffer.carlsson](https://discourse.julialang.org/u/kristoffer.carlsson)\
**Post date:** [February 15, 2018, 4:11pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/90 "2018-02-15T16:11:25Z")

</div>

Better to use discourse so everyone can see the answers. Private communication is quite time inefficient.

---

<div class="post-metadata">

**Author:** ![ScottPJones](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/scottpjones/32/146_2.png) [@ScottPJones](https://discourse.julialang.org/u/ScottPJones)\
**Post date:** [February 15, 2018, 4:11pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/91 "2018-02-15T16:11:32Z")

</div>

Sure, no problem.

---

<div class="post-metadata">

**Author:** ![NaOH](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/naoh/32/5632_2.png) [@NaOH](https://discourse.julialang.org/u/NaOH)\
**Post date:** [February 15, 2018, 5:35pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/92 "2018-02-15T17:35:45Z")

</div>

Thank you Kristoffer didn’t know about CSTParser.

You can ping me anytime you like, I’ll try to help, but I am no parser expert by any means. 😛 I just red the JuliaParser code and with the help of the community was able to refactor a bit of it and understand how it works a little in the process.

---

<div class="post-metadata">

**Author:** ![stevengj](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stevengj/32/71_2.png) [@stevengj](https://discourse.julialang.org/u/stevengj)\
**Post date:** [February 15, 2018, 6:12pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/93 "2018-02-15T18:12:49Z")

</div>

I don’t see why you would have to touch a parser in order to experiment with this. Julia already parses `:=` as an operator with the same precedence as `=`, for example. You can just use the Julia parser as-is, and then rewrite the parsed code with a macro.

For example, if you define a `macro explicitmutation`, you could use it with

```julia
@explicitmutation function foo(x)
    y := x
    z = sqrt(x)
    y := y + z
    return y - x
end

```

and transform/interpret the parsed code however you want (e.g. to throw an error if you assign something with `=` and later mutate it).

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [February 16, 2018, 9:12am UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/94 "2018-02-16T09:12:04Z")

</div>

Is there a minimal example of a parser, along with some theory, to learn the basics?

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [February 19, 2018, 8:42am UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/95 "2018-02-19T08:42:44Z")

</div>

“Transients are interesting and we should steal them.” — note from a Haskeller on Reddit

The idea of _transient data structures_ in Clojure is quite similar to what I had in mind in my proposal (a sort of “mapping” from mutable data structures to immutables ones), though, in Clojure, the idea is to make a temporary mutable from an immutable, for short use; see eg.,  
\< [Clojure - Transient Data Structures](https://clojure.org/reference/transients) \>

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [February 28, 2018, 7:45am UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/96 "2018-02-28T07:45:15Z")

</div>

“Every time someone writes `i = i + 1`, a mathematician dies.”

– a deep statement 😆

---

<div class="post-metadata">

**Author:** ![SepandMeenu](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/sepandmeenu/32/8846_2.png) [@SepandMeenu](https://discourse.julialang.org/u/SepandMeenu)\
**Post date:** [September 13, 2018, 8:09am UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/97 "2018-09-13T08:09:59Z")

</div>

_A Critique of Impure Reason_  
Runar Bjarnason

> **[A Critique of Impure Reason - Higher Order](http://blog.higher-order.com/blog/2009/04/27/a-critique-of-impure-reason/)**
>
> Much has been made of the difference between “object-oriented” and “functional” programming. As much as I’ve seen …

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [September 13, 2018, 12:00pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/98 "2018-09-13T12:00:52Z")

</div>

> **[Haskell](https://en.wikipedia.org/wiki/Haskell_(programming_language))**
>
> Haskell (/ˈhæskəl/) is a general-purpose, statically-typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell has pioneered a number of programming language features such as type classes, which enable type-safe operator overloading, and monadic input/output (IO). It is named after logician Haskell Curry. Haskell's main implementation is the Glasgow Haskell Compiler (GHC).
> Haskell's semantics are...

---

<div class="post-metadata">

**Author:** ![Vic](https://avatars.discourse-cdn.com/v4/letter/v/9e8a1a/32.png) [@Vic](https://discourse.julialang.org/u/Vic)\
**Post date:** [November 5, 2018, 7:59pm UTC](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686/99 "2018-11-05T19:59:21Z")

</div>

> [@SepandMeenu](#):
>
> I propose _explicit_ **syntactical** safeguards to denote programmer’s intention to **mutate values or bindings** (mutations of the state) in _any_ scope.

One useful but much simpler change compared to what the OP suggests, is to have a different syntactical notation for _defining_ vs _changing_ a binding. For ex, keep `=` for defining, and introduce `:=` or `=:` (or other) for changing the binding of the previously defined variable (re-assignment).

I think when we program we already have this different intent in mind (“I’m going to define this to be…” , “I’m going to change that var to…”), so it will not be any mental cost to actually convey that intent when we write the code.  
So it’s a low-hanging fruit that I think most dynamic or scripting langs don’t collect.  
I suspect doing so, can result in compiler being able to catch more errors, and perhaps optimize the code better, and perhaps also give more options to solve the scope problem (as this [github reply](https://github.com/JuliaLang/julia/issues/28789#issuecomment-423346801) by @jeff.bezanson ).

I guess it could be introduced at first as optional, and if most agree, then in future mandatory.

EDIT: I found that this(or essentially this) idea was also proposed, independently, by @Balance  
,and with more background details, [here](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/201) , [here](https://discourse.julialang.org/t/another-possible-solution-to-the-global-scope-debacle/15894/214)

[Previous page](https://discourse.julialang.org/t/explicit-denotation-of-variability-and-immutability/8686.md?page=4)
