# General Usage

**URL:** https://discourse.julialang.org/c/usage/6.md?page=917

[Latest](https://discourse.julialang.org/latest.md) · [Categories](https://discourse.julialang.org/categories.md) · [Tags](https://discourse.julialang.org/tags.md)

**Page:** 918

---

## [Broadcast dot in a normal setfield! - intended behavior or bug?](https://discourse.julialang.org/t/broadcast-dot-in-a-normal-setfield-intended-behavior-or-bug/17707)

<div class="topic-metadata">

**Author:** [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Replies:** 2\
**Last updated:** [November 19, 2018, 12:51pm UTC](https://discourse.julialang.org/t/broadcast-dot-in-a-normal-setfield-intended-behavior-or-bug/17707 "2018-11-19T12:51:05Z")

</div>

This errors in the latest Julia master but worked in Julia 0.6.4. a = \[1, 2\] a\[2\] .= a\[1\] Is this issue-worthy or the intended behavior?

---

## [No automatic conversion with abstract type](https://discourse.julialang.org/t/no-automatic-conversion-with-abstract-type/17710)

<div class="topic-metadata">

**Author:** [@mikolajpp](https://discourse.julialang.org/u/mikolajpp)\
**Replies:** 6\
**Last updated:** [November 19, 2018, 12:40pm UTC](https://discourse.julialang.org/t/no-automatic-conversion-with-abstract-type/17710 "2018-11-19T12:40:41Z")

</div>

I have the following minimal example: abstract type Gate{N} end; struct IdentGate{N} \<: Gate{N} wire::UInt8 function IdentGate{N}(w::Int) where {N} @assert 1 \<= w \<= N new(w) end end GateP…

---

## [Mutate NTuple at position](https://discourse.julialang.org/t/mutate-ntuple-at-position/17682)

<div class="topic-metadata">

**Author:** [@foobar\_lv2](https://discourse.julialang.org/u/foobar_lv2)\
**Replies:** 7\
**Last updated:** [November 19, 2018, 6:49am UTC](https://discourse.julialang.org/t/mutate-ntuple-at-position/17682 "2018-11-19T06:49:21Z")

</div>

I want to switch out an NTuple’s element, like this: julia\> function switch\_k(tup::NTuple{N,T}, elem::T, pos::Integer) where {N,T} #\_assume(0\<pos\<=N) return ntuple(i-\> (pos!==i) ? tup\[i\] : elem ,N) …

---

## [Help reduce large gc time](https://discourse.julialang.org/t/help-reduce-large-gc-time/17215)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 32\
**Last updated:** [November 18, 2018, 6:56am UTC](https://discourse.julialang.org/t/help-reduce-large-gc-time/17215 "2018-11-18T06:56:46Z")

</div>

Hi, In PDMP.jl, I have some large gc time reported. I looked at the performance tips and it seems my code is not type stable. For example, considering the example tcp.jl, I find that pdmp! is not type stable even if th…

---

## [use gdb to debug julia](https://discourse.julialang.org/t/use-gdb-to-debug-julia/17679)

<div class="topic-metadata">

**Author:** [@ralzq01](https://discourse.julialang.org/u/ralzq01)\
**Replies:** 2\
**Last updated:** [November 19, 2018, 6:34am UTC](https://discourse.julialang.org/t/use-gdb-to-debug-julia/17679 "2018-11-19T06:34:07Z")

</div>

Hi, I am trying to use gdb for julia debugging. Although there is a debugging tips, I still can’t find the correct way to use gdb for julia. For example, I want to show values of variable a in gdb for the following t…

---

## [Immutable Data Structures](https://discourse.julialang.org/t/immutable-data-structures/17696)

<div class="topic-metadata">

**Author:** [@Qiyamah](https://discourse.julialang.org/u/Qiyamah)\
**Replies:** 3\
**Last updated:** [November 19, 2018, 6:32am UTC](https://discourse.julialang.org/t/immutable-data-structures/17696 "2018-11-19T06:32:01Z")

</div>

Is there a package which provides this? I don’t want to use push!, I would like to concat and so on Thanks

---

## [Cannot get the NLopt example to work](https://discourse.julialang.org/t/cannot-get-the-nlopt-example-to-work/17539)

<div class="topic-metadata">

**Author:** [@CPPhysics](https://discourse.julialang.org/u/CPPhysics)\
**Replies:** 2\
**Last updated:** [November 18, 2018, 11:05pm UTC](https://discourse.julialang.org/t/cannot-get-the-nlopt-example-to-work/17539 "2018-11-18T23:05:52Z")

</div>

I am trying to get the NLopt main example from the github page to work and I cannot. When I try on julia .6.2 I get this error: type Opt has no field numevals Stacktrace: \[1\] include\_string(::String, ::String) at .\\lo…

---

## [Recursive \`@code\_lowered\`](https://discourse.julialang.org/t/recursive-code-lowered/17638)

<div class="topic-metadata">

**Author:** [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Replies:** 6\
**Last updated:** [November 18, 2018, 9:11pm UTC](https://discourse.julialang.org/t/recursive-code-lowered/17638 "2018-11-18T21:11:15Z")

</div>

We can get IR for a single call using @code\_lowered: foo(x) = x + 1 bar(x) = 2 \* foo(x) @code\_lowered bar(2.0) # CodeInfo( # 1 1 ─ %1 = (Main.foo)(x) │ # │ %2 = 2…

---

## [How to plot histogram based on bin width and bin height?](https://discourse.julialang.org/t/how-to-plot-histogram-based-on-bin-width-and-bin-height/17661)

<div class="topic-metadata">

**Author:** [@jling](https://discourse.julialang.org/u/jling)\
**Replies:** 10\
**Last updated:** [November 18, 2018, 4:42pm UTC](https://discourse.julialang.org/t/how-to-plot-histogram-based-on-bin-width-and-bin-height/17661 "2018-11-18T16:42:02Z")

</div>

e.g: given: Bins: \[0,1), \[1,2) Height: \[3,5\]

---

## [Memrory allocation](https://discourse.julialang.org/t/memrory-allocation/17669)

<div class="topic-metadata">

**Author:** [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Replies:** 7\
**Last updated:** [November 18, 2018, 1:17pm UTC](https://discourse.julialang.org/t/memrory-allocation/17669 "2018-11-18T13:17:45Z")

</div>

Can someone explain why the memory allocation is differnet between foo and foo2 and increased time between foo2(21) and foo2(22). using Distributed,SharedArrays,BenchmarkTools,StatsBase function foo(m::Int64) z = Sh…

---

## [Relative module paths](https://discourse.julialang.org/t/relative-module-paths/17659)

<div class="topic-metadata">

**Author:** [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Replies:** 0\
**Last updated:** [November 17, 2018, 10:09pm UTC](https://discourse.julialang.org/t/relative-module-paths/17659 "2018-11-17T22:09:09Z")

</div>

In t2.jl I can use both import ..MyPkg and import ...MyPkg, is this a feature? It seems to be safe though, because Modules cannot contain modules with the same name. MyPkg ├── Manifest.toml ├── Project.toml └── src …

---

## [Why is multiplication A\*B\*C left-associative (\`foldl\`) not right-associative (\`foldr\`)?](https://discourse.julialang.org/t/why-is-multiplication-a-b-c-left-associative-foldl-not-right-associative-foldr/17552)

<div class="topic-metadata">

**Author:** [@dlfivefifty](https://discourse.julialang.org/u/dlfivefifty)\
**Replies:** 31\
**Last updated:** [November 17, 2018, 7:22pm UTC](https://discourse.julialang.org/t/why-is-multiplication-a-b-c-left-associative-foldl-not-right-associative-foldr/17552 "2018-11-17T19:22:19Z")

</div>

This behaviour is a bit surprising: julia\> A = randn(50,50); x = randn(50); julia\> @btime A\*A\*x; 10.064 μs (3 allocations: 20.17 KiB) julia\> @btime A\*(A\*x); 736.336 ns (2 allocations: 1.06 KiB) julia\> @btime (A\*A…

---

## [Replacement for find(all) on zip?](https://discourse.julialang.org/t/replacement-for-find-all-on-zip/17595)

<div class="topic-metadata">

**Author:** [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Replies:** 8\
**Last updated:** [November 17, 2018, 7:15pm UTC](https://discourse.julialang.org/t/replacement-for-find-all-on-zip/17595 "2018-11-17T19:15:35Z")

</div>

In Julia 0.6, we could to julia\> find(x -\> x\[1\] + x\[2\] \> 0.5, zip(rand(10), rand(10))) However, in Julia v1.0 this doesn’t work, because Base.Iterators.Zip2 has no keys: julia\> findall(x -\> x\[1\] + x\[2\] \> 0.5, zip(rand…

---

## [Type inference: map + accumulate tuple recursively](https://discourse.julialang.org/t/type-inference-map-accumulate-tuple-recursively/17648)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 3\
**Last updated:** [November 17, 2018, 5:27pm UTC](https://discourse.julialang.org/t/type-inference-map-accumulate-tuple-recursively/17648 "2018-11-17T17:27:13Z")

</div>

I have a function f that returns two results: the first one maps the argument to something, the second is a scalar. For the MWE, let f(x::Real) = x + 1, abs2(x) f(x::AbstractArray) = x .+ 1, sum(abs2, x) Please treat t…

---

## [Package for reading/writing ~100GB data files](https://discourse.julialang.org/t/package-for-reading-writing-100gb-data-files/17458)

<div class="topic-metadata">

**Author:** [@Juan](https://discourse.julialang.org/u/Juan)\
**Replies:** 10\
**Last updated:** [November 17, 2018, 1:10pm UTC](https://discourse.julialang.org/t/package-for-reading-writing-100gb-data-files/17458 "2018-11-17T13:10:02Z")

</div>

Then, what is nowadays the fastest package/function/options to read and write say 100GB data with julia? For example with 10000 columns. Each column with all elements of the same type and a header. It would be great to…

---

## [Using functions and types defined in a module, inside a function](https://discourse.julialang.org/t/using-functions-and-types-defined-in-a-module-inside-a-function/17600)

<div class="topic-metadata">

**Author:** [@Ferran\_Mazzanti](https://discourse.julialang.org/u/Ferran_Mazzanti)\
**Replies:** 1\
**Last updated:** [November 17, 2018, 9:05am UTC](https://discourse.julialang.org/t/using-functions-and-types-defined-in-a-module-inside-a-function/17600 "2018-11-17T09:05:12Z")

</div>

Dear all, moving to Julia 0.7/1.0.2 brings in some problems with old code I have. This time I have a user-defined module containing a fcuntion. This module is stored in a separate file MyMod.jl which I can acces as its…

---

## [Reassigning variable in do syntax is not optimized, \`\`Ref\`\` is, what is the difference?](https://discourse.julialang.org/t/reassigning-variable-in-do-syntax-is-not-optimized-ref-is-what-is-the-difference/17635)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 1\
**Last updated:** [November 17, 2018, 9:00am UTC](https://discourse.julialang.org/t/reassigning-variable-in-do-syntax-is-not-optimized-ref-is-what-is-the-difference/17635 "2018-11-17T09:00:53Z")

</div>

I frequently stumble about examples similar to the following, where I have a helper function which supports do style anonymous functions helper(cont, range) = for i ∈ range cont(i) end and want to write something whi…

---

## [UndefVarError: tic not defined](https://discourse.julialang.org/t/undefvarerror-tic-not-defined/17627)

<div class="topic-metadata">

**Author:** [@yuan\_liao](https://discourse.julialang.org/u/yuan_liao)\
**Replies:** 2\
**Last updated:** [November 17, 2018, 12:43am UTC](https://discourse.julialang.org/t/undefvarerror-tic-not-defined/17627 "2018-11-17T00:43:20Z")

</div>

I typed tic() in Julia, and got message: UndefVarError: tic not defined Am I missing any package here?

---

## [Function with arguments of type one/two dim array and a dictionary](https://discourse.julialang.org/t/function-with-arguments-of-type-one-two-dim-array-and-a-dictionary/17605)

<div class="topic-metadata">

**Author:** [@Ajaychat3](https://discourse.julialang.org/u/Ajaychat3)\
**Replies:** 0\
**Last updated:** [November 16, 2018, 5:21pm UTC](https://discourse.julialang.org/t/function-with-arguments-of-type-one-two-dim-array-and-a-dictionary/17605 "2018-11-16T17:21:59Z")

</div>

If I define a function whose two of arguments are of type 2 dimensional array float64 and other of one dim array int64 and also one of the arguments being a dictionary, will it make compilation more efficient if I specif…

---

## [Is this a valid @pure function?](https://discourse.julialang.org/t/is-this-a-valid-pure-function/17577)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 3\
**Last updated:** [November 16, 2018, 4:58pm UTC](https://discourse.julialang.org/t/is-this-a-valid-pure-function/17577 "2018-11-16T16:58:51Z")

</div>

Hi julia pros, is the following function safe to be annotated with @pure? Base.@pure getParameters(t::Type) = Tuple{t.parameters...} it would be soo awesome, because this indeed supports type inference

---

## [Pkg workflow for unregistered packages](https://discourse.julialang.org/t/pkg-workflow-for-unregistered-packages/17385)

<div class="topic-metadata">

**Author:** [@holtri](https://discourse.julialang.org/u/holtri)\
**Replies:** 1\
**Last updated:** [November 16, 2018, 4:07pm UTC](https://discourse.julialang.org/t/pkg-workflow-for-unregistered-packages/17385 "2018-11-16T16:07:10Z")

</div>

Hi, We have upgraded our projects/packages to Julia 1.0. The new Pkg is a well thought-out package manager, and we are currently trying to figure how to best use it in our development workflow. In the following, I descr…

---

## [Garbage collector for string arrays](https://discourse.julialang.org/t/garbage-collector-for-string-arrays/17597)

<div class="topic-metadata">

**Author:** [@hhaensel](https://discourse.julialang.org/u/hhaensel)\
**Replies:** 0\
**Last updated:** [November 16, 2018, 2:54pm UTC](https://discourse.julialang.org/t/garbage-collector-for-string-arrays/17597 "2018-11-16T14:54:58Z")

</div>

I have generated several strings in the C api via jl\_cstr\_to\_string(x) and pushed them to the gc stack. Then I create an array of strings by passing an array of the respective string pointers. Now the critical question…

---

## [When does julia infer optimal code, when not?](https://discourse.julialang.org/t/when-does-julia-infer-optimal-code-when-not/17592)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 4\
**Last updated:** [November 16, 2018, 12:09pm UTC](https://discourse.julialang.org/t/when-does-julia-infer-optimal-code-when-not/17592 "2018-11-16T12:09:32Z")

</div>

Dear julia pros, lets say I have a basic function fn(i::Integer) = 5 which and another function gn(i::Integer) = ... what is all allowed in gn so that @code\_llvm fn(3) @code\_llvm gn(3) return very similar results, i.…

---

## [MethodError](https://discourse.julialang.org/t/methoderror/17555)

<div class="topic-metadata">

**Author:** [@lannisite110](https://discourse.julialang.org/u/lannisite110)\
**Replies:** 3\
**Last updated:** [November 16, 2018, 2:30am UTC](https://discourse.julialang.org/t/methoderror/17555 "2018-11-16T02:30:25Z")

</div>

julia\>xtrnFeatures = zeros(1,1,4096,100); julia\> ypred = forw(:vgg\_model,xtrnZeroPad\[:,:,:,1:100\],weights); julia\> size(ypred) (1, 1, 4096, 100) julia\>typeof(ypred) KnetArray{Float32,4} julia\> xtrnFeatures\[:,:,:,item:ite…

---

## [Unexpected "end"](https://discourse.julialang.org/t/unexpected-end/17579)

<div class="topic-metadata">

**Author:** [@joa-quim](https://discourse.julialang.org/u/joa-quim)\
**Replies:** 3\
**Last updated:** [November 15, 2018, 9:40pm UTC](https://discourse.julialang.org/t/unexpected-end/17579 "2018-11-15T21:40:14Z")

</div>

Is this on purpose? I was clearly expecting that end could be used here. julia\> a=rand(3,3) 3×3 Array{Float64,2}: 0.886505 0.270155 0.912865 0.335745 0.6829 0.402649 0.839621 0.736626 0.174028 julia\> view(a,…

---

## [\`view\` array indexes that vary as a function of another index of that subarray?](https://discourse.julialang.org/t/view-array-indexes-that-vary-as-a-function-of-another-index-of-that-subarray/17531)

<div class="topic-metadata">

**Author:** [@ianshmean](https://discourse.julialang.org/u/ianshmean)\
**Replies:** 3\
**Last updated:** [November 15, 2018, 3:11am UTC](https://discourse.julialang.org/t/view-array-indexes-that-vary-as-a-function-of-another-index-of-that-subarray/17531 "2018-11-15T03:11:13Z")

</div>

In a view is there a way to define an index of an array that varies as a function of another index of that array? i.e. the indexing of dim 1 varies along dim 2. I’d love to avoid making a memory copy of the subarray. M…

---

## [Loading modules at the REPL in 0.7 - is it different?](https://discourse.julialang.org/t/loading-modules-at-the-repl-in-0-7-is-it-different/9190)

<div class="topic-metadata">

**Author:** [@Stephen\_Vavasis](https://discourse.julialang.org/u/Stephen_Vavasis)\
**Replies:** 3\
**Last updated:** [November 15, 2018, 3:22pm UTC](https://discourse.julialang.org/t/loading-modules-at-the-repl-in-0-7-is-it-different/9190 "2018-11-15T15:22:40Z")

</div>

My code is divided into several files, say A.jl, B.jl, C.jl, each of which defines a single module, say A, B, C. Inside C.jl there are declarations like this: import A.myfunction1 import B.myfunction2 In 0.6.2, I was …

---

## [Pkg3 going back to v1.0 environment](https://discourse.julialang.org/t/pkg3-going-back-to-v1-0-environment/17559)

<div class="topic-metadata">

**Author:** [@daniel](https://discourse.julialang.org/u/daniel)\
**Replies:** 2\
**Last updated:** [November 15, 2018, 2:40pm UTC](https://discourse.julialang.org/t/pkg3-going-back-to-v1-0-environment/17559 "2018-11-15T14:40:32Z")

</div>

This is probably an easy question: after activating some environment with \] activate MyPackage, is there any way I can go back to the standard (v1.0) environment? At the moment I’m just restarting the REPL, but I’m sure…

---

## [GraphPlot how to color edges?](https://discourse.julialang.org/t/graphplot-how-to-color-edges/17519)

<div class="topic-metadata">

**Author:** [@Tero\_Frondelius](https://discourse.julialang.org/u/Tero_Frondelius)\
**Replies:** 3\
**Last updated:** [November 15, 2018, 2:30pm UTC](https://discourse.julialang.org/t/graphplot-how-to-color-edges/17519 "2018-11-15T14:30:14Z")

</div>

Dear all, Here is the code that almost works: using LightGraphs using GraphPlot using Colors # nodes membership membership = \[1,1,1,1,1,1,1,1,2,1,1,1,1,1,2,2,1,1,2,1,2,1,2,1,1,1,1,2,1,1,2,1,1,1\] nodecolor = \[colorant"…

---

## [Juno is not picking up JULIA\_DEPOT\_PATH environment variable](https://discourse.julialang.org/t/juno-is-not-picking-up-julia-depot-path-environment-variable/17556)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 2\
**Last updated:** [November 15, 2018, 2:12pm UTC](https://discourse.julialang.org/t/juno-is-not-picking-up-julia-depot-path-environment-variable/17556 "2018-11-15T14:12:18Z")

</div>

I’m on Linux Mint and just installed Atom/Juno afresh. When I open Atom from the menu, it doesn’t pick up the JULIA\_DEPOT\_PATH environment variable. If I open the Juno REPL, it proceeds to install Atom.jl, Juno.jl, etc. …

[Previous page](https://discourse.julialang.org/c/usage/6.md?page=916)

[Next page](https://discourse.julialang.org/c/usage/6.md?page=918)
