# Writing better / faster / more julia-ish code

**URL:** <https://discourse.julialang.org/t/writing-better-faster-more-julia-ish-code/3269>\
**Category:** General Usage\
**Tags:** macros, reactiveprogramming\
**Created:** [April 18, 2017, 4:57pm UTC](https://discourse.julialang.org/t/writing-better-faster-more-julia-ish-code/3269 "2017-04-18T16:57:43Z")\
**Posts on this page:** 1\
**Showing post:** 3

<div class="post-metadata">

**Author:** ![pyrex41](https://avatars.discourse-cdn.com/v4/letter/p/4bbf92/32.png) [@pyrex41](https://discourse.julialang.org/u/pyrex41)\
**Post date:** [April 18, 2017, 5:42pm UTC](https://discourse.julialang.org/t/writing-better-faster-more-julia-ish-code/3269/3 "2017-04-18T17:42:53Z")

</div>

I did not expect the macro approach to work like this, either; however, I tried this based on [this thread](https://discourse.julialang.org/t/using-gensym-properly/3257/5). To demonstrate:

```julia
ff = Signal(0.0)
gg = @medWin(ff,3)

for i=1:10
    push!(ff, i)
    println("ff is ", ff.value)
    println("gg is ", gg.value)
    println("-----")
end

```

Gives desired output for gg (median of last 3 values of f):

```julia
ff is 1.0
gg is 0.5
-----
ff is 2.0
gg is 1.0
-----
ff is 3.0
gg is 2.0
-----
ff is 4.0
gg is 3.0
-----
ff is 5.0
gg is 4.0
-----
ff is 6.0
gg is 5.0
-----
ff is 7.0
gg is 6.0
-----
ff is 8.0
gg is 7.0
-----
ff is 9.0
gg is 8.0
-----
ff is 10.0
gg is 9.0
-----

```

And, i forgot to include my lastX function:

```julia
function lastX(u::Signal, n ::Int)
    sigs = Array{Signal}(1,n+1)
    sigs[1] = u
    for i=1:n
        sigs[i+1] = previous(sigs[i])
    end
    return zip(sigs[2:end]...)
end

```

---

_[View the full topic](https://discourse.julialang.org/t/writing-better-faster-more-julia-ish-code/3269)._
