# General Usage

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

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

**Page:** 521

---

## [Trampolines](https://discourse.julialang.org/t/trampolines/71351)

<div class="topic-metadata">

**Author:** [@goerch](https://discourse.julialang.org/u/goerch)\
**Replies:** 6\
**Last updated:** [November 13, 2021, 12:03am UTC](https://discourse.julialang.org/t/trampolines/71351 "2021-11-13T00:03:16Z")

</div>

Hi guys, I was playing around with trampolines and the following program using BenchmarkTools fac(n) = n == 0 ? 1 : n \* fac(n - 1) pow(x, n) = n == 0 ? 1 : x \* pow(x, n - 1) n = 63 @btime fac($n) x = 2. n = 64 @btim…

---

## [How to query CoinMarketCap with Julia (rest api)](https://discourse.julialang.org/t/how-to-query-coinmarketcap-with-julia-rest-api/71406)

<div class="topic-metadata">

**Author:** [@ufechner7](https://discourse.julialang.org/u/ufechner7)\
**Replies:** 2\
**Last updated:** [November 12, 2021, 11:37pm UTC](https://discourse.julialang.org/t/how-to-query-coinmarketcap-with-julia-rest-api/71406 "2021-11-12T23:37:24Z")

</div>

Hello, How can I translate the following request to a Julia function: curl -H "X-CMC\_PRO\_API\_KEY: b54bcf4d-1bca-4e8e-9a24-22ff2c3d462c" -H "Accept: application/json" -d "start=1&limit=5000&convert=USD" -G https://sandb…

---

## [Syntax for active patterns](https://discourse.julialang.org/t/syntax-for-active-patterns/71407)

<div class="topic-metadata">

**Author:** [@jzr](https://discourse.julialang.org/u/jzr)\
**Replies:** 2\
**Last updated:** [November 12, 2021, 10:37pm UTC](https://discourse.julialang.org/t/syntax-for-active-patterns/71407 "2021-11-12T22:37:42Z")

</div>

@active Split(xs) begin n = length(xs) n%2==0 ? (xs\[begin:Int(n/2)\], xs\[Int(n/2+1):end\]) : (xs\[begin:Int(floor(n/2))\], xs\[Int(ceil(n/2))\], xs\[Int(floor(n/2+1)):end\]) end @match \[-2,-1,0,1,2\] begi…

---

## [Is NLopt thread safe?](https://discourse.julialang.org/t/is-nlopt-thread-safe/71398)

<div class="topic-metadata">

**Author:** [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Replies:** 6\
**Last updated:** [November 12, 2021, 10:25pm UTC](https://discourse.julialang.org/t/is-nlopt-thread-safe/71398 "2021-11-12T22:25:33Z")

</div>

I’ve got a constrained optimization situation where restarting NLopt from multiple initial points tends to be a good idea. I’d like to simply do @threads and split them over several threads, but I don’t know if this is s…

---

## [Can Programming in Julia Be "Pure"?](https://discourse.julialang.org/t/can-programming-in-julia-be-pure/71165)

<div class="topic-metadata">

**Author:** [@TheCedarPrince](https://discourse.julialang.org/u/TheCedarPrince)\
**Replies:** 13\
**Last updated:** [November 12, 2021, 10:13pm UTC](https://discourse.julialang.org/t/can-programming-in-julia-be-pure/71165 "2021-11-12T22:13:09Z")

</div>

Hi all, I am learning about pure functions. The definition I have is: A pure function is one in which the same result is always produced with no side effects given the same input. This comes from Category Theory for…

---

## [Getting the last element of an iterator](https://discourse.julialang.org/t/getting-the-last-element-of-an-iterator/49696)

<div class="topic-metadata">

**Author:** [@sijo](https://discourse.julialang.org/u/sijo)\
**Replies:** 45\
**Last updated:** [November 12, 2021, 9:51pm UTC](https://discourse.julialang.org/t/getting-the-last-element-of-an-iterator/49696 "2021-11-12T21:51:31Z")

</div>

Question 1: Is there a nice one-liner to get the last element of an iterator, without collecting in a temporary array? The obvious doesn’t work: julia\> eachline(\`dir\`) |\> last ERROR: MethodError: no method matching last…

---

## [Julia for VS Code: error when trying to output plot](https://discourse.julialang.org/t/julia-for-vs-code-error-when-trying-to-output-plot/71394)

<div class="topic-metadata">

**Author:** [@Olivier\_Merchiers](https://discourse.julialang.org/u/Olivier_Merchiers)\
**Replies:** 2\
**Last updated:** [November 12, 2021, 9:39pm UTC](https://discourse.julialang.org/t/julia-for-vs-code-error-when-trying-to-output-plot/71394 "2021-11-12T21:39:20Z")

</div>

I get this error: Error loading webview: Error: Could not register service workers: InvalidStateError: Failed to register a ServiceWorker: The document is in an invalid state.. Here are the versions: Julia1.63 julia…

---

## [Setting the editor for \`@edit\` in the REPL](https://discourse.julialang.org/t/setting-the-editor-for-edit-in-the-repl/4812)

<div class="topic-metadata">

**Author:** [@anon94023334](https://discourse.julialang.org/u/anon94023334)\
**Replies:** 4\
**Last updated:** [November 12, 2021, 5:55pm UTC](https://discourse.julialang.org/t/setting-the-editor-for-edit-in-the-repl/4812 "2021-11-12T17:55:40Z")

</div>

Right now, @edit opens up TextEdit on my mac, which is not great for editing (especially since it has no line numbering by default, which makes it difficult to jump to the function). How does one specify the editor (e.g.…

---

## [Downloads.jl: Error: curl\_easy\_setopt: 48](https://discourse.julialang.org/t/downloads-jl-error-curl-easy-setopt-48/58222)

<div class="topic-metadata">

**Author:** [@carstenbauer](https://discourse.julialang.org/u/carstenbauer)\
**Replies:** 11\
**Last updated:** [November 12, 2021, 4:27pm UTC](https://discourse.julialang.org/t/downloads-jl-error-curl-easy-setopt-48/58222 "2021-11-12T16:27:05Z")

</div>

On one of the supercomputers that I use I get: (@v1.6) pkg\> add BenchmarkTools Installing known registries into \`/p/project/chku27/hku273/.julia\` ┌ Error: curl\_easy\_setopt: 48 └ @ Downloads.Curl /buildworker/worker/pa…

---

## [Specify digits in contour plot scale](https://discourse.julialang.org/t/specify-digits-in-contour-plot-scale/71384)

<div class="topic-metadata">

**Author:** [@Christopher\_Fisher](https://discourse.julialang.org/u/Christopher_Fisher)\
**Replies:** 4\
**Last updated:** [November 12, 2021, 4:14pm UTC](https://discourse.julialang.org/t/specify-digits-in-contour-plot-scale/71384 "2021-11-12T16:14:31Z")

</div>

I have a grid of contour plots. Depending on input, some subplots only have a single value on the z dimension. The problem is that the scale displays multiple digits, which decreases the size of all subplots in the grid.…

---

## [Failed build of documentation on CI due to missing "Qt plugin" (?)](https://discourse.julialang.org/t/failed-build-of-documentation-on-ci-due-to-missing-qt-plugin/71389)

<div class="topic-metadata">

**Author:** [@sylvaticus](https://discourse.julialang.org/u/sylvaticus)\
**Replies:** 2\
**Last updated:** [November 12, 2021, 3:45pm UTC](https://discourse.julialang.org/t/failed-build-of-documentation-on-ci-due-to-missing-qt-plugin/71389 "2021-11-12T15:45:43Z")

</div>

It is a few weeks that my documentation doesn’t build anymore on GitHub, and I can’t get back to the problem. The actions log just tells me that the line where I call makedocs returns the above error: qt.qpa.xcb: coul…

---

## [Get\_variables from Symbolics](https://discourse.julialang.org/t/get-variables-from-symbolics/71366)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 2\
**Last updated:** [November 12, 2021, 3:51pm UTC](https://discourse.julialang.org/t/get-variables-from-symbolics/71366 "2021-11-12T15:51:09Z")

</div>

the issue is more clearly described at this github issue comment link https://github.com/SciML/Catalyst.jl/issues/422#issuecomment-966919073 If anybody could explain, how to obtain variables from such expressions, eg, …

---

## [Type inference for recursive broadcasting operations](https://discourse.julialang.org/t/type-inference-for-recursive-broadcasting-operations/71336)

<div class="topic-metadata">

**Author:** [@Marco\_Lombardi](https://discourse.julialang.org/u/Marco_Lombardi)\
**Replies:** 6\
**Last updated:** [November 12, 2021, 2:21pm UTC](https://discourse.julialang.org/t/type-inference-for-recursive-broadcasting-operations/71336 "2021-11-12T14:21:49Z")

</div>

Apologizes for the relatively long minimal example. I want to write an efficient broadcasting which is able to sum results from different objects. As an example, suppose I want to compute the sum of periodic functions, …

---

## [Terminate condition in ContinuousCallback in DifferentialEquations.jl](https://discourse.julialang.org/t/terminate-condition-in-continuouscallback-in-differentialequations-jl/69748)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 13\
**Last updated:** [November 12, 2021, 11:45am UTC](https://discourse.julialang.org/t/terminate-condition-in-continuouscallback-in-differentialequations-jl/69748 "2021-11-12T11:45:09Z")

</div>

using DifferentialEquations u0 = \[1.,0.\] harmonic! = @ode\_def HarmonicOscillator begin dv = -x dx = v end tspan = (0.0,10.0) prob = ODEProblem(harmonic!,u0,tspan) function terminate\_affect!…

---

## [Add comment to generated code file from expressions](https://discourse.julialang.org/t/add-comment-to-generated-code-file-from-expressions/71377)

<div class="topic-metadata">

**Author:** [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Replies:** 0\
**Last updated:** [November 12, 2021, 11:43am UTC](https://discourse.julialang.org/t/add-comment-to-generated-code-file-from-expressions/71377 "2021-11-12T11:43:40Z")

</div>

hellow! How can i add a comment to file with generated code based on expression i use Expr(:line, “comment”) , but it is not a best solution , because julia\> expr = Expr(:line, "comment") :(#= line comment =#)

---

## [Nested static arrays perform worse than nested arrays](https://discourse.julialang.org/t/nested-static-arrays-perform-worse-than-nested-arrays/70938)

<div class="topic-metadata">

**Author:** [@anneJulia](https://discourse.julialang.org/u/anneJulia)\
**Replies:** 14\
**Last updated:** [November 12, 2021, 11:02am UTC](https://discourse.julialang.org/t/nested-static-arrays-perform-worse-than-nested-arrays/70938 "2021-11-12T11:02:24Z")

</div>

I am performing array operations, where I retrieve elements of an array (this array is nested). The functions below are minimal working examples of what I am trying to do. using TimerOutputs using StaticArrays using Sta…

---

## [How to fix an error related to the Effects package](https://discourse.julialang.org/t/how-to-fix-an-error-related-to-the-effects-package/71320)

<div class="topic-metadata">

**Author:** [@Jad](https://discourse.julialang.org/u/Jad)\
**Replies:** 2\
**Last updated:** [November 12, 2021, 10:24am UTC](https://discourse.julialang.org/t/how-to-fix-an-error-related-to-the-effects-package/71320 "2021-11-12T10:24:11Z")

</div>

I want to run the average marginal effects between two predictors: education and unemployment rate. While the package Effects in Julia can do the trick, i am having an error which i will describe below. First, i show the…

---

## [Linear regression from scratch using QR decomposition](https://discourse.julialang.org/t/linear-regression-from-scratch-using-qr-decomposition/71363)

<div class="topic-metadata">

**Author:** [@valperez](https://discourse.julialang.org/u/valperez)\
**Replies:** 3\
**Last updated:** [November 12, 2021, 6:27am UTC](https://discourse.julialang.org/t/linear-regression-from-scratch-using-qr-decomposition/71363 "2021-11-12T06:27:08Z")

</div>

Hi there :slight\_smile: I’m trying to fit a polinomial regression of grade 10 from scratch. First things first, imagine I have a dataset with just two columns, x and y. I want to fit a polinomial of grade 10 but I don’t…

---

## [Using GalacticOptim to optimize, cannot understand the error](https://discourse.julialang.org/t/using-galacticoptim-to-optimize-cannot-understand-the-error/71308)

<div class="topic-metadata">

**Author:** [@yewalenikhil65](https://discourse.julialang.org/u/yewalenikhil65)\
**Replies:** 5\
**Last updated:** [November 12, 2021, 8:39am UTC](https://discourse.julialang.org/t/using-galacticoptim-to-optimize-cannot-understand-the-error/71308 "2021-11-12T08:39:42Z")

</div>

I have a vector of ODE problems that i want to optimize, and here is first odeproblem from the probs array which contains my ODEProblem. I am using GalacticOptim to optimize, but am encountering following error. Some cod…

---

## [Make @chain base Julia](https://discourse.julialang.org/t/make-chain-base-julia/71357)

<div class="topic-metadata">

**Author:** [@Lincoln\_Hannah](https://discourse.julialang.org/u/Lincoln_Hannah)\
**Replies:** 3\
**Last updated:** [November 12, 2021, 6:30am UTC](https://discourse.julialang.org/t/make-chain-base-julia/71357 "2021-11-12T06:30:51Z")

</div>

Instead of having the @chain macro, how about making the previous line’s output always available (if you want it) through “\_” or by omitting the first argument of a function. So you could write something like. 1…

---

## [Understanding dependencies of a package](https://discourse.julialang.org/t/understanding-dependencies-of-a-package/71347)

<div class="topic-metadata">

**Author:** [@affans](https://discourse.julialang.org/u/affans)\
**Replies:** 12\
**Last updated:** [November 12, 2021, 4:51am UTC](https://discourse.julialang.org/t/understanding-dependencies-of-a-package/71347 "2021-11-12T04:51:44Z")

</div>

I am trying to install a package TSAnalysis.jl, which according to its Project.toml only depends on \[deps\] Dates = "ade2ca70-3891-5945-98fb-dc099432e06a" Distributed = "8ba89e20-285c-5b6f-9357-94700520ee1b" Distribution…

---

## [Should @\_\_DIR\_\_ give a path to the directory of the current file?](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303)

<div class="topic-metadata">

**Author:** [@BMval](https://discourse.julialang.org/u/BMval)\
**Replies:** 7\
**Last updated:** [November 12, 2021, 4:43am UTC](https://discourse.julialang.org/t/should-dir-give-a-path-to-the-directory-of-the-current-file/71303 "2021-11-12T04:43:28Z")

</div>

should @DIR give a path to the directory of the current file? pwd() and @DIR give the same result.

---

## [Questions about pyjulia usage](https://discourse.julialang.org/t/questions-about-pyjulia-usage/71332)

<div class="topic-metadata">

**Author:** [@lmiq](https://discourse.julialang.org/u/lmiq)\
**Replies:** 6\
**Last updated:** [November 11, 2021, 10:33pm UTC](https://discourse.julialang.org/t/questions-about-pyjulia-usage/71332 "2021-11-11T22:33:15Z")

</div>

I am trying to see how well a code runs called from python, and I’m facing some problems and have some doubts: When trying to import any package I am getting this error: Your Python interpreter "/usr/bin/python3" is s…

---

## [What is # = none: 1 = # in expression?](https://discourse.julialang.org/t/what-is-none-1-in-expression/71355)

<div class="topic-metadata">

**Author:** [@andrey2185](https://discourse.julialang.org/u/andrey2185)\
**Replies:** 2\
**Last updated:** [November 11, 2021, 11:51pm UTC](https://discourse.julialang.org/t/what-is-none-1-in-expression/71355 "2021-11-11T23:51:41Z")

</div>

Hellow! what is # = none: 4 = #, is it possible to create an expression without this? or is bad idea to generate src-files based on expressions? julia\> ex = quote x = 1 y = 2 x + y …

---

## [Empty iterator](https://discourse.julialang.org/t/empty-iterator/4440)

<div class="topic-metadata">

**Author:** [@pint](https://discourse.julialang.org/u/pint)\
**Replies:** 4\
**Last updated:** [November 11, 2021, 10:47pm UTC](https://discourse.julialang.org/t/empty-iterator/4440 "2021-11-11T22:47:17Z")

</div>

a function of mine returns an iterator. in some cases, i want to return an empty iterator, but one that is efficient and typed. so i came up with this little thing struct Empty{T} end Base.iteratorsize(::Type{\<:Empty}) …

---

## [What's the usual practice about type stability testing in packages?](https://discourse.julialang.org/t/whats-the-usual-practice-about-type-stability-testing-in-packages/64113)

<div class="topic-metadata">

**Author:** [@heliosdrm](https://discourse.julialang.org/u/heliosdrm)\
**Replies:** 2\
**Last updated:** [November 11, 2021, 8:48pm UTC](https://discourse.julialang.org/t/whats-the-usual-practice-about-type-stability-testing-in-packages/64113 "2021-11-11T20:48:31Z")

</div>

Julia developers have utilities to test type stability in their packages, as commented in another post long ago. And new tools that improve it have been released since then, e.g. Cthulhu.jl, or JETTests.jl more recently. …

---

## [Run code non-interactively from script with -e option](https://discourse.julialang.org/t/run-code-non-interactively-from-script-with-e-option/71338)

<div class="topic-metadata">

**Author:** [@mzaffalon](https://discourse.julialang.org/u/mzaffalon)\
**Replies:** 2\
**Last updated:** [November 11, 2021, 8:13pm UTC](https://discourse.julialang.org/t/run-code-non-interactively-from-script-with-e-option/71338 "2021-11-11T20:13:17Z")

</div>

How do I escape correctly the quotation marks in C:\\Users\\mzaffalon\>julia -e 'println("hello world")' on a Windows machine? The line above gives ERROR: syntax: character literal contains multiple characters Stacktrace…

---

## [How to avoid allocations in recursive data structures](https://discourse.julialang.org/t/how-to-avoid-allocations-in-recursive-data-structures/71268)

<div class="topic-metadata">

**Author:** [@peremato](https://discourse.julialang.org/u/peremato)\
**Replies:** 3\
**Last updated:** [November 11, 2021, 4:00pm UTC](https://discourse.julialang.org/t/how-to-avoid-allocations-in-recursive-data-structures/71268 "2021-11-11T16:00:26Z")

</div>

For my project I need a tree-like data structure. Since I didn’t find a way to forward declare types I am using the trick of an abstract type instead of a reference a concrete type. The problem is that when using this da…

---

## [How to programatically construct a ComponentArray or NamedTuple?](https://discourse.julialang.org/t/how-to-programatically-construct-a-componentarray-or-namedtuple/70937)

<div class="topic-metadata">

**Author:** [@amrods](https://discourse.julialang.org/u/amrods)\
**Replies:** 5\
**Last updated:** [November 11, 2021, 3:22pm UTC](https://discourse.julialang.org/t/how-to-programatically-construct-a-componentarray-or-namedtuple/70937 "2021-11-11T15:22:48Z")

</div>

As the title says, how can I programatically construct a ComponentArray or NamedTuple from a vector of strings (or symbols) and a vector of numbers? from this n = \["a", "b", "c"\] x = \[1, 2, 3\] I want to get this ca =…

---

## [Optional arguments of subtype](https://discourse.julialang.org/t/optional-arguments-of-subtype/71333)

<div class="topic-metadata">

**Author:** [@Kruxigt](https://discourse.julialang.org/u/Kruxigt)\
**Replies:** 2\
**Last updated:** [November 11, 2021, 2:55pm UTC](https://discourse.julialang.org/t/optional-arguments-of-subtype/71333 "2021-11-11T14:55:12Z")

</div>

Hi good folks! Quick question which I’m sure has been answered many times but which’s answers I can’t find. Can I specify a subtype for an optional argument. Something similar to: function f(a::Int64, b::T=10) where T\<…

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

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