# General Usage

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

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

**Page:** 856

---

## [Simpler identifier for last result than ans](https://discourse.julialang.org/t/simpler-identifier-for-last-result-than-ans/25568)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 15\
**Last updated:** [June 23, 2019, 9:08pm UTC](https://discourse.julialang.org/t/simpler-identifier-for-last-result-than-ans/25568 "2019-06-23T21:08:12Z")

</div>

Hello, With ans I can refer to the last result in Julia. In ipython you can do the same with \_ (just an underscore). Is there a way to use a different identifier than ans to refer to the last result? Preferably using…

---

## [Irrational optimized away?](https://discourse.julialang.org/t/irrational-optimized-away/25577)

<div class="topic-metadata">

**Author:** [@tk3369](https://discourse.julialang.org/u/tk3369)\
**Replies:** 4\
**Last updated:** [June 23, 2019, 7:38pm UTC](https://discourse.julialang.org/t/irrational-optimized-away/25577 "2019-06-23T19:38:09Z")

</div>

I found this a little interesting. It seems that the add operation has been optimized away for irrational. How does it do that? julia\> koo(v) = v + 10 koo (generic function with 1 method) julia\> @code\_llvm koo(1) ; …

---

## [Importing a macro within another macro](https://discourse.julialang.org/t/importing-a-macro-within-another-macro/25550)

<div class="topic-metadata">

**Author:** [@phrmoy](https://discourse.julialang.org/u/phrmoy)\
**Replies:** 6\
**Last updated:** [June 23, 2019, 7:17pm UTC](https://discourse.julialang.org/t/importing-a-macro-within-another-macro/25550 "2019-06-23T19:17:20Z")

</div>

Why doesn’t this work? macro verify() return esc(quote using julia\_utils: @add\_default\_constructor mutable struct A a::Int A() = new() end @add\_default\_constru…

---

## [\`String\` returns true for \`isstructtype\`](https://discourse.julialang.org/t/string-returns-true-for-isstructtype/25559)

<div class="topic-metadata">

**Author:** [@phrmoy](https://discourse.julialang.org/u/phrmoy)\
**Replies:** 10\
**Last updated:** [June 23, 2019, 6:59pm UTC](https://discourse.julialang.org/t/string-returns-true-for-isstructtype/25559 "2019-06-23T18:59:36Z")

</div>

help?\> isstructtypesearch: isstructtype Base.isstructtype(T) -\> Bool Determine whether type T was declared as a struct type (i.e. using the struct or mutable struct keyword). julia\> xs = "test"; isstructtype(typeo…

---

## [JuMP 0.19 create constraints iteratively](https://discourse.julialang.org/t/jump-0-19-create-constraints-iteratively/25525)

<div class="topic-metadata">

**Author:** [@plapplop](https://discourse.julialang.org/u/plapplop)\
**Replies:** 2\
**Last updated:** [June 23, 2019, 10:18am UTC](https://discourse.julialang.org/t/jump-0-19-create-constraints-iteratively/25525 "2019-06-23T10:18:36Z")

</div>

I’m new to JuMP and I’m trying to model a simple problem: using JuMP, Gurobi months = 1:12 n\_months = length(months) demands = \[30, 15, 15, 25, 33, 40, 45, 45, 26, 14, 25, 30\] cap = 20 model = Model(with\_optimizer(Gur…

---

## [Mutually recursive type](https://discourse.julialang.org/t/mutually-recursive-type/25536)

<div class="topic-metadata">

**Author:** [@Freddy\_Chua](https://discourse.julialang.org/u/Freddy_Chua)\
**Replies:** 14\
**Last updated:** [June 23, 2019, 4:05am UTC](https://discourse.julialang.org/t/mutually-recursive-type/25536 "2019-06-23T04:05:07Z")

</div>

struct A b::B end struct B a::A end how to do this?

---

## [How do I push a value to all processes?](https://discourse.julialang.org/t/how-do-i-push-a-value-to-all-processes/25552)

<div class="topic-metadata">

**Author:** [@pixel27](https://discourse.julialang.org/u/pixel27)\
**Replies:** 4\
**Last updated:** [June 23, 2019, 3:24am UTC](https://discourse.julialang.org/t/how-do-i-push-a-value-to-all-processes/25552 "2019-06-23T03:24:03Z")

</div>

First what I’m trying to do: using Distributed addprocs(1) target = string(@\_\_DIR\_\_, "/dir2/d2.jl") @everywhere include(target) With a directory structure like: /dir1 m1.jl /dir 2 d2.jl The above code is in m…

---

## [Multiline Regex](https://discourse.julialang.org/t/multiline-regex/25477)

<div class="topic-metadata">

**Author:** [@Amval](https://discourse.julialang.org/u/Amval)\
**Replies:** 2\
**Last updated:** [June 22, 2019, 3:25pm UTC](https://discourse.julialang.org/t/multiline-regex/25477 "2019-06-22T15:25:40Z")

</div>

Hello all, I am trying to split a long regex into different lines. I am aware that string macros can be called with triple quotes. However this introduces a newline at the end. Any way of avoiding this?

---

## [Issues with incomplete parameterized types](https://discourse.julialang.org/t/issues-with-incomplete-parameterized-types/25542)

<div class="topic-metadata">

**Author:** [@Ross\_Boylan](https://discourse.julialang.org/u/Ross_Boylan)\
**Replies:** 1\
**Last updated:** [June 22, 2019, 8:02am UTC](https://discourse.julialang.org/t/issues-with-incomplete-parameterized-types/25542 "2019-06-22T08:02:39Z")

</div>

I thought I would build up a data structure with intermediate values I needed for a computation, to which I would later add the final results and return the whole thing. I’ve attempted to add type information, but some …

---

## [Semver and possible downside for Julia packages](https://discourse.julialang.org/t/semver-and-possible-downside-for-julia-packages/25531)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 3\
**Last updated:** [June 22, 2019, 5:03am UTC](https://discourse.julialang.org/t/semver-and-possible-downside-for-julia-packages/25531 "2019-06-22T05:03:52Z")

</div>

I do see at semver, which Julia follows, including the package manager (and thus all packages?): Given a version number MAJOR.MINOR.PATCH, increment the: MAJOR version when you make incompatible API changes, MINOR ver…

---

## [Parsing String to Dates.CompoundPeriod](https://discourse.julialang.org/t/parsing-string-to-dates-compoundperiod/25484)

<div class="topic-metadata">

**Author:** [@scelles](https://discourse.julialang.org/u/scelles)\
**Replies:** 11\
**Last updated:** [June 22, 2019, 4:32am UTC](https://discourse.julialang.org/t/parsing-string-to-dates-compoundperiod/25484 "2019-06-22T04:32:45Z")

</div>

Hello, I have Strings representing duration like "0.123" (in seconds, with millisecond resolution), "1:2.123" (minute:second.millisecond), "1:2:3.456" (hour:minute:second.millisecond) I wonder if some functions to pars…

---

## [How to use \`getproperty\`/\`setproperty!\`?](https://discourse.julialang.org/t/how-to-use-getproperty-setproperty/16033)

<div class="topic-metadata">

**Author:** [@e3c6](https://discourse.julialang.org/u/e3c6)\
**Replies:** 6\
**Last updated:** [June 22, 2019, 3:00am UTC](https://discourse.julialang.org/t/how-to-use-getproperty-setproperty/16033 "2019-06-22T03:00:47Z")

</div>

The recommended way to implement getproperty(value, name::Symbol) is by making as many branches as required to check what name is? This seems inefficient. Or is the compiler able to eliminate the branching when it sees a…

---

## [Best practice for broadcastable callables](https://discourse.julialang.org/t/best-practice-for-broadcastable-callables/21000)

<div class="topic-metadata">

**Author:** [@tkf](https://discourse.julialang.org/u/tkf)\
**Replies:** 4\
**Last updated:** [June 22, 2019, 2:55am UTC](https://discourse.julialang.org/t/best-practice-for-broadcastable-callables/21000 "2019-06-22T02:55:22Z")

</div>

I wonder what is the best practice for callables that are broadcastable for input and its parameters. Here is an example: struct Scale{T} a::T end struct Shift{T} a::T end (f::Scale)(x) = f.a \* x (f::Shift)(x…

---

## [Problem with broadcasting, flatten, and type-stability](https://discourse.julialang.org/t/problem-with-broadcasting-flatten-and-type-stability/25539)

<div class="topic-metadata">

**Author:** [@marius311](https://discourse.julialang.org/u/marius311)\
**Replies:** 1\
**Last updated:** [June 22, 2019, 2:32am UTC](https://discourse.julialang.org/t/problem-with-broadcasting-flatten-and-type-stability/25539 "2019-06-22T02:32:37Z")

</div>

I’m writing a custom AbstractArray implementation which supports broadcasting. This implementation makes use of Broadcast.flatten, but I’m finding that this introduces type-instabilities once expressions go beyond a few …

---

## [MonteCarloProblem Error](https://discourse.julialang.org/t/montecarloproblem-error/25538)

<div class="topic-metadata">

**Author:** [@LGa](https://discourse.julialang.org/u/LGa)\
**Replies:** 3\
**Last updated:** [June 21, 2019, 11:57pm UTC](https://discourse.julialang.org/t/montecarloproblem-error/25538 "2019-06-21T23:57:38Z")

</div>

Hello, I am following the instructions from the DifferentialEquations.jl package (http://docs.juliadiffeq.org/latest/features/noise\_process.html#Direct-Simulation-of-the-Noise-Process-1) to Monte Carlo simulate paths of…

---

## [Julia with C++ (C++20 and modules) vs. e.g. Python and pybind11](https://discourse.julialang.org/t/julia-with-c-c-20-and-modules-vs-e-g-python-and-pybind11/25526)

<div class="topic-metadata">

**Author:** [@Palli](https://discourse.julialang.org/u/Palli)\
**Replies:** 3\
**Last updated:** [June 21, 2019, 9:37pm UTC](https://discourse.julialang.org/t/julia-with-c-c-20-and-modules-vs-e-g-python-and-pybind11/25526 "2019-06-21T21:37:47Z")

</div>

Just curious, has anyone used/compared the “excellent” pybind11 (that supports at least C++17, not sure with C++20) and Julia with Cxx.jl and/or Cppwrap.jl? Note, Pybind11 has a benchmark section in their extensive docs…

---

## [Tuples of closures](https://discourse.julialang.org/t/tuples-of-closures/25506)

<div class="topic-metadata">

**Author:** [@cgeoga](https://discourse.julialang.org/u/cgeoga)\
**Replies:** 5\
**Last updated:** [June 21, 2019, 7:38pm UTC](https://discourse.julialang.org/t/tuples-of-closures/25506 "2019-06-21T19:38:14Z")

</div>

Hi all—I have a use case where I have a collection of functions that I want to include in a struct. I know the number of functions at compile time, but they will be made into closures with run-time data. It has been sugg…

---

## [Using Julia to set env variables](https://discourse.julialang.org/t/using-julia-to-set-env-variables/25492)

<div class="topic-metadata">

**Author:** [@ExpandingMan](https://discourse.julialang.org/u/ExpandingMan)\
**Replies:** 6\
**Last updated:** [June 21, 2019, 1:06pm UTC](https://discourse.julialang.org/t/using-julia-to-set-env-variables/25492 "2019-06-21T13:06:24Z")

</div>

I’d like to set environment variables in the enclosing shell from a Julia script. I’d have thought I could do run(\`export TESTVAR=varname\`) but I got the following very unexpected error ERROR: IOError: could not spaw…

---

## [Cumulative min / cumulative max](https://discourse.julialang.org/t/cumulative-min-cumulative-max/25516)

<div class="topic-metadata">

**Author:** [@scelles](https://discourse.julialang.org/u/scelles)\
**Replies:** 7\
**Last updated:** [June 21, 2019, 10:22am UTC](https://discourse.julialang.org/t/cumulative-min-cumulative-max/25516 "2019-06-21T10:22:50Z")

</div>

Hello, Python Pandas have an interesting function named cumulative min (and its counterpart cumulative max) See python - Rolling min of a Pandas Series without window / cumulative minimum / expanding min - Stack Overfl…

---

## [Testing Unexported functions](https://discourse.julialang.org/t/testing-unexported-functions/25510)

<div class="topic-metadata">

**Author:** [@Alec\_Loudenback](https://discourse.julialang.org/u/Alec_Loudenback)\
**Replies:** 1\
**Last updated:** [June 21, 2019, 4:12am UTC](https://discourse.julialang.org/t/testing-unexported-functions/25510 "2019-06-21T04:12:28Z")

</div>

If I have a function in a package that I am working on, how do perform unit testing on a function that I don’t want to export? When I try to test my\_unexported\_function via pkg\> test I get the error UndefVarError: my…

---

## [Help me get rid of extra allocations in this generic batching iterator](https://discourse.julialang.org/t/help-me-get-rid-of-extra-allocations-in-this-generic-batching-iterator/25061)

<div class="topic-metadata">

**Author:** [@Roger-luo](https://discourse.julialang.org/u/Roger-luo)\
**Replies:** 3\
**Last updated:** [June 21, 2019, 12:21am UTC](https://discourse.julialang.org/t/help-me-get-rid-of-extra-allocations-in-this-generic-batching-iterator/25061 "2019-06-21T00:21:59Z")

</div>

I’m trying to make the routines in BatchedRoutines more generic, so I could wrap other BLAS routines to use pointer offsets easier. However, when I wrap the iteration to a function, the batched\_gemm routine become type u…

---

## [Converting String to DataType](https://discourse.julialang.org/t/converting-string-to-datatype/25504)

<div class="topic-metadata">

**Author:** [@dataSurfer](https://discourse.julialang.org/u/dataSurfer)\
**Replies:** 3\
**Last updated:** [June 20, 2019, 11:46pm UTC](https://discourse.julialang.org/t/converting-string-to-datatype/25504 "2019-06-20T23:46:42Z")

</div>

I’m using Julia v1.2 rc1 and I’d like to be able to convert a string to a data type but eval(Symbol("SomeComplexType")) isn’t doing it for types that are not basic. For instance this eval(Symbol("Float64")) returns Flo…

---

## [Enforcing higher-order type parameter constraints](https://discourse.julialang.org/t/enforcing-higher-order-type-parameter-constraints/25435)

<div class="topic-metadata">

**Author:** [@simsurace](https://discourse.julialang.org/u/simsurace)\
**Replies:** 13\
**Last updated:** [June 20, 2019, 11:11pm UTC](https://discourse.julialang.org/t/enforcing-higher-order-type-parameter-constraints/25435 "2019-06-20T23:11:24Z")

</div>

One design pattern I keep stumbling upon is that I want to generate parametric types based on existing parametric types, but with certain constraints among parameters, such that inappropriate combinations are prevented f…

---

## [Using PARTR in Julia 1.2?](https://discourse.julialang.org/t/using-partr-in-julia-1-2/25485)

<div class="topic-metadata">

**Author:** [@oschulz](https://discourse.julialang.org/u/oschulz)\
**Replies:** 7\
**Last updated:** [June 20, 2019, 7:08pm UTC](https://discourse.julialang.org/t/using-partr-in-julia-1-2/25485 "2019-06-20T19:08:44Z")

</div>

Hi, from what I understand, PARTR (resp. parts of what it will become) will be part of Julia 1.2. I’m keen to try it out, if possible, by my attempts at starting tasks within an @threads loop have failed, the tasks alwa…

---

## [Float32 function return and Cuda](https://discourse.julialang.org/t/float32-function-return-and-cuda/25489)

<div class="topic-metadata">

**Author:** [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Replies:** 3\
**Last updated:** [June 20, 2019, 7:06pm UTC](https://discourse.julialang.org/t/float32-function-return-and-cuda/25489 "2019-06-20T19:06:11Z")

</div>

I have GPU(GTX 1050) that performance for Float32 compared to Float64 is about 32 times better, so I should use Float32 values. I have function that return values in format of Float64(or Tuple of Float64). Function looks…

---

## [Can't pop/delteat elements in loop](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462)

<div class="topic-metadata">

**Author:** [@wiktorkujawa](https://discourse.julialang.org/u/wiktorkujawa)\
**Replies:** 4\
**Last updated:** [June 20, 2019, 6:28pm UTC](https://discourse.julialang.org/t/cant-pop-delteat-elements-in-loop/25462 "2019-06-20T18:28:18Z")

</div>

I can pop/deleteat only last element in my program. Here’s the code(it uses CImGui library): for i=1:length(S) CImGui.PushID(i-1) CImGui.Text("Line nr $i: $(S\[i\]) \\n") CImGui.SameLine() CImGui.Button…

---

## [More elegant way to get the \`UnionAll\` type from an instance?](https://discourse.julialang.org/t/more-elegant-way-to-get-the-unionall-type-from-an-instance/22439)

<div class="topic-metadata">

**Author:** [@singularitti](https://discourse.julialang.org/u/singularitti)\
**Replies:** 4\
**Last updated:** [June 20, 2019, 6:24pm UTC](https://discourse.julialang.org/t/more-elegant-way-to-get-the-unionall-type-from-an-instance/22439 "2019-06-20T18:24:24Z")

</div>

I have a UnionAll type MyVec: julia\> struct MyVec{a,A \<: AbstractVector} data::A function MyVec{a,A}(data) where {a,A} new(data) end end julia\> x = MyVec{:x, Vecto…

---

## [Debugging strange allocations](https://discourse.julialang.org/t/debugging-strange-allocations/25488)

<div class="topic-metadata">

**Author:** [@jw3126](https://discourse.julialang.org/u/jw3126)\
**Replies:** 5\
**Last updated:** [June 20, 2019, 4:19pm UTC](https://discourse.julialang.org/t/debugging-strange-allocations/25488 "2019-06-20T16:19:11Z")

</div>

Motivation When optimizing julia code, my first step is usually to make sure the compiler infers everything. There are great tools like @code\_warntype and Cthulhu, that allow to diagnose inference problems in a systemati…

---

## [User-defined Variadic Parametric Types](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487)

<div class="topic-metadata">

**Author:** [@cshenton](https://discourse.julialang.org/u/cshenton)\
**Replies:** 4\
**Last updated:** [June 20, 2019, 4:09pm UTC](https://discourse.julialang.org/t/user-defined-variadic-parametric-types/25487 "2019-06-20T16:09:29Z")

</div>

In Base, Tuple can have variadic (0 or more) type arguments. Is there a way to achieve this for a user defined type? I want to represent something like a strongly typed reference to a single database row. Where the str…

---

## [Realtime streaming of tick data](https://discourse.julialang.org/t/realtime-streaming-of-tick-data/5713)

<div class="topic-metadata">

**Author:** [@hgeorgako](https://discourse.julialang.org/u/hgeorgako)\
**Replies:** 9\
**Last updated:** [June 20, 2019, 2:55pm UTC](https://discourse.julialang.org/t/realtime-streaming-of-tick-data/5713 "2019-06-20T14:55:34Z")

</div>

I have a black box model (written in Julia) that requires realtime tick data as an input. The output of this model needs to be pub-subbed out to clients listening on a socket or topic. I have dozens to potentially hund…

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

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