# \[Translating\] from Pascal to Julia

**URL:** <https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184>\
**Category:** General Usage\
**Tags:** question\
**Created:** [October 3, 2022, 7:54pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184 "2022-10-03T19:54:02Z")\
**Posts on this page:** 20\
**Page:** 1

<div class="post-metadata">

**Author:** ![fabbius69](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabbius69/32/43200_2.png) [@fabbius69](https://discourse.julialang.org/u/fabbius69)\
**Post date:** [October 3, 2022, 7:54pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/1 "2022-10-03T19:54:02Z")

</div>

is it possible to have similar code in julia?  
thanks

“type  
lo=array[1…5,1…10]of smallint;  
nom=string[25];  
lot=record  
num:lo;  
ind:smallint;  
anno:smallint;  
mese:string[15];  
end;  
fi=file of lot;  
var  
f2,f3:fi;”

---

<div class="post-metadata">

**Author:** ![StefanKarpinski](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/stefankarpinski/32/24_2.png) [@StefanKarpinski](https://discourse.julialang.org/u/StefanKarpinski)\
**Post date:** [October 3, 2022, 7:59pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/2 "2022-10-03T19:59:21Z")

</div>

I think you’re going to have to explain what that code does in order to get a helpful answer to your question.

---

<div class="post-metadata">

**Author:** ![fabbius69](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabbius69/32/43200_2.png) [@fabbius69](https://discourse.julialang.org/u/fabbius69)\
**Post date:** [October 3, 2022, 8:51pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/3 "2022-10-03T20:51:49Z")

</div>

binary file composed of structures, each structure is composed of variables and a 5X10 matrix.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 3, 2022, 8:52pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/4 "2022-10-03T20:52:57Z")

</div>

You want to write a series of binary records with a certain format, and read it back in?

---

<div class="post-metadata">

**Author:** ![fabbius69](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabbius69/32/43200_2.png) [@fabbius69](https://discourse.julialang.org/u/fabbius69)\
**Post date:** [October 3, 2022, 8:54pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/5 "2022-10-03T20:54:11Z")

</div>

yes yes

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 3, 2022, 8:54pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/6 "2022-10-03T20:54:34Z")

</div>

@fabbius69 yes, you could have an exact translation, or similar, here partially similar I think:

```julia
struct lo
  lo::Array{Int16, 2} # You can have static arrays with (5, 10) dimensions using StaticArrys.jl package, but might not be needed, unless you want to read a specific format.
  nom::String # It's better to not limit length of the strings, not needed.
end

struct lot
  num::lo # This isn't really helpful to split across structures, unless you want here an Array of lo.
  ind::Int16
  anno::Int16
  mese::String
end

Something like:
julia> x = lot(lo([1 2; 3 4], "test"), 1, 1, "Palli")

julia> using FileIO
julia> save("example.jld2", "x", x) # this was a bit slower then with Serialization, but likely just on first use.

or alternatively:
julia> using Serialization
julia> open(f -> serialize(f,x), "x.jls", "w")

```

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 3, 2022, 8:54pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/7 "2022-10-03T20:54:53Z")

</div>

Does it have to have a certain format because compatibility with other software, or do you just want to be able to read and write stuff to a file in some format?

---

<div class="post-metadata">

**Author:** ![fabbius69](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabbius69/32/43200_2.png) [@fabbius69](https://discourse.julialang.org/u/fabbius69)\
**Post date:** [October 3, 2022, 8:57pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/8 "2022-10-03T20:57:25Z")

</div>

thanks, but how do I create the file to be stored with this structure?

---

<div class="post-metadata">

**Author:** ![greatpet](https://avatars.discourse-cdn.com/v4/letter/g/e495f1/32.png) [@greatpet](https://discourse.julialang.org/u/greatpet)\
**Post date:** [October 3, 2022, 8:57pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/9 "2022-10-03T20:57:33Z")

</div>

(1) Julia arrays have dynamic sizes. The size is not part of the type of the array, unlike in Pascal. Statically-sized arrays, when needed for specific purposes, are available from the package StaticArrays.jl.

(2) The size of a string in Julia is not part of its type, either.

(3) Pascal’s `smallint` is Julia’s `Int16`. Pascal’s `record` is roughly Julia’s `struct`.

(4) Julia does not have a file type for storing data of a single type. Instead you use a more “dynamically typed” standard library called `Serialization`.

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 3, 2022, 8:59pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/10 "2022-10-03T20:59:41Z")

</div>

You might want to use JLD2.jl package rather than `Serialization`, though the latter is built-in…

---

<div class="post-metadata">

**Author:** ![fabbius69](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabbius69/32/43200_2.png) [@fabbius69](https://discourse.julialang.org/u/fabbius69)\
**Post date:** [October 3, 2022, 9:01pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/11 "2022-10-03T21:01:48Z")

</div>

I create a database by entering this data from time to time, over time the data increases. I often read all the data and store them in array structures and do some processing.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 3, 2022, 9:02pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/12 "2022-10-03T21:02:17Z")

</div>

> [@dlakelan](#):
>
> certain format because compatibility with other software

If you have to be able to read files in a specific binary format that exist already and convert them into Julia structs… this is a more difficult task. If you are free to read and write any format, then Serialization library is I think the way to go.

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [October 3, 2022, 9:04pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/13 "2022-10-03T21:04:46Z")

</div>

`Serialization` format is not stable across versions, so it is not suitable for storing data for long periods.

Edit: Incorrect, see below

---

<div class="post-metadata">

**Author:** ![fabbius69](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabbius69/32/43200_2.png) [@fabbius69](https://discourse.julialang.org/u/fabbius69)\
**Post date:** [October 3, 2022, 9:05pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/14 "2022-10-03T21:05:22Z")

</div>

where I find a guide on the Serialization library

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 3, 2022, 9:05pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/15 "2022-10-03T21:05:46Z")

</div>

> [@jar1](#):
>
> not suitable for storing data for long periods

Well it is guaranteed that later Julia versions may read data produced by older Julia versions…

---

<div class="post-metadata">

**Author:** ![jar1](https://avatars.discourse-cdn.com/v4/letter/j/c0e974/32.png) [@jar1](https://discourse.julialang.org/u/jar1)\
**Post date:** [October 3, 2022, 9:06pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/16 "2022-10-03T21:06:26Z")

</div>

Ah you’re right

> The data format can change in minor (1.x) Julia releases, but files written by prior 1.x versions will remain readable.

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 3, 2022, 9:06pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/17 "2022-10-03T21:06:33Z")

</div>

> [@fabbius69](#):
>
> guide on the Serialization library

[https://docs.julialang.org/en/v1/stdlib/Serialization/](https://docs.julialang.org/en/v1/stdlib/Serialization/)

---

<div class="post-metadata">

**Author:** ![dlakelan](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/dlakelan/32/8491_2.png) [@dlakelan](https://discourse.julialang.org/u/dlakelan)\
**Post date:** [October 3, 2022, 9:09pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/18 "2022-10-03T21:09:50Z")

</div>

> [@jar1](#):
>
> files written by prior 1.x versions will remain readable.

yes, the big issue is if you need to send data to someone running an older Julia version.

Another option is to write the data to Arrow or Parquet formats… Arrow is good for writing binary data in large quantities and reading it in super fast. Parquet is more for compressed long term storage.

---

<div class="post-metadata">

**Author:** ![fabbius69](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/fabbius69/32/43200_2.png) [@fabbius69](https://discourse.julialang.org/u/fabbius69)\
**Post date:** [October 3, 2022, 9:25pm UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/19 "2022-10-03T21:25:51Z")

</div>

> [@Palli](#):
>
> `FileIO`

a guide for FileIO?  
thanks

---

<div class="post-metadata">

**Author:** ![Palli](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/palli/32/3380_2.png) [@Palli](https://discourse.julialang.org/u/Palli)\
**Post date:** [October 4, 2022, 8:03am UTC](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184/20 "2022-10-04T08:03:14Z")

</div>

Yes, in general it’s best to add .jl to package names (inbuilt Julia modules should be documented in the Julia manual) when googling:

> julia FileIO.jl

and from there click on docs. At least this package has good docs, and you could have rather done `using JLD2`, and that package might have the docs…

[Next page](https://discourse.julialang.org/t/translating-from-pascal-to-julia/88184.md?page=2)
