# General Usage

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

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

**Page:** 904

---

## [How to dispatch on an array of T or Union{Nothing,T} but not nothing](https://discourse.julialang.org/t/how-to-dispatch-on-an-array-of-t-or-union-nothing-t-but-not-nothing/19504)

<div class="topic-metadata">

**Author:** [@ndinsmore](https://discourse.julialang.org/u/ndinsmore)\
**Replies:** 3\
**Last updated:** [January 11, 2019, 1:26pm UTC](https://discourse.julialang.org/t/how-to-dispatch-on-an-array-of-t-or-union-nothing-t-but-not-nothing/19504 "2019-01-11T13:26:14Z")

</div>

I am looking for a concise way to match an AbstractArray of T or Union{Nothing,T} but not Nothing. Does anyone have any ideas how to do that? The general test I have been using is the following, with the ideal result be…

---

## [Comparison performance with \`any\`](https://discourse.julialang.org/t/comparison-performance-with-any/19478)

<div class="topic-metadata">

**Author:** [@MLackner](https://discourse.julialang.org/u/MLackner)\
**Replies:** 5\
**Last updated:** [January 11, 2019, 11:20am UTC](https://discourse.julialang.org/t/comparison-performance-with-any/19478 "2019-01-11T11:20:43Z")

</div>

Hey! How can I prevent this loop from allocating memory on every iteration? If I interchange @view b\[i-1:i\] with just b the loop does not allocate but that’s not what I want :wink:. I don’t really understand this behav…

---

## [Nested functions pros and cons](https://discourse.julialang.org/t/nested-functions-pros-and-cons/19417)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 24\
**Last updated:** [January 11, 2019, 11:08am UTC](https://discourse.julialang.org/t/nested-functions-pros-and-cons/19417 "2019-01-11T11:08:40Z")

</div>

I’ve learned that nested functions are useful in Matlab to avoid passing tons of arguments to external functions when optimizing/fitting some data. Is this still true in Julia? Since lambda functions are very cheap, is …

---

## [Stack overflow from unexpected mutual constructor recursion on type alias](https://discourse.julialang.org/t/stack-overflow-from-unexpected-mutual-constructor-recursion-on-type-alias/19495)

<div class="topic-metadata">

**Author:** [@andyljones](https://discourse.julialang.org/u/andyljones)\
**Replies:** 8\
**Last updated:** [January 11, 2019, 10:04am UTC](https://discourse.julialang.org/t/stack-overflow-from-unexpected-mutual-constructor-recursion-on-type-alias/19495 "2019-01-11T10:04:23Z")

</div>

Define using DataStructures const Bar = OrderedDict{Int64, Int64} Bar() = Bar(1=\>2, 2=\>3) Then calling Bar() gets me \*\*ERROR:\*\* StackOverflowError: Stacktrace: \[1\] \*\*OrderedDict{Int64,Int64}()\*\* at \*\*./REPL\[3\]:1\*\* \[…

---

## [Adding data to worker processes via @everywhere](https://discourse.julialang.org/t/adding-data-to-worker-processes-via-everywhere/19410)

<div class="topic-metadata">

**Author:** [@colintbowers](https://discourse.julialang.org/u/colintbowers)\
**Replies:** 12\
**Last updated:** [January 11, 2019, 2:53am UTC](https://discourse.julialang.org/t/adding-data-to-worker-processes-via-everywhere/19410 "2019-01-11T02:53:33Z")

</div>

Hi all, I know next to nothing about parallel processing, so apologies if this question is obvious. I start julia with julia -p 2. Here is a broken simplified version of what my code does: d = read(some\_filepath) # d i…

---

## [Base.whos() no longer works in 1.0](https://discourse.julialang.org/t/base-whos-no-longer-works-in-1-0/19475)

<div class="topic-metadata">

**Author:** [@gatohaus](https://discourse.julialang.org/u/gatohaus)\
**Replies:** 5\
**Last updated:** [January 11, 2019, 12:55am UTC](https://discourse.julialang.org/t/base-whos-no-longer-works-in-1-0/19475 "2019-01-11T00:55:51Z")

</div>

We’ve recently upgraded from 0.6 to 1.0 and have found that whos() seems to have gone away. Can someone please verify that this is true? What has replaced it? Thanks. -David whos() error base.whos invalid whos() …

---

## [Is there a central difference/gradient function somewhere?](https://discourse.julialang.org/t/is-there-a-central-difference-gradient-function-somewhere/19454)

<div class="topic-metadata">

**Author:** [@weech](https://discourse.julialang.org/u/weech)\
**Replies:** 12\
**Last updated:** [January 10, 2019, 6:51pm UTC](https://discourse.julialang.org/t/is-there-a-central-difference-gradient-function-somewhere/19454 "2019-01-10T18:51:47Z")

</div>

When I write in Python, I often use the gradient function from NumPy, and, when I write in NCL, I often use the center\_finite\_diff\_n function. However, it looks like Julia does not have a function that has a behavior sim…

---

## [DataFrame display in IJulia](https://discourse.julialang.org/t/dataframe-display-in-ijulia/19442)

<div class="topic-metadata">

**Author:** [@AsafManela](https://discourse.julialang.org/u/AsafManela)\
**Replies:** 3\
**Last updated:** [January 10, 2019, 2:29pm UTC](https://discourse.julialang.org/t/dataframe-display-in-ijulia/19442 "2019-01-10T14:29:08Z")

</div>

Is there an easy way, like an environment variable or a function I can override to avoid displaying the column types and row numbers of DataFrames in IJulia? When I try this DataFrame(a=\[1,2\], b=\["3", "4"\]) I get 2 …

---

## [ERROR: LoadError: IOError: chdir /buildworker/worker/package\_linux64/build/usr/share/julia/stdlib/v1.0/Sockets/src: no such file or directory (ENOENT)](https://discourse.julialang.org/t/error-loaderror-ioerror-chdir-buildworker-worker-package-linux64-build-usr-share-julia-stdlib-v1-0-sockets-src-no-such-file-or-directory-enoent/19414)

<div class="topic-metadata">

**Author:** [@scelles](https://discourse.julialang.org/u/scelles)\
**Replies:** 2\
**Last updated:** [January 10, 2019, 11:49am UTC](https://discourse.julialang.org/t/error-loaderror-ioerror-chdir-buildworker-worker-package-linux64-build-usr-share-julia-stdlib-v1-0-sockets-src-no-such-file-or-directory-enoent/19414 "2019-01-10T11:49:17Z")

</div>

Hello, I’m trying to publish doc to Github page (compiling doc locally is working fine) for Doc should be available at http://scls19fr.github.io/Nextion.jl/latest but I’m facing this error: ERROR: LoadError: IOErro…

---

## [Rank is wrong for Rational matrices](https://discourse.julialang.org/t/rank-is-wrong-for-rational-matrices/19380)

<div class="topic-metadata">

**Author:** [@Jean\_Michel](https://discourse.julialang.org/u/Jean_Michel)\
**Replies:** 19\
**Last updated:** [January 10, 2019, 10:58am UTC](https://discourse.julialang.org/t/rank-is-wrong-for-rational-matrices/19380 "2019-01-10T10:58:05Z")

</div>

consider the matrix: julia\> m=\[1//(n+m) for n in 1:11, m in 1:11\]; it can be inverted exactly with no problem: julia\> one(m)==inv(m)\*m true however: julia\> rank(m) 10 The reason is that rank begins by converting it…

---

## [Get module of a caller](https://discourse.julialang.org/t/get-module-of-a-caller/11445)

<div class="topic-metadata">

**Author:** [@dfdx](https://discourse.julialang.org/u/dfdx)\
**Replies:** 4\
**Last updated:** [January 10, 2019, 9:15am UTC](https://discourse.julialang.org/t/get-module-of-a-caller/11445 "2019-01-10T09:15:55Z")

</div>

module A foo(???) = println("I've been called from $???") end module B import A A.foo() # should pring "I've been called from B" end Is it possible to get this behavior, i.e. find out the caller’s module w…

---

## [How to shift bits faster](https://discourse.julialang.org/t/how-to-shift-bits-faster/19405)

<div class="topic-metadata">

**Author:** [@bennedich](https://discourse.julialang.org/u/bennedich)\
**Replies:** 8\
**Last updated:** [January 10, 2019, 7:42am UTC](https://discourse.julialang.org/t/how-to-shift-bits-faster/19405 "2019-01-10T07:42:16Z")

</div>

I thought I’d share something that I’ve run into before, and that I’ve seen a couple of times now on this forum (most recently in this topic). If you want to shift the integer n to the left or right by k bits, the natur…

---

## [Help resolving Dict access type inference](https://discourse.julialang.org/t/help-resolving-dict-access-type-inference/19452)

<div class="topic-metadata">

**Author:** [@jackf](https://discourse.julialang.org/u/jackf)\
**Replies:** 9\
**Last updated:** [January 10, 2019, 4:41am UTC](https://discourse.julialang.org/t/help-resolving-dict-access-type-inference/19452 "2019-01-10T04:41:26Z")

</div>

I have some code that starts with a loosely type Dict (e.g. something returned from a web service). I want to write a function that will extract a certain key from it, convert that key into a concretely-typed array (Arra…

---

## [Efficient looping statement in Julia](https://discourse.julialang.org/t/efficient-looping-statement-in-julia/19420)

<div class="topic-metadata">

**Author:** [@chuljang](https://discourse.julialang.org/u/chuljang)\
**Replies:** 15\
**Last updated:** [January 10, 2019, 1:04am UTC](https://discourse.julialang.org/t/efficient-looping-statement-in-julia/19420 "2019-01-10T01:04:15Z")

</div>

Happy new year to all. I have a quick question about writing effcient looping code. To describe a problem, let me use a simple for looping statement which check if a number is even and store that number into an array (r…

---

## [Sum statistic over a day](https://discourse.julialang.org/t/sum-statistic-over-a-day/19409)

<div class="topic-metadata">

**Author:** [@natemcintosh](https://discourse.julialang.org/u/natemcintosh)\
**Replies:** 2\
**Last updated:** [January 10, 2019, 12:06am UTC](https://discourse.julialang.org/t/sum-statistic-over-a-day/19409 "2019-01-10T00:06:18Z")

</div>

I have a DataFrame as such │ Row │ start │ finish │ cals │ DOW │ │ │ DateTime │ DateTime │ Float64 │ Int64 │ ├─────┼─────────────────────┼─────────────────────┼─…

---

## [Is \`Pkg.precompile()\` missing on purpose?](https://discourse.julialang.org/t/is-pkg-precompile-missing-on-purpose/19456)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 2\
**Last updated:** [January 9, 2019, 11:10pm UTC](https://discourse.julialang.org/t/is-pkg-precompile-missing-on-purpose/19456 "2019-01-09T23:10:11Z")

</div>

I’d like to do the equivalent of \] precompile but from a script, however Pkg.precompile() does not seem to exist. Is this intentional, and is there a way to accomplish this from a script? Thanks.

---

## [Help: macro expander not gensyming local variables in returned function expr if signature is escaped](https://discourse.julialang.org/t/help-macro-expander-not-gensyming-local-variables-in-returned-function-expr-if-signature-is-escaped/19446)

<div class="topic-metadata">

**Author:** [@NHDaly](https://discourse.julialang.org/u/NHDaly)\
**Replies:** 9\
**Last updated:** [January 9, 2019, 9:35pm UTC](https://discourse.julialang.org/t/help-macro-expander-not-gensyming-local-variables-in-returned-function-expr-if-signature-is-escaped/19446 "2019-01-09T21:35:07Z")

</div>

Hey, can anyone help with this macro expansion not working like I expect? It’s not gensyming the local variables in a function body if the function’s signature is escaped. Anyone seen this before? …

---

## [Unit-test mapping/layout convention/style-guide](https://discourse.julialang.org/t/unit-test-mapping-layout-convention-style-guide/19316)

<div class="topic-metadata">

**Author:** [@taqtiqa-mark](https://discourse.julialang.org/u/taqtiqa-mark)\
**Replies:** 17\
**Last updated:** [January 9, 2019, 9:08pm UTC](https://discourse.julialang.org/t/unit-test-mapping-layout-convention-style-guide/19316 "2019-01-09T21:08:43Z")

</div>

Hi, As I’ve been working through some of the Base, Core and Julia packages, I’ve noted that the src-test mapping/layout conventions (or lack of), more often than not, increase the burden of exploring Julia and most Juli…

---

## [Write bytes of object to io](https://discourse.julialang.org/t/write-bytes-of-object-to-io/19444)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 5\
**Last updated:** [January 9, 2019, 8:23pm UTC](https://discourse.julialang.org/t/write-bytes-of-object-to-io/19444 "2019-01-09T20:23:10Z")

</div>

I can read a struct from its bytes from an IO like so: julia\> struct MyInt; data::Int; end julia\> io = IOBuffer(); write(io, 42); seekstart(io) IOBuffer(data=UInt8\[...\], readable=true, writable=true, seekable=true, app…

---

## [\`fft(v)\` fails for subtypes of \`AbstractArray{\<:Complex}\`](https://discourse.julialang.org/t/fft-v-fails-for-subtypes-of-abstractarray-complex/19404)

<div class="topic-metadata">

**Author:** [@raminammour](https://discourse.julialang.org/u/raminammour)\
**Replies:** 2\
**Last updated:** [January 9, 2019, 5:30pm UTC](https://discourse.julialang.org/t/fft-v-fails-for-subtypes-of-abstractarray-complex/19404 "2019-01-09T17:30:36Z")

</div>

Hello, I think this is a bug: struct wrap{T,N} \<: AbstractArray{T,N} v::Array{T,N} end Base.size(w::wrap)=size(w.v) Base.getindex(w::wrap,i)=getindex(w.v,i) Base.setindex!(w::wrap,i,v)=setindex!(w.v,i,v) wwr=wrap(…

---

## [Append struct element to an array](https://discourse.julialang.org/t/append-struct-element-to-an-array/19439)

<div class="topic-metadata">

**Author:** [@algebrato](https://discourse.julialang.org/u/algebrato)\
**Replies:** 1\
**Last updated:** [January 9, 2019, 4:43pm UTC](https://discourse.julialang.org/t/append-struct-element-to-an-array/19439 "2019-01-09T16:43:47Z")

</div>

Hello, I am a newbie programmer in Julia, and I can not explain a bizarre behavior of the append command. I have a structure define as struct Point{T} x::T y::T z::T end and an array of points: points = \[Poi…

---

## [Setting path for Julia config dir?](https://discourse.julialang.org/t/setting-path-for-julia-config-dir/19418)

<div class="topic-metadata">

**Author:** [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Replies:** 2\
**Last updated:** [January 9, 2019, 3:03pm UTC](https://discourse.julialang.org/t/setting-path-for-julia-config-dir/19418 "2019-01-09T15:03:49Z")

</div>

Is there a way to redirect “~/.julia/config” to another directory via an envionment variable? I didn’t see anything in Environment Variables · The Julia Language for config, but it’s possible to redirect everything else …

---

## [Promote parametric type in repeat](https://discourse.julialang.org/t/promote-parametric-type-in-repeat/19323)

<div class="topic-metadata">

**Author:** [@kellertuer](https://discourse.julialang.org/u/kellertuer)\
**Replies:** 2\
**Last updated:** [January 9, 2019, 12:54pm UTC](https://discourse.julialang.org/t/promote-parametric-type-in-repeat/19323 "2019-01-09T12:54:52Z")

</div>

Just for laziness I would like to implement a repeat function for my own parametric type. For example, consider the following example, where A1 might even be used recursively (i.e. Arrays of Arrays) and I would like to d…

---

## [Struct vs primitive type?](https://discourse.julialang.org/t/struct-vs-primitive-type/19422)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 1\
**Last updated:** [January 9, 2019, 12:31pm UTC](https://discourse.julialang.org/t/struct-vs-primitive-type/19422 "2019-01-09T12:31:33Z")

</div>

When should I use primitive types over structs and why? Here is a concrete example: I am working with a C code and there is a UInt32 called LATCH that is interpreted in fancy ways. E.g. so me of its bits are flags and …

---

## [Precompilation or sysimg building not working as expected](https://discourse.julialang.org/t/precompilation-or-sysimg-building-not-working-as-expected/1399)

<div class="topic-metadata">

**Author:** [@jminardi](https://discourse.julialang.org/u/jminardi)\
**Replies:** 10\
**Last updated:** [January 8, 2019, 8:43pm UTC](https://discourse.julialang.org/t/precompilation-or-sysimg-building-not-working-as-expected/1399 "2019-01-08T20:43:36Z")

</div>

Our company has a medium size Julia app that we run from the command line. Because every time we run we start a new julia instance we have a good amount of overheard in loading the libraries we use and priming the JIT co…

---

## [Performance of type-stable fields in structs](https://discourse.julialang.org/t/performance-of-type-stable-fields-in-structs/19348)

<div class="topic-metadata">

**Author:** [@Ferran\_Mazzanti](https://discourse.julialang.org/u/Ferran_Mazzanti)\
**Replies:** 16\
**Last updated:** [January 8, 2019, 4:07pm UTC](https://discourse.julialang.org/t/performance-of-type-stable-fields-in-structs/19348 "2019-01-08T16:07:10Z")

</div>

Hi, just a quick question because I do not have this point very clear. That is related to the performance of type-stable against type-unstable fields in structs. For instance consider mutable struct croco x :: Int64 …

---

## [Logs on depot path](https://discourse.julialang.org/t/logs-on-depot-path/19383)

<div class="topic-metadata">

**Author:** [@madprogrammer](https://discourse.julialang.org/u/madprogrammer)\
**Replies:** 0\
**Last updated:** [January 8, 2019, 1:19pm UTC](https://discourse.julialang.org/t/logs-on-depot-path/19383 "2019-01-08T13:19:21Z")

</div>

Is it possible to change the logs from depot path to another location?

---

## [Package Manager and Registries](https://discourse.julialang.org/t/package-manager-and-registries/19382)

<div class="topic-metadata">

**Author:** [@madprogrammer](https://discourse.julialang.org/u/madprogrammer)\
**Replies:** 0\
**Last updated:** [January 8, 2019, 1:17pm UTC](https://discourse.julialang.org/t/package-manager-and-registries/19382 "2019-01-08T13:17:04Z")

</div>

Hi. Let’s say I want to add a package which is already installed, because I want to run using Package. At the same time I have no interest in updating packages or the registries for a while. Is there any way I can do t…

---

## [Including modules in Julia v0.7](https://discourse.julialang.org/t/including-modules-in-julia-v0-7/12559)

<div class="topic-metadata">

**Author:** [@migarstka](https://discourse.julialang.org/u/migarstka)\
**Replies:** 8\
**Last updated:** [January 8, 2019, 1:03pm UTC](https://discourse.julialang.org/t/including-modules-in-julia-v0-7/12559 "2019-01-08T13:03:16Z")

</div>

I am trying to update some of my code to make it work with Julia v0.7.0-beta2.0. I am a bit confused about what is the right way to include a bunch of modules that refer to each other. Assume I have three files that ea…

---

## [AOT compiled hello.jl core dump](https://discourse.julialang.org/t/aot-compiled-hello-jl-core-dump/19318)

<div class="topic-metadata">

**Author:** [@LeoK987](https://discourse.julialang.org/u/LeoK987)\
**Replies:** 18\
**Last updated:** [January 8, 2019, 12:06pm UTC](https://discourse.julialang.org/t/aot-compiled-hello-jl-core-dump/19318 "2019-01-08T12:06:04Z")

</div>

Compiled through, but execution got core dump. Any idea? $ julia \_ \_ \_ \_(\_)\_ | Documentation: https://docs.julialang.org (\_) | (\_) (\_) | \_ \_ \_| |\_ \_\_ \_ | Type "?" for help…

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

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