# General Usage

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

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

**Page:** 1040

---

## [Warning: VSCode formatter shredders code!](https://discourse.julialang.org/t/warning-vscode-formatter-shredders-code/4663)

<div class="topic-metadata">

**Author:** [@leiteiro](https://discourse.julialang.org/u/leiteiro)\
**Replies:** 3\
**Last updated:** [July 5, 2017, 8:17pm UTC](https://discourse.julialang.org/t/warning-vscode-formatter-shredders-code/4663 "2017-07-05T20:17:12Z")

</div>

I used Visual Studio Code 1.13.1 on Windows10 and Julia v0.6 to shredder my code. And this is how you do it: Right click, format document. Before: function f(len::Int) R = Array{Int}(len) a = c+d R end After…

---

## [Memory and composition](https://discourse.julialang.org/t/memory-and-composition/4633)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 16\
**Last updated:** [July 5, 2017, 11:01am UTC](https://discourse.julialang.org/t/memory-and-composition/4633 "2017-07-05T11:01:35Z")

</div>

If I have a struct that has another struct as a field, is the latter always copied as a whole? Eg struct Large a::Int b::Int c::Int end struct UsesLarge l::Large d::Int end l = Large(1,2,3) sizeof(…

---

## [Right way of using DistributedArrays](https://discourse.julialang.org/t/right-way-of-using-distributedarrays/4657)

<div class="topic-metadata">

**Author:** [@rveltz](https://discourse.julialang.org/u/rveltz)\
**Replies:** 0\
**Last updated:** [July 5, 2017, 7:16am UTC](https://discourse.julialang.org/t/right-way-of-using-distributedarrays/4657 "2017-07-05T07:16:42Z")

</div>

Hi, I want to apply an inplace function foo! to a vector of elements of type lT. I want this operation to be done in parallel (distributed) because this vector is big. Is the following prototype the right way to do it? …

---

## [Generating for loops with macros](https://discourse.julialang.org/t/generating-for-loops-with-macros/4654)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 1\
**Last updated:** [July 5, 2017, 4:03am UTC](https://discourse.julialang.org/t/generating-for-loops-with-macros/4654 "2017-07-05T04:03:09Z")

</div>

I am having difficulty trying to write a macro that takes a vector of types, defines 3 input parameters for the constructor of each type, loops over different values of the parameters and instantiates the types inside of…

---

## [The update from 0.5 to 0.6 does not seem to happen](https://discourse.julialang.org/t/the-update-from-0-5-to-0-6-does-not-seem-to-happen/4622)

<div class="topic-metadata">

**Author:** [@Jean-Victor](https://discourse.julialang.org/u/Jean-Victor)\
**Replies:** 21\
**Last updated:** [July 5, 2017, 1:25am UTC](https://discourse.julialang.org/t/the-update-from-0-5-to-0-6-does-not-seem-to-happen/4622 "2017-07-05T01:25:15Z")

</div>

I am using Atom and I have updated Julia, or so I thought, from version 0.5 to version 0.6, but when I open the Julia terminal, the version shown is 0.5.2. Also, Atom fetches everything from a subdirectory labeled 0.5, n…

---

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

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Replies:** 12\
**Last updated:** [July 4, 2017, 11:31pm UTC](https://discourse.julialang.org/t/undefvarerror-imshow-not-defined/4616 "2017-07-04T23:31:14Z")

</div>

I’m having problems with a simple demo using JuliaImages. Here is what I get with Julia 0.5.2 and Jupyter: Pkg.status("Images") Pkg.status("TestImages") Pkg.status("ImageView") using TestImages, Images, ImageView img =…

---

## [Can't chop using SymPy in Julia](https://discourse.julialang.org/t/cant-chop-using-sympy-in-julia/3487)

<div class="topic-metadata">

**Author:** [@cserteGT3](https://discourse.julialang.org/u/cserteGT3)\
**Replies:** 9\
**Last updated:** [July 4, 2017, 9:34pm UTC](https://discourse.julialang.org/t/cant-chop-using-sympy-in-julia/3487 "2017-07-04T21:34:53Z")

</div>

I’m using SymPy in Julia and can’t use the chop function. As a result of my calculations I have a number like 20.663702825333246 + 2.6469779601696886e-23im If I try to: chop(ans) I get this error: MethodError: …

---

## [Map a scalar function over collection of arrays](https://discourse.julialang.org/t/map-a-scalar-function-over-collection-of-arrays/4634)

<div class="topic-metadata">

**Author:** [@mauro3](https://discourse.julialang.org/u/mauro3)\
**Replies:** 3\
**Last updated:** [July 4, 2017, 6:49pm UTC](https://discourse.julialang.org/t/map-a-scalar-function-over-collection-of-arrays/4634 "2017-07-04T18:49:01Z")

</div>

In Julia map(rad2deg, (\[1\],\[2\]) ) works. In 0.6 is is deprecated: julia\> map(rad2deg, (\[1\], \[2\])) WARNING: rad2deg…

---

## [Warning: deprecated syntax .+?](https://discourse.julialang.org/t/warning-deprecated-syntax/4645)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 13\
**Last updated:** [July 4, 2017, 6:16pm UTC](https://discourse.julialang.org/t/warning-deprecated-syntax/4645 "2017-07-04T18:16:46Z")

</div>

Recently, I noticed this warning on my Travis builds Julia v0.6: WARNING: deprecated syntax “function .+(…)”. Use “function Base.broadcast(::typeof(+), …)” instead. Can you please confirm the dot notation is not dep…

---

## [Remote SharedArray problems](https://discourse.julialang.org/t/remote-sharedarray-problems/4579)

<div class="topic-metadata">

**Author:** [@alha02](https://discourse.julialang.org/u/alha02)\
**Replies:** 4\
**Last updated:** [July 4, 2017, 4:57pm UTC](https://discourse.julialang.org/t/remote-sharedarray-problems/4579 "2017-07-04T16:57:54Z")

</div>

I am trying to run this example but I get the following: julia\> remotes = addprocs(\[("user@remote\_host", 4)\]) 4-element Array{Int64,1}: 2 3 4 5 julia\> S = SharedArray{Int}((3,4), init = S -\> S\[localindexes(S)\] = my…

---

## [PROBLEMS WITH BuildExecutable in linux ubuntu](https://discourse.julialang.org/t/problems-with-buildexecutable-in-linux-ubuntu/4612)

<div class="topic-metadata">

**Author:** [@flomenbom](https://discourse.julialang.org/u/flomenbom)\
**Replies:** 6\
**Last updated:** [July 4, 2017, 3:11pm UTC](https://discourse.julialang.org/t/problems-with-buildexecutable-in-linux-ubuntu/4612 "2017-07-04T15:11:04Z")

</div>

There is a problem with missing \<julia.h\> file when running build\_executable(“test”,file\_main,taget,“natove”,force=true) The file exist in the /julia/src/ folder yet the command (through the file start\_func.c) look f…

---

## [Stack multidimensional Array](https://discourse.julialang.org/t/stack-multidimensional-array/4632)

<div class="topic-metadata">

**Author:** [@Saran\_S](https://discourse.julialang.org/u/Saran_S)\
**Replies:** 5\
**Last updated:** [July 4, 2017, 12:36pm UTC](https://discourse.julialang.org/t/stack-multidimensional-array/4632 "2017-07-04T12:36:30Z")

</div>

Hello, I would like to know if there is better way to stack multidimensional array like vcat Below is the code which i am working with. data1 = rand(10000,3072); data2 = rand(10000,3072); data3 = rand(10000,3072); data…

---

## [Goto definition for struct declarations](https://discourse.julialang.org/t/goto-definition-for-struct-declarations/4639)

<div class="topic-metadata">

**Author:** [@TsurHerman](https://discourse.julialang.org/u/TsurHerman)\
**Replies:** 0\
**Last updated:** [July 4, 2017, 11:31am UTC](https://discourse.julialang.org/t/goto-definition-for-struct-declarations/4639 "2017-07-04T11:31:53Z")

</div>

Is there a way to tell where a certain type was first declared , similar to the data I can get for functions?

---

## [Lazy broadcast Nullable](https://discourse.julialang.org/t/lazy-broadcast-nullable/4596)

<div class="topic-metadata">

**Author:** [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Replies:** 10\
**Last updated:** [July 4, 2017, 9:49am UTC](https://discourse.julialang.org/t/lazy-broadcast-nullable/4596 "2017-07-04T09:49:38Z")

</div>

I could express a certain class computation with variations on composing small but occasionally expensive functions. Sometimes the functions produce Nullables, in which case I want computation to short-circuit and not co…

---

## [Using remote workers on Linux from Mac OS master](https://discourse.julialang.org/t/using-remote-workers-on-linux-from-mac-os-master/4395)

<div class="topic-metadata">

**Author:** [@ilya](https://discourse.julialang.org/u/ilya)\
**Replies:** 0\
**Last updated:** [June 21, 2017, 7:43pm UTC](https://discourse.julialang.org/t/using-remote-workers-on-linux-from-mac-os-master/4395 "2017-06-21T19:43:01Z")

</div>

I would like to run a master Julia process on a laptop with Mac OS (ideally as a jupyter notebook) and have the work done by remote processes on a cluster of Linux nodes. Or, to be more generic, to have a notebook in the…

---

## [Optional arguments in Julia v0.6](https://discourse.julialang.org/t/optional-arguments-in-julia-v0-6/4630)

<div class="topic-metadata">

**Author:** [@juliohm](https://discourse.julialang.org/u/juliohm)\
**Replies:** 5\
**Last updated:** [July 4, 2017, 4:16am UTC](https://discourse.julialang.org/t/optional-arguments-in-julia-v0-6/4630 "2017-07-04T04:16:03Z")

</div>

Is there any trick to handle optional arguments in Julia? Sometimes I want to setup some of the arguments of a function for the user, however; this setup is not necessarily straightforward that I could just pass a defaul…

---

## [Unable to load pickle data](https://discourse.julialang.org/t/unable-to-load-pickle-data/4620)

<div class="topic-metadata">

**Author:** [@Saran\_S](https://discourse.julialang.org/u/Saran_S)\
**Replies:** 8\
**Last updated:** [July 3, 2017, 5:22pm UTC](https://discourse.julialang.org/t/unable-to-load-pickle-data/4620 "2017-07-03T17:22:55Z")

</div>

Hello, I am trying to load python pickle object. I keep getting the below error message and I am unable to resolve the issue. The data which i am trying to load is CIFAR10 Dataset. Below is my code with which i am tryin…

---

## [Using \`@allocated\` to track memory allocations](https://discourse.julialang.org/t/using-allocated-to-track-memory-allocations/4617)

<div class="topic-metadata">

**Author:** [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Replies:** 7\
**Last updated:** [July 3, 2017, 3:45pm UTC](https://discourse.julialang.org/t/using-allocated-to-track-memory-allocations/4617 "2017-07-03T15:45:37Z")

</div>

I am having a hard time understanding allocation in some code I have. The minimal example is the code below: function foo(c) v = c \* 1 v end c = 1.0 @show @allocated foo(c) @show @allocated foo(c) @show @alloc…

---

## [Trouble understanding macros: creating a struct on the fly](https://discourse.julialang.org/t/trouble-understanding-macros-creating-a-struct-on-the-fly/4576)

<div class="topic-metadata">

**Author:** [@JonathanAnderson](https://discourse.julialang.org/u/JonathanAnderson)\
**Replies:** 7\
**Last updated:** [July 3, 2017, 3:21pm UTC](https://discourse.julialang.org/t/trouble-understanding-macros-creating-a-struct-on-the-fly/4576 "2017-07-03T15:21:39Z")

</div>

I’m trying to create a macro that will help me build structs from a schema defined in a JSON document and while I have something that works, I would love a code review so I can learn how to do it better… macro make\_stru…

---

## [Allocation using broadcasting with custom type](https://discourse.julialang.org/t/allocation-using-broadcasting-with-custom-type/4592)

<div class="topic-metadata">

**Author:** [@gasagna](https://discourse.julialang.org/u/gasagna)\
**Replies:** 7\
**Last updated:** [July 3, 2017, 1:56pm UTC](https://discourse.julialang.org/t/allocation-using-broadcasting-with-custom-type/4592 "2017-07-03T13:56:55Z")

</div>

Hi, I am seeing some suspect allocations using broadcasting defined on a custom type, in particular when the broadcast involves Numbers. The MWE is reported below. My actual code is somewhat larger but this example repr…

---

## [Writing DataFrame with no quotemarks](https://discourse.julialang.org/t/writing-dataframe-with-no-quotemarks/4599)

<div class="topic-metadata">

**Author:** [@pauljurczak](https://discourse.julialang.org/u/pauljurczak)\
**Replies:** 7\
**Last updated:** [July 3, 2017, 12:49pm UTC](https://discourse.julialang.org/t/writing-dataframe-with-no-quotemarks/4599 "2017-07-03T12:49:29Z")

</div>

Function writetable requires a quotemark character. Is there a direct way to write a DataFrame to CSV file without any quotemarks?

---

## [Cumbersome scoping rules for try - catch - finally](https://discourse.julialang.org/t/cumbersome-scoping-rules-for-try-catch-finally/4582)

<div class="topic-metadata">

**Author:** [@essenciary](https://discourse.julialang.org/u/essenciary)\
**Replies:** 10\
**Last updated:** [July 3, 2017, 11:20am UTC](https://discourse.julialang.org/t/cumbersome-scoping-rules-for-try-catch-finally/4582 "2017-07-03T11:20:36Z")

</div>

I just had to implement the following logic: 1 - connect to DB (with potential error) 2 - run query (with potential error) 3 - return query result 4 - make sure the connection is closed The most concise way to write…

---

## [How Base.invokelatest invoke a function with keyword parameters?](https://discourse.julialang.org/t/how-base-invokelatest-invoke-a-function-with-keyword-parameters/4610)

<div class="topic-metadata">

**Author:** [@Jieyi\_Xiong](https://discourse.julialang.org/u/Jieyi_Xiong)\
**Replies:** 1\
**Last updated:** [July 3, 2017, 8:28am UTC](https://discourse.julialang.org/t/how-base-invokelatest-invoke-a-function-with-keyword-parameters/4610 "2017-07-03T08:28:39Z")

</div>

julia\> function tryeval() @eval newfun(;kw="default") = uppercase(kw) Base.invokelatest(newfun,kw="abc") end tryeval (generic function with 1 method) julia\> tryeval() ERROR: function invokel…

---

## [Augmenting a function](https://discourse.julialang.org/t/augmenting-a-function/4585)

<div class="topic-metadata">

**Author:** [@cstjean](https://discourse.julialang.org/u/cstjean)\
**Replies:** 9\
**Last updated:** [July 2, 2017, 1:07am UTC](https://discourse.julialang.org/t/augmenting-a-function/4585 "2017-07-02T01:07:57Z")

</div>

Say I wanted to write a classical (non-sampling) profiler. In Lisp/Python, I can replace any to-be-profiled function F with a function F’ that takes note of the time, calls F, then takes note of the time again. Something…

---

## [Cost of checking if statements in type parameters in a big loop and generated functions](https://discourse.julialang.org/t/cost-of-checking-if-statements-in-type-parameters-in-a-big-loop-and-generated-functions/4588)

<div class="topic-metadata">

**Author:** [@mohamed82008](https://discourse.julialang.org/u/mohamed82008)\
**Replies:** 8\
**Last updated:** [July 2, 2017, 12:31am UTC](https://discourse.julialang.org/t/cost-of-checking-if-statements-in-type-parameters-in-a-big-loop-and-generated-functions/4588 "2017-07-02T00:31:05Z")

</div>

I am curious as to how Julia’s compiler handles if statements in type parameters. Does it select one specific branch based on the arguments which will always be true as the type parameter is constant, or does it keep che…

---

## [Slow Newton method](https://discourse.julialang.org/t/slow-newton-method/4590)

<div class="topic-metadata">

**Author:** [@barche](https://discourse.julialang.org/u/barche)\
**Replies:** 1\
**Last updated:** [July 2, 2017, 12:02am UTC](https://discourse.julialang.org/t/slow-newton-method/4590 "2017-07-02T00:02:49Z")

</div>

The following code, based on @dpsanders 's hands-on Julia example seems to allocate much more than necessary, and is a lot slower as a result: newton(f, f′, x) = x - f(x) / f′(x) function do\_newton(g, g′, x0) x = x…

---

## [How to tell BinDeps I don't have permission for package installer](https://discourse.julialang.org/t/how-to-tell-bindeps-i-dont-have-permission-for-package-installer/4572)

<div class="topic-metadata">

**Author:** [@JonathanAnderson](https://discourse.julialang.org/u/JonathanAnderson)\
**Replies:** 2\
**Last updated:** [July 1, 2017, 1:33pm UTC](https://discourse.julialang.org/t/how-to-tell-bindeps-i-dont-have-permission-for-package-installer/4572 "2017-07-01T13:33:47Z")

</div>

How can I tell BinDeps that I do not have permissions for yum. I frequently have to edit a package’s deps/build.jl files to comment out the provides(Yum,...) line to get around lack of sudo permissions.

---

## [How to detect variables of type \`Any\` at compiletime?](https://discourse.julialang.org/t/how-to-detect-variables-of-type-any-at-compiletime/4568)

<div class="topic-metadata">

**Author:** [@gdkrmr](https://discourse.julialang.org/u/gdkrmr)\
**Replies:** 5\
**Last updated:** [July 1, 2017, 1:07pm UTC](https://discourse.julialang.org/t/how-to-detect-variables-of-type-any-at-compiletime/4568 "2017-07-01T13:07:14Z")

</div>

I want a macro that detects (and makes the function fail or warns me) if some variable is not inferred correctly, if the variable’s type is inferred, then it should do nothing. E.g. something like this: j = 3 function …

---

## [Unitful parse](https://discourse.julialang.org/t/unitful-parse/4573)

<div class="topic-metadata">

**Author:** [@yakir12](https://discourse.julialang.org/u/yakir12)\
**Replies:** 2\
**Last updated:** [July 1, 2017, 6:28am UTC](https://discourse.julialang.org/t/unitful-parse/4573 "2017-07-01T06:28:39Z")

</div>

Say I have 1m in a text file. I read the text file and put that “1m” into variable x. How do I parse this x so that it contains the Unitful.jl 1m? julia\> x = strip(readstring("a.txt")) # a.txt contains: 1m "1m" julia\> …

---

## [Plots, How to save figure to the file with high resolution (dpi=300)?](https://discourse.julialang.org/t/plots-how-to-save-figure-to-the-file-with-high-resolution-dpi-300/4570)

<div class="topic-metadata">

**Author:** [@zhangliye](https://discourse.julialang.org/u/zhangliye)\
**Replies:** 10\
**Last updated:** [July 1, 2017, 6:19am UTC](https://discourse.julialang.org/t/plots-how-to-save-figure-to-the-file-with-high-resolution-dpi-300/4570 "2017-07-01T06:19:39Z")

</div>

When I use “scatter()” function with the parameter of “dpi”, the output figure looks strange. On windows 7, Julia0.5.2, Plots v0.11.4, Python2.7, matplotlib v1.1.1 using Plots; using StatPlots; pyplot( legend = true, d…

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

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