# Is there a way to tell if a method is pure?

**URL:** https://discourse.julialang.org/t/is-there-a-way-to-tell-if-a-method-is-pure/2355
**Category:** General Usage
**Tags:** question
**Created:** [February 27, 2017, 11:02pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-tell-if-a-method-is-pure/2355 "2017-02-27T23:02:10Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [February 27, 2017, 11:02pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-tell-if-a-method-is-pure/2355/1 "2017-02-27T23:02:10Z")

</div>

While drilling through `Method` fields, I’ve found `method.source.pure` flag. Does it mean there’s some analysis involved indicating if the function is pure, i.e. doesn’t modify its inputs?

---

<div class="post-metadata">

### Author: ![yuyichao](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/yuyichao/32/20_2.png) [@yuyichao](https://discourse.julialang.org/u/yuyichao)
#### Post date: [February 27, 2017, 11:07pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-tell-if-a-method-is-pure/2355/2 "2017-02-27T23:07:24Z")

</div>

There’s a really simple one in type inference which we are planing to improve.

---

<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: [February 28, 2017, 2:13pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-tell-if-a-method-is-pure/2355/3 "2017-02-28T14:13:06Z")

</div>

The simplest I’ve found is to ask @jameson, but it’s easy to predict the answer: he will say “no”.

Longer version: the sense of “purity” which is being used in Julia’s internals is much stronger than the intuitive notion of purity because Julia’s method tables are stateful, so almost any computation you can do is technically impure because it depends on the state of various method tables – e.g. for the `+` or `*` functions. These can be changed and indeed often are. Since there’s no way to seal these method tables (yet), there are very few situations in which no potential future method definition could change the result of a computation – you can redefine something as basic as integer addition, after all. (I don’t recommend it because your program will crash almost immediately, but you can do it.) I’ve proposed that we start referring to this extreme sense of purity as “hyperpure” or something like that, to avoid some of the confusion this terminology has been causing.

---

<div class="post-metadata">

### Author: ![dfdx](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dfdx/32/120_2.png) [@dfdx](https://discourse.julialang.org/u/dfdx)
#### Post date: [February 28, 2017, 11:12pm UTC](https://discourse.julialang.org/t/is-there-a-way-to-tell-if-a-method-is-pure/2355/4 "2017-02-28T23:12:29Z")

</div>

Thanks for the clarification. Do I understand correctly, that even though method tables for some dependencies may change, _at the moment of (pre)compilation_ and with _concrete types_ their state is fully deterministic? E.g. if we compile a function:

```julia
function add(x::Int, y::Int)
    return x + y
end

```

and we know that right now `+` is a normal integer addition, we _can_ infer that this function is really pure? Isn’t it what’s happening in [`pure_eval_call()`](https://github.com/JuliaLang/julia/blob/master/base/inference.jl#L1551-L1580)?
