# New to Julia

**URL:** https://discourse.julialang.org/c/first-steps/8.md?page=71

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

**Page:** 72

---

## [Type system abuse, advisability of](https://discourse.julialang.org/t/type-system-abuse-advisability-of/103390)

<div class="topic-metadata">

**Author:** [@deaminase](https://discourse.julialang.org/u/deaminase)\
**Replies:** 17\
**Last updated:** [August 31, 2023, 4:25pm UTC](https://discourse.julialang.org/t/type-system-abuse-advisability-of/103390 "2023-08-31T16:25:36Z")

</div>

Part of my learning process with Julia has been to abuse the type system in various fun ways to see what’s possible. My latest monstrosity uses type parameters for partial application of functions: module TypeAbuse stru…

---

## [How to solve the error while loading saved chain as JLD2 file or JLS file?](https://discourse.julialang.org/t/how-to-solve-the-error-while-loading-saved-chain-as-jld2-file-or-jls-file/36031)

<div class="topic-metadata">

**Author:** [@Manu\_Francis](https://discourse.julialang.org/u/Manu_Francis)\
**Replies:** 6\
**Last updated:** [August 31, 2023, 1:52pm UTC](https://discourse.julialang.org/t/how-to-solve-the-error-while-loading-saved-chain-as-jld2-file-or-jls-file/36031 "2023-08-31T13:52:39Z")

</div>

Hi, I have saved the chain that generated using Turing package as below: using JLD2, FileIO using Turing # Set the true probability of heads in a coin. p\_true = 0.5 # Iterate from having seen 0 observations t…

---

## [How to correctly set a WHILE loop in Julia?](https://discourse.julialang.org/t/how-to-correctly-set-a-while-loop-in-julia/103379)

<div class="topic-metadata">

**Author:** [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Replies:** 4\
**Last updated:** [August 31, 2023, 5:52am UTC](https://discourse.julialang.org/t/how-to-correctly-set-a-while-loop-in-julia/103379 "2023-08-31T05:52:49Z")

</div>

Hello, I would like to set a loop to get information from the user from console. The loop should run until the user says otherwise. I have prepared this script: ANS = "N" while ANS == "N" # get data println("…

---

## [Update Julia in Ubuntu 22](https://discourse.julialang.org/t/update-julia-in-ubuntu-22/103376)

<div class="topic-metadata">

**Author:** [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Replies:** 4\
**Last updated:** [August 31, 2023, 1:54am UTC](https://discourse.julialang.org/t/update-julia-in-ubuntu-22/103376 "2023-08-31T01:54:08Z")

</div>

Hello, I am running a julia file from console in Ubuntu 22 but I got this error: $ julia natParmsInput.jl The latest version of Julia in the \`release\` channel is 1.9.3+0.x64.linux.gnu. You currently have \`1.9.0+0.x64.…

---

## [What determines if integers are formatted as hex or not in the REPL?](https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386)

<div class="topic-metadata">

**Author:** [@frylock](https://discourse.julialang.org/u/frylock)\
**Replies:** 3\
**Last updated:** [August 30, 2023, 8:58pm UTC](https://discourse.julialang.org/t/what-determines-if-integers-are-formatted-as-hex-or-not-in-the-repl/103386 "2023-08-30T20:58:48Z")

</div>

Why is one printed as hex and the other not? Also, why does the line number not increase after the first assignment? (doesn’t seem to always do that - just noticed it) \_ \_ \_(\_)\_ | Documentation: https://d…

---

## [Simple compile-time evaluation for struct types](https://discourse.julialang.org/t/simple-compile-time-evaluation-for-struct-types/103326)

<div class="topic-metadata">

**Author:** [@RPS](https://discourse.julialang.org/u/RPS)\
**Replies:** 3\
**Last updated:** [August 30, 2023, 11:58am UTC](https://discourse.julialang.org/t/simple-compile-time-evaluation-for-struct-types/103326 "2023-08-30T11:58:38Z")

</div>

I have a nested struct similar to the following: struct A{N1, N2, T} a1::SVector{N1, T} a2::SVector{N2, T} b::B{N1, N2, T} end N1 and N2 are integers satisfying some simple (known) relationship, e.g. N2=N1+1. The…

---

## [Julia Nightly fails with an error on overwritten method](https://discourse.julialang.org/t/julia-nightly-fails-with-an-error-on-overwritten-method/103358)

<div class="topic-metadata">

**Author:** [@dmitry-kabanov](https://discourse.julialang.org/u/dmitry-kabanov)\
**Replies:** 3\
**Last updated:** [August 30, 2023, 3:53pm UTC](https://discourse.julialang.org/t/julia-nightly-fails-with-an-error-on-overwritten-method/103358 "2023-08-30T15:53:38Z")

</div>

I need to work with someone else’s code repository and I have zero experience in Julia (although I know how to program). This code repository runs workflows on GitHub Actions, and one of the workflows that runs under Jul…

---

## [Is there a good tutorial for using JSON in Julia?](https://discourse.julialang.org/t/is-there-a-good-tutorial-for-using-json-in-julia/103356)

<div class="topic-metadata">

**Author:** [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Replies:** 3\
**Last updated:** [August 30, 2023, 11:24am UTC](https://discourse.julialang.org/t/is-there-a-good-tutorial-for-using-json-in-julia/103356 "2023-08-30T11:24:27Z")

</div>

Hello, I am starting to learn how to use JSON in Julia. I can create a json object, for sinatcne: jsJ = JSON.json(Dict("name"=\>\["Paul", "Peter", "Jude", "Mark"\], "level"=\>\[1, 10, 20, 30\], "code"=\>\["Pa", "Pe", "…

---

## [Element wise multiplication of lower triangular matrices](https://discourse.julialang.org/t/element-wise-multiplication-of-lower-triangular-matrices/103252)

<div class="topic-metadata">

**Author:** [@ahmed](https://discourse.julialang.org/u/ahmed)\
**Replies:** 17\
**Last updated:** [August 29, 2023, 6:20pm UTC](https://discourse.julialang.org/t/element-wise-multiplication-of-lower-triangular-matrices/103252 "2023-08-29T18:20:32Z")

</div>

I’m confused by how the element wise multiplication of lower triangular matrices is not faster than the element wise multiplication of the completely full matrices. This behavior is shown in the following MWE using Line…

---

## [How to add/create/use submodules?](https://discourse.julialang.org/t/how-to-add-create-use-submodules/103329)

<div class="topic-metadata">

**Author:** [@frylock](https://discourse.julialang.org/u/frylock)\
**Replies:** 5\
**Last updated:** [August 29, 2023, 1:40pm UTC](https://discourse.julialang.org/t/how-to-add-create-use-submodules/103329 "2023-08-29T13:40:59Z")

</div>

In the documentation for modules, I understand that the name of a module (or submodule) does not necessarily have to be the same as the module name - since the module name is a namespace. I’m having trouble loading a sub…

---

## [How to extract pvalue?](https://discourse.julialang.org/t/how-to-extract-pvalue/103327)

<div class="topic-metadata">

**Author:** [@Sahil\_Khan](https://discourse.julialang.org/u/Sahil_Khan)\
**Replies:** 1\
**Last updated:** [August 29, 2023, 12:33pm UTC](https://discourse.julialang.org/t/how-to-extract-pvalue/103327 "2023-08-29T12:33:24Z")

</div>

Hello i’m using EqualVarianceTTest() from HypothesisTests.jl. I did test and it gives a summary report but i don’t know how can i extract some specific values from summary? such as p-value in case i want to do several…

---

## [Cronbach's alpha StatsBase](https://discourse.julialang.org/t/cronbachs-alpha-statsbase/103292)

<div class="topic-metadata">

**Author:** [@victorshiramizu](https://discourse.julialang.org/u/victorshiramizu)\
**Replies:** 8\
**Last updated:** [August 29, 2023, 11:26am UTC](https://discourse.julialang.org/t/cronbachs-alpha-statsbase/103292 "2023-08-29T11:26:05Z")

</div>

I’m trying to calculate Cronbach’s alpha via cronbachalpha function from StatsBase. I’m getting the following error: ERROR: MethodError: no method matching cronbachalpha(::Matrix{Union{Missing, Float64}}). However, my ma…

---

## [Implement two variants of a simulation which works with the same objects](https://discourse.julialang.org/t/implement-two-variants-of-a-simulation-which-works-with-the-same-objects/103321)

<div class="topic-metadata">

**Author:** [@natema](https://discourse.julialang.org/u/natema)\
**Replies:** 2\
**Last updated:** [August 29, 2023, 9:17am UTC](https://discourse.julialang.org/t/implement-two-variants-of-a-simulation-which-works-with-the-same-objects/103321 "2023-08-29T09:17:03Z")

</div>

I want to simulate two variants of a process that involves the same objects (e.g. a stochastic process on the unit interval \[0,1) or on the circle \\mathbb R/\\mathbb Z). For the first variant, I’ve grouped the objects de…

---

## [Is there a function in Julia similar to Python's \`tell\`?](https://discourse.julialang.org/t/is-there-a-function-in-julia-similar-to-pythons-tell/103308)

<div class="topic-metadata">

**Author:** [@frylock](https://discourse.julialang.org/u/frylock)\
**Replies:** 3\
**Last updated:** [August 28, 2023, 8:09pm UTC](https://discourse.julialang.org/t/is-there-a-function-in-julia-similar-to-pythons-tell/103308 "2023-08-28T20:09:57Z")

</div>

In addition to seek on open files, Python has a tell function … so I could save my place in a file and go back to it? Perhaps I am going about things wrong. What I’m really trying to do is read in a structure from a fil…

---

## [Custom iterator failed](https://discourse.julialang.org/t/custom-iterator-failed/103301)

<div class="topic-metadata">

**Author:** [@Denis\_Ivanov](https://discourse.julialang.org/u/Denis_Ivanov)\
**Replies:** 12\
**Last updated:** [August 28, 2023, 6:41pm UTC](https://discourse.julialang.org/t/custom-iterator-failed/103301 "2023-08-28T18:41:41Z")

</div>

Here is very simple idea: struct Test a::Int n::Int end step(x::Int) = x \> 1 ? x - 1 : 1 Base.iterate(t::Test, state=1) = state \> t.n ? nothing : (step(t.a), state + 1) Base.length(t::Test) = t.n For some …

---

## [Rownumber() in Dataframe like SQL](https://discourse.julialang.org/t/rownumber-in-dataframe-like-sql/72098)

<div class="topic-metadata">

**Author:** [@AlexanderChen](https://discourse.julialang.org/u/AlexanderChen)\
**Replies:** 9\
**Last updated:** [August 28, 2023, 4:21pm UTC](https://discourse.julialang.org/t/rownumber-in-dataframe-like-sql/72098 "2023-08-28T16:21:36Z")

</div>

Hi, In SQL you have a function called rownumber() over which you partition a certain column and get a column from 1 …n. Like this: dataframes has a function called rownumber but it only return an integer in specific…

---

## [How to parse text between specific characters in Julia?](https://discourse.julialang.org/t/how-to-parse-text-between-specific-characters-in-julia/103284)

<div class="topic-metadata">

**Author:** [@Luigi\_Marongiu](https://discourse.julialang.org/u/Luigi_Marongiu)\
**Replies:** 3\
**Last updated:** [August 28, 2023, 3:01pm UTC](https://discourse.julialang.org/t/how-to-parse-text-between-specific-characters-in-julia/103284 "2023-08-28T15:01:16Z")

</div>

Hello, I would like to create a text files (a plain text txt or a tab-separated file tsv) with modular information. I have been thinking of including the information within some markers, for instance \*= and =\* so that t…

---

## [Distributed computing and wasm](https://discourse.julialang.org/t/distributed-computing-and-wasm/103178)

<div class="topic-metadata">

**Author:** [@ShalokShalom](https://discourse.julialang.org/u/ShalokShalom)\
**Replies:** 4\
**Last updated:** [August 28, 2023, 12:57am UTC](https://discourse.julialang.org/t/distributed-computing-and-wasm/103178 "2023-08-28T00:57:15Z")

</div>

I am saying this as a complete starter to newbie. I am interested about this platform: https://lunatic.solutions/ It basically turns every WASM capable language into an actor language. That means, you do not need to c…

---

## [Get iterator "from:to"](https://discourse.julialang.org/t/get-iterator-from-to/103259)

<div class="topic-metadata">

**Author:** [@Denis\_Ivanov](https://discourse.julialang.org/u/Denis_Ivanov)\
**Replies:** 6\
**Last updated:** [August 27, 2023, 7:17pm UTC](https://discourse.julialang.org/t/get-iterator-from-to/103259 "2023-08-27T19:17:18Z")

</div>

Hi, sorry for naive question. I’ve read carefully about iterators , but is there a straightforward method to get “from n to m” elements of iterator, without such as rest(take(iter, m), n)? NB I use complicated generi…

---

## [Can't install any packages with Pkg.jl](https://discourse.julialang.org/t/cant-install-any-packages-with-pkg-jl/103235)

<div class="topic-metadata">

**Author:** [@ssghost](https://discourse.julialang.org/u/ssghost)\
**Replies:** 2\
**Last updated:** [August 27, 2023, 2:17am UTC](https://discourse.julialang.org/t/cant-install-any-packages-with-pkg-jl/103235 "2023-08-27T02:17:40Z")

</div>

OS: MacOSX 12.6 Julia VersionInfo: Julia Version 1.8.5 Commit 17cfb8e65ea (2023-01-08 06:45 UTC) After I typed “\] add \<package\_name\>” in REPL it will always return an Unsatisfiable requirements Error, for example this…

---

## [Private and protected attributes in OOP](https://discourse.julialang.org/t/private-and-protected-attributes-in-oop/103104)

<div class="topic-metadata">

**Author:** [@ahmed-desoki](https://discourse.julialang.org/u/ahmed-desoki)\
**Replies:** 8\
**Last updated:** [August 26, 2023, 2:47pm UTC](https://discourse.julialang.org/t/private-and-protected-attributes-in-oop/103104 "2023-08-26T14:47:05Z")

</div>

Dear folks I want to switch OOP from C++ to Julia. Please guide what is the Julia way of OOP? In OOP in C++, classes can have member variables, or properties. These properties can have attributes like “private” or “pro…

---

## [Faster way for matrix multiplication including a Hermitian matrix with special properties](https://discourse.julialang.org/t/faster-way-for-matrix-multiplication-including-a-hermitian-matrix-with-special-properties/103177)

<div class="topic-metadata">

**Author:** [@ahmed](https://discourse.julialang.org/u/ahmed)\
**Replies:** 6\
**Last updated:** [August 26, 2023, 2:38pm UTC](https://discourse.julialang.org/t/faster-way-for-matrix-multiplication-including-a-hermitian-matrix-with-special-properties/103177 "2023-08-26T14:38:40Z")

</div>

I have a simple question that I hope can make certain kinds of matrix multiplications faster in my code. Is there a way to make use of matrix multiplications that are of the form phi\*P\*adjoint(phi) to make the computati…

---

## [The repetition of results](https://discourse.julialang.org/t/the-repetition-of-results/103026)

<div class="topic-metadata">

**Author:** [@R0033h](https://discourse.julialang.org/u/R0033h)\
**Replies:** 4\
**Last updated:** [August 26, 2023, 8:47am UTC](https://discourse.julialang.org/t/the-repetition-of-results/103026 "2023-08-26T08:47:14Z")

</div>

I am encountering issues with the repetition of results in this code (in the terminal) I saw each result 4 times. May the problem i used the same sorted\_dic i am not sure. I wrote for q in 1:4 # number of school sta…

---

## [How to get a matrix anti-diagonal?](https://discourse.julialang.org/t/how-to-get-a-matrix-anti-diagonal/103202)

<div class="topic-metadata">

**Author:** [@jcbritobr](https://discourse.julialang.org/u/jcbritobr)\
**Replies:** 6\
**Last updated:** [August 25, 2023, 7:49pm UTC](https://discourse.julialang.org/t/how-to-get-a-matrix-anti-diagonal/103202 "2023-08-25T19:49:01Z")

</div>

Hello, good afternoon. How to get an offdiagonal from a square matrix? I have diag function for the diagonal but how to acquire the below? A = \[1 2; 3 4\] offd(A) result -\> \[2, 3\]

---

## [Saving Simulation and Truncating Values in Memory](https://discourse.julialang.org/t/saving-simulation-and-truncating-values-in-memory/103095)

<div class="topic-metadata">

**Author:** [@yoshi](https://discourse.julialang.org/u/yoshi)\
**Replies:** 4\
**Last updated:** [August 25, 2023, 6:42pm UTC](https://discourse.julialang.org/t/saving-simulation-and-truncating-values-in-memory/103095 "2023-08-25T18:42:29Z")

</div>

I have a long simulation. I’m trying to find a way to save the values of my simulation to disk and truncate the values held in memory. My guess is to use a callback. So far I have: using MAT function save\_and\_clea…

---

## [Reading binary file to Julia](https://discourse.julialang.org/t/reading-binary-file-to-julia/103151)

<div class="topic-metadata">

**Author:** [@marianoarnaiz](https://discourse.julialang.org/u/marianoarnaiz)\
**Replies:** 10\
**Last updated:** [August 25, 2023, 10:53am UTC](https://discourse.julialang.org/t/reading-binary-file-to-julia/103151 "2023-08-25T10:53:09Z")

</div>

Hi all. I have a binary file that I need to load to julia. I have a python scrip that reads it, can anyone help me a bit to turn this to julia, it is not working for me # omit the first 4 values (header information)…

---

## [Multiple package dependencies consistently fail to compile](https://discourse.julialang.org/t/multiple-package-dependencies-consistently-fail-to-compile/102956)

<div class="topic-metadata">

**Author:** [@FHeslop](https://discourse.julialang.org/u/FHeslop)\
**Replies:** 19\
**Last updated:** [August 24, 2023, 3:15pm UTC](https://discourse.julialang.org/t/multiple-package-dependencies-consistently-fail-to-compile/102956 "2023-08-24T15:15:10Z")

</div>

Hello Julia community, I’m new to Julia and relatively new to programming. I am trying to use packages (namely CSVFiles and DataFrames). At the simplest level however, when adding and precompiling these packages in the…

---

## [Assistance in speeding up Array operations and summations](https://discourse.julialang.org/t/assistance-in-speeding-up-array-operations-and-summations/102989)

<div class="topic-metadata">

**Author:** [@ahmed](https://discourse.julialang.org/u/ahmed)\
**Replies:** 12\
**Last updated:** [August 23, 2023, 12:01pm UTC](https://discourse.julialang.org/t/assistance-in-speeding-up-array-operations-and-summations/102989 "2023-08-23T12:01:00Z")

</div>

I have a problem where I have arrays of matrices that I do operations on and then sum the result. I wonder if I can optimize this part of my code as it will be used repeatedly. Please find below an MWE that reproduces my…

---

## [Dual y axis appears on the same side in a Pluto notebook with Plots](https://discourse.julialang.org/t/dual-y-axis-appears-on-the-same-side-in-a-pluto-notebook-with-plots/99240)

<div class="topic-metadata">

**Author:** [@PeX](https://discourse.julialang.org/u/PeX)\
**Replies:** 4\
**Last updated:** [August 23, 2023, 12:29am UTC](https://discourse.julialang.org/t/dual-y-axis-appears-on-the-same-side-in-a-pluto-notebook-with-plots/99240 "2023-08-23T00:29:15Z")

</div>

I’m trying to make a plot with dual y axis using Plots in a Pluto notebook. begin plot(randn(100), ylabel="y1", leg=:topright) plot!(twinx(), randn(100)\*10, c=:red, ylabel="y2", leg=:bottomright, size=(6…

---

## [Warning: Method definition f(Any) overwritten](https://discourse.julialang.org/t/warning-method-definition-f-any-overwritten/103060)

<div class="topic-metadata">

**Author:** [@afyon](https://discourse.julialang.org/u/afyon)\
**Replies:** 10\
**Last updated:** [August 22, 2023, 10:45pm UTC](https://discourse.julialang.org/t/warning-method-definition-f-any-overwritten/103060 "2023-08-22T22:45:17Z")

</div>

Hi everyone, I am trying to make a function that would look like this: function create\_f(flag::Bool) if flag f(x) = x^2 else f(x) = x^3 end return f end And, when I create this function, I got …

[Previous page](https://discourse.julialang.org/c/first-steps/8.md?page=70)

[Next page](https://discourse.julialang.org/c/first-steps/8.md?page=72)
