# General Usage

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

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

**Page:** 226

---

## [Yield in iterator](https://discourse.julialang.org/t/yield-in-iterator/106833)

<div class="topic-metadata">

**Author:** [@cesarmarinhorj](https://discourse.julialang.org/u/cesarmarinhorj)\
**Replies:** 5\
**Last updated:** [November 28, 2023, 12:00pm UTC](https://discourse.julialang.org/t/yield-in-iterator/106833 "2023-11-28T12:00:07Z")

</div>

How can I use a “yield” inside a function like a generator/iterator? function results() yield 1 yield 2 yield 3 }

---

## [How to separate joint and disjoint intervals from an interval vector?](https://discourse.julialang.org/t/how-to-separate-joint-and-disjoint-intervals-from-an-interval-vector/106515)

<div class="topic-metadata">

**Author:** [@Ashu](https://discourse.julialang.org/u/Ashu)\
**Replies:** 17\
**Last updated:** [November 28, 2023, 11:56am UTC](https://discourse.julialang.org/t/how-to-separate-joint-and-disjoint-intervals-from-an-interval-vector/106515 "2023-11-28T11:56:42Z")

</div>

Hello, I have a vector. Each element of the vector is a tuple that contains two elements, an interval, and a set of three intervals. I want to separate and take unions of those elements of the vector that contain an emp…

---

## [Unexpected sensitivity to order of method definitions](https://discourse.julialang.org/t/unexpected-sensitivity-to-order-of-method-definitions/106510)

<div class="topic-metadata">

**Author:** [@tverho](https://discourse.julialang.org/u/tverho)\
**Replies:** 11\
**Last updated:** [November 22, 2023, 8:03am UTC](https://discourse.julialang.org/t/unexpected-sensitivity-to-order-of-method-definitions/106510 "2023-11-22T08:03:03Z")

</div>

The following works like a charm: function f(a; b) a + b end function f(a) a + a end julia\> f(2) 4 julia\> f(2,b=1) 3 But reversing the order results in an error: function f(a) a + a end function f(a; b)…

---

## [Problem in reading TIFF floats file](https://discourse.julialang.org/t/problem-in-reading-tiff-floats-file/106610)

<div class="topic-metadata">

**Author:** [@RunguangLi](https://discourse.julialang.org/u/RunguangLi)\
**Replies:** 8\
**Last updated:** [November 28, 2023, 3:17am UTC](https://discourse.julialang.org/t/problem-in-reading-tiff-floats-file/106610 "2023-11-28T03:17:06Z")

</div>

When I read a tiff floats image (001.tif) using FileIO by real(load("001.tif")), I get a matrix with only 1.0 and 0.0 elements. 360×2304 Array{N0f32,2} with eltype FixedPointNumbers.N0f32: 0.0 0.0 0.0 0.0 0.0 0.0 …

---

## [How to document functions twice?](https://discourse.julialang.org/t/how-to-document-functions-twice/106816)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 4\
**Last updated:** [November 27, 2023, 9:45pm UTC](https://discourse.julialang.org/t/how-to-document-functions-twice/106816 "2023-11-27T21:45:08Z")

</div>

I want to refer to a function twice in my documentation, once I document the functions per file, and once per category. How can I achieve that? If I refer to a function in two files like this: \`\`\`@docs plot\_cp plot\_fou…

---

## [What is a safer way to expand other packages' function?](https://discourse.julialang.org/t/what-is-a-safer-way-to-expand-other-packages-function/106818)

<div class="topic-metadata">

**Author:** [@tiZ](https://discourse.julialang.org/u/tiZ)\
**Replies:** 8\
**Last updated:** [November 27, 2023, 9:21pm UTC](https://discourse.julialang.org/t/what-is-a-safer-way-to-expand-other-packages-function/106818 "2023-11-27T21:21:23Z")

</div>

Hi friends, I am try to expand the DataFrame function for my data struct, I defined it as: using DataFrames DataFrame(Q::mystrust) = begin # do something end it works well, but when I write above as a file and incl…

---

## [Typeof on Any vs Typeof on Union?](https://discourse.julialang.org/t/typeof-on-any-vs-typeof-on-union/106806)

<div class="topic-metadata">

**Author:** [@hlbnet](https://discourse.julialang.org/u/hlbnet)\
**Replies:** 3\
**Last updated:** [November 27, 2023, 4:48pm UTC](https://discourse.julialang.org/t/typeof-on-any-vs-typeof-on-union/106806 "2023-11-27T16:48:10Z")

</div>

Hi everybody, Is there a general explanation of why typeof comparisons on Any is 20 times slower than on Union in the following example ? Especially, the huge memory allocation in one case but not in the other ? Here …

---

## [Speed of multiple dispatch](https://discourse.julialang.org/t/speed-of-multiple-dispatch/106717)

<div class="topic-metadata">

**Author:** [@hlbnet](https://discourse.julialang.org/u/hlbnet)\
**Replies:** 14\
**Last updated:** [November 27, 2023, 4:25pm UTC](https://discourse.julialang.org/t/speed-of-multiple-dispatch/106717 "2023-11-27T16:25:24Z")

</div>

Hello, In the following example, multiple dispatch is more that 10 times slower than typeof comparisons. Is it expected, or is there some issue in my code ? Ouput: Size=20000 If typeof 1006900000 1.576137 seconds…

---

## [Is there a possibility to prevent task switches in a block of code?](https://discourse.julialang.org/t/is-there-a-possibility-to-prevent-task-switches-in-a-block-of-code/106798)

<div class="topic-metadata">

**Author:** [@schlichtanders](https://discourse.julialang.org/u/schlichtanders)\
**Replies:** 49\
**Last updated:** [November 27, 2023, 3:54pm UTC](https://discourse.julialang.org/t/is-there-a-possibility-to-prevent-task-switches-in-a-block-of-code/106798 "2023-11-27T15:54:16Z")

</div>

I would like to ensure that within a certain block of code no task switch can happen. A bit like an “atomic block” for async tasks

---

## [Is it possible to cut a vector into 2 pieces without allocations?](https://discourse.julialang.org/t/is-it-possible-to-cut-a-vector-into-2-pieces-without-allocations/106749)

<div class="topic-metadata">

**Author:** [@Leo\_I](https://discourse.julialang.org/u/Leo_I)\
**Replies:** 11\
**Last updated:** [November 27, 2023, 10:25am UTC](https://discourse.julialang.org/t/is-it-possible-to-cut-a-vector-into-2-pieces-without-allocations/106749 "2023-11-27T10:25:36Z")

</div>

Let’s say I have toy data m, n = 10^3, 10^6; x1 = \[rand(-1:0.001:1,s) for j=1:n for s in rand(1:m,1)\] len = \[rand(1:length(x)) for x in x1\] I wish to split each vector x1\[j\] into x1\[j\]\[1:len\[j\]\] and x1\[j\]\[len\[j\]:end…

---

## [Definition of struct written from C and read-only in Julia](https://discourse.julialang.org/t/definition-of-struct-written-from-c-and-read-only-in-julia/106667)

<div class="topic-metadata">

**Author:** [@PatrickHaecker](https://discourse.julialang.org/u/PatrickHaecker)\
**Replies:** 7\
**Last updated:** [November 27, 2023, 10:57am UTC](https://discourse.julialang.org/t/definition-of-struct-written-from-c-and-read-only-in-julia/106667 "2023-11-27T10:57:45Z")

</div>

I hand over a struct to a C library which periodically will enter values in the struct’s field and then call a Julia callback function. The struct is defined and gets created (memory allocated) in Julia, but only C write…

---

## [When I add any package, PrettyTables will get stuck here and cannot be executed. I need to control+C to close it](https://discourse.julialang.org/t/when-i-add-any-package-prettytables-will-get-stuck-here-and-cannot-be-executed-i-need-to-control-c-to-close-it/106301)

<div class="topic-metadata">

**Author:** [@wang\_ruoxu](https://discourse.julialang.org/u/wang_ruoxu)\
**Replies:** 3\
**Last updated:** [November 27, 2023, 10:24am UTC](https://discourse.julialang.org/t/when-i-add-any-package-prettytables-will-get-stuck-here-and-cannot-be-executed-i-need-to-control-c-to-close-it/106301 "2023-11-27T10:24:14Z")

</div>

what can i do to solved it . Julia Version 1.9.4 Commit 8e5136fa297 (2023-11-14 08:46 UTC) Build Info: Official https://julialang.org/ release Platform Info: OS: Linux (x86\_64-linux-gnu) CPU: 16 × Intel(R) Core™ i…

---

## [How to suppress Pkg messages?](https://discourse.julialang.org/t/how-to-suppress-pkg-messages/106776)

<div class="topic-metadata">

**Author:** [@PetrKryslUCSD](https://discourse.julialang.org/u/PetrKryslUCSD)\
**Replies:** 5\
**Last updated:** [November 27, 2023, 10:07am UTC](https://discourse.julialang.org/t/how-to-suppress-pkg-messages/106776 "2023-11-27T10:07:33Z")

</div>

pkrysl@BlackCube MINGW64 /d/BoneShaker.jl (main) $ julia --quiet …

---

## [Parametric types & multiple dispatch](https://discourse.julialang.org/t/parametric-types-multiple-dispatch/106650)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 7\
**Last updated:** [November 27, 2023, 9:30am UTC](https://discourse.julialang.org/t/parametric-types-multiple-dispatch/106650 "2023-11-27T09:30:34Z")

</div>

Method choice can be determined by a parametric type struct X{x} end f(::X{:x1}) = 1 f(::X{:x2}) = 2 f(X{:x1}()) # 1 f(X{:x2}()) # 2 Why not allow it to be determined just with the parameter ? f({:x1}) = 1 f({:x2}) …

---

## [Int and float functions](https://discourse.julialang.org/t/int-and-float-functions/106770)

<div class="topic-metadata">

**Author:** [@fdekerme](https://discourse.julialang.org/u/fdekerme)\
**Replies:** 7\
**Last updated:** [November 27, 2023, 6:43am UTC](https://discourse.julialang.org/t/int-and-float-functions/106770 "2023-11-27T06:43:55Z")

</div>

Hello, Just a question: Why is the Int function capitalized and the float function lower-case? julia\> 0x0001 |\> Int 1 julia\> 0x0001 |\> float 1.0 julia\> 0x0001 |\> Float ERROR: UndefVarError: \`Float\` not defined Stackt…

---

## [Extending \`dropmissing\` to AbstractArrays](https://discourse.julialang.org/t/extending-dropmissing-to-abstractarrays/106753)

<div class="topic-metadata">

**Author:** [@Dan](https://discourse.julialang.org/u/Dan)\
**Replies:** 4\
**Last updated:** [November 26, 2023, 9:53pm UTC](https://discourse.julialang.org/t/extending-dropmissing-to-abstractarrays/106753 "2023-11-26T21:53:15Z")

</div>

From another thread, there was discussion of skipmissing, and it prompted me to think dropmissing is a convenient way to get rid of those pesky missings. DataFrames has dropmissing but regular Arrays don’t. How could it …

---

## [Trouble defining hash/isequal for an interval type](https://discourse.julialang.org/t/trouble-defining-hash-isequal-for-an-interval-type/106629)

<div class="topic-metadata">

**Author:** [@rocco\_sprmnt21](https://discourse.julialang.org/u/rocco_sprmnt21)\
**Replies:** 7\
**Last updated:** [November 26, 2023, 2:58pm UTC](https://discourse.julialang.org/t/trouble-defining-hash-isequal-for-an-interval-type/106629 "2023-11-26T14:58:46Z")

</div>

I tried to practice on this topic, but evidently I still lack a lot of knowledge to be profitable. I would like to be able to merge the two dictionaries so that, for example, merge(da,db) ==db That is, having da and db…

---

## [PrecompileTools - how to disable output of @info](https://discourse.julialang.org/t/precompiletools-how-to-disable-output-of-info/106737)

<div class="topic-metadata">

**Author:** [@judober](https://discourse.julialang.org/u/judober)\
**Replies:** 3\
**Last updated:** [November 26, 2023, 11:57am UTC](https://discourse.julialang.org/t/precompiletools-how-to-disable-output-of-info/106737 "2023-11-26T11:57:22Z")

</div>

I try to implement precompilation with PrecompileTools. It works quite good now. However, in my compile\_workload() I have some code that uses @info "test" resulting in output during precompilation. I tried to remove the…

---

## [Would attribute inference be possible?](https://discourse.julialang.org/t/would-attribute-inference-be-possible/106723)

<div class="topic-metadata">

**Author:** [@Tarny\_GG\_Channie](https://discourse.julialang.org/u/Tarny_GG_Channie)\
**Replies:** 12\
**Last updated:** [November 26, 2023, 11:59am UTC](https://discourse.julialang.org/t/would-attribute-inference-be-possible/106723 "2023-11-26T11:59:47Z")

</div>

@attributeInferredType Student end function main() s1 = Student() s2 = Student() s1.age = 19 s2.age = 20 s1.grade = 3.7 #Here, you have two instances of students, one with only attribute age, …

---

## [What's your "standard" Julia project toolkit?](https://discourse.julialang.org/t/whats-your-standard-julia-project-toolkit/106732)

<div class="topic-metadata">

**Author:** [@astra\_kawa](https://discourse.julialang.org/u/astra_kawa)\
**Replies:** 6\
**Last updated:** [November 26, 2023, 10:04am UTC](https://discourse.julialang.org/t/whats-your-standard-julia-project-toolkit/106732 "2023-11-26T10:04:43Z")

</div>

I’ve started a new job a couple months ago and have been using Julia recently for a project. I’m interested to learn what packages people always turn to/rely on for their general, day-to-day work. I want to expand my kno…

---

## [Unable to remove the smallest element from a Set](https://discourse.julialang.org/t/unable-to-remove-the-smallest-element-from-a-set/106726)

<div class="topic-metadata">

**Author:** [@StevenSiew](https://discourse.julialang.org/u/StevenSiew)\
**Replies:** 3\
**Last updated:** [November 26, 2023, 1:50am UTC](https://discourse.julialang.org/t/unable-to-remove-the-smallest-element-from-a-set/106726 "2023-11-26T01:50:59Z")

</div>

I have a set of Characters A to Z which are represented by int64 1,2,3…,26 in a set. I want to remove the smallest character A from the set but my code does not work and I could not figure out why """ Create a set of …

---

## [Creating a tensor (array) in the tensor product of super vector spaces](https://discourse.julialang.org/t/creating-a-tensor-array-in-the-tensor-product-of-super-vector-spaces/106657)

<div class="topic-metadata">

**Author:** [@Yue-Zhengyuan](https://discourse.julialang.org/u/Yue-Zhengyuan)\
**Replies:** 8\
**Last updated:** [November 26, 2023, 1:15am UTC](https://discourse.julialang.org/t/creating-a-tensor-array-in-the-tensor-product-of-super-vector-spaces/106657 "2023-11-26T01:15:54Z")

</div>

I want to create a custom array of arrays (each array is called a “block”) indexed by a list of 0 and 1’s. For example, suppose the array has 4 dimensions; then. The arrays are indexed by (0,0,0,0), (0,0,0,1), (0,0,1,0…

---

## [Strange (to me, at least) result in string interpolation](https://discourse.julialang.org/t/strange-to-me-at-least-result-in-string-interpolation/106709)

<div class="topic-metadata">

**Author:** [@braamvandyk](https://discourse.julialang.org/u/braamvandyk)\
**Replies:** 2\
**Last updated:** [November 25, 2023, 5:34pm UTC](https://discourse.julialang.org/t/strange-to-me-at-least-result-in-string-interpolation/106709 "2023-11-25T17:34:39Z")

</div>

I stumbled across this today while debugging a little macro I am writing. If someone could explain this to me, I would really appreciate it. It’s not a problem for my code, but I’m quite curious to understand. My macro …

---

## [\<CTRL\>\<c\> on Windows](https://discourse.julialang.org/t/ctrl-c-on-windows/106707)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 5\
**Last updated:** [November 25, 2023, 4:16pm UTC](https://discourse.julialang.org/t/ctrl-c-on-windows/106707 "2023-11-25T16:16:35Z")

</div>

I am using the package LiveServer to display my documentation, using this function: function docu() @eval using LiveServer Base.invokelatest(servedocs, launch\_browser=true) end This works fine, but on Windows I…

---

## [How can I use TimerOutputs.jl to time a function and its internal function calls in a package?](https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702)

<div class="topic-metadata">

**Author:** [@liuyxpp](https://discourse.julialang.org/u/liuyxpp)\
**Replies:** 1\
**Last updated:** [November 25, 2023, 10:00am UTC](https://discourse.julialang.org/t/how-can-i-use-timeroutputs-jl-to-time-a-function-and-its-internal-function-calls-in-a-package/106702 "2023-11-25T10:00:23Z")

</div>

From the doc of the TimerOutputs.jl, it is not clear how to use it for timing a function and its internal function calls in my developing packages. Normally, I will create a new environment outside of my package and writ…

---

## [Weird UndefRefError in pmap since 1.8](https://discourse.julialang.org/t/weird-undefreferror-in-pmap-since-1-8/91567)

<div class="topic-metadata">

**Author:** [@K\_B](https://discourse.julialang.org/u/K_B)\
**Replies:** 5\
**Last updated:** [November 25, 2023, 4:16am UTC](https://discourse.julialang.org/t/weird-undefreferror-in-pmap-since-1-8/91567 "2023-11-25T04:16:49Z")

</div>

Hey. I am kind of new to the language and my coding knowledge is very minimal. Therefore I am unable to solve (even understand) the problem I have right now. My code is kind of large and convoluted and I don’t know how …

---

## [Error when file is not found](https://discourse.julialang.org/t/error-when-file-is-not-found/106665)

<div class="topic-metadata">

**Author:** [@Barvid](https://discourse.julialang.org/u/Barvid)\
**Replies:** 12\
**Last updated:** [November 24, 2023, 8:21pm UTC](https://discourse.julialang.org/t/error-when-file-is-not-found/106665 "2023-11-24T20:21:30Z")

</div>

Hello All I am sure there is super simple elegant solution to this, but I cant find it, so sorry for the silly question. my code loads a csv file and sometimes the file is not there, so need to handle that. I found 2 w…

---

## [Is this string2range function correct?](https://discourse.julialang.org/t/is-this-string2range-function-correct/106655)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 5\
**Last updated:** [November 24, 2023, 6:18pm UTC](https://discourse.julialang.org/t/is-this-string2range-function-correct/106655 "2023-11-24T18:18:28Z")

</div>

I wrote the following function: function string2range(string\_range) a, b, c = split(string\_range, ':') a1 = parse(Float64, a) b1 = parse(Float64, b) c1 = parse(Float64, c) StepRangeLen(a1, b1, 1+Int6…

---

## [Limit \`catch\_backtrace()\` to function handling the exception](https://discourse.julialang.org/t/limit-catch-backtrace-to-function-handling-the-exception/106649)

<div class="topic-metadata">

**Author:** [@goerz](https://discourse.julialang.org/u/goerz)\
**Replies:** 2\
**Last updated:** [November 24, 2023, 7:02pm UTC](https://discourse.julialang.org/t/limit-catch-backtrace-to-function-handling-the-exception/106649 "2023-11-24T19:02:58Z")

</div>

Consider the following example: f(x) = 1/sqrt(x) function myfunc(x) try @show f(x) catch exc @error "Exception in f" exception=(exc, catch\_backtrace()) end end myfunc(-1) If I run this in …

---

## [Building an anonymous callback function on the fly](https://discourse.julialang.org/t/building-an-anonymous-callback-function-on-the-fly/106678)

<div class="topic-metadata">

**Author:** [@Niall](https://discourse.julialang.org/u/Niall)\
**Replies:** 3\
**Last updated:** [November 24, 2023, 6:28pm UTC](https://discourse.julialang.org/t/building-an-anonymous-callback-function-on-the-fly/106678 "2023-11-24T18:28:35Z")

</div>

Hi. This (I think) is probably a question about meta-programming. I’m writing a System Dynamics (Stock and Flow) wrapper around the DynamicalSystems package. In a method named build!(), I pull together the various bits o…

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

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