On Mon, Apr 13 2015, Mauro <[email protected]> wrote:

> Why can you not make it into a function?
>
> function foo!(spec::Symbol, A, i)
>     A[i,spec] = 1
> end
> function foo!{T<:Real}(spec::Vector{(Symbol,T), A, i)
>       @assert(isapprox(sum(map(x -> x[2],spec)),1))
>       for (obs,prob) = spec
>         A[i,obs] = prob
>       end
>     A[i,spec] = 1
> end
> foo!(spec, A, i)  = error(" ...")
>
> that way your code will be cleaner too:
>
> foo!(spec, A, i)

Sure, I can do this, but since foo! would be used in one place only, I
would consider this suboptimal design.

> In Julia, when you use an isa, then ask yourself whether it might not be
> cleaner using methods instead.

I am not sure I understand the reasoning behind this. I find polluting
the namespace with wrapping up trivial code that is used in exactly one
place icky.

Best,

Tamas

Reply via email to