# Questions(ss) about function import and type, parsing, OCaml code importing, compiling and regex syntax

**URL:** <https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241>\
**Category:** New to Julia\
**Created:** [March 23, 2019, 10:44am UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241 "2019-03-23T10:44:30Z")\
**Posts on this page:** 12\
**Page:** 1

<div class="post-metadata">

**Author:** ![maestox](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@maestox](https://discourse.julialang.org/u/maestox)\
**Post date:** [March 23, 2019, 10:44am UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/1 "2019-03-23T10:44:30Z")

</div>

Hi !

[If you don’t understand my english, tell me, it may be normal 😛]

I’ve some beginner questions (again). But certainly I don’t understand because I don’t understand the Julia’s behaviour. I’ve some knows about programming language (i’ve already made a little compiler, but that was some years ago).

- What do we need to import functions in order to extend them ? If we can call them, that means their name are known, no ? So, what can’t you extend them ? What is the Julia’s behaviour ?

- What about the functions type ? `typeof(f)` tells me `typeof(f)`. If I’ve well understood, that’s because each function has its own type, and all the “functions” are methods. That means that I can’t tell, in some syntax `example(f::Function{Int64,Int64}, arg::Int64) = f(x+1) - 1` which `Function{Int64,Int64}` is the function type `Int64 -> Int64` ?  
(in fact, i’ve seen that seem to exists some ways to do this in the doc, but I havn’t understood)

- Does there exist tools in order to do syntax analysis in Julia ? (to make a parser, as Menhir in OCaml) If no, is it possible to “import” OCaml code ? (i’ve seen it’s possible with at least C and Python code)

- In a similar way, does there exist in Julia a package to manage the “inputs/parameters” of my program ? In example : `julia myprogram.jl -o output -g parameter`, a package which simplify the managing of the `-o output` and the `-g parameter` ?

- Is it possible to “compile” Julia ? To make an executable, which would work without the Julia interpretor ?

- I havn’t found the supported regex syntax in Julia. I’ve searched in the PCRE Ruby doc, but I havn’t found yet : is it somewhere ?

I think it’s all ! Thanks for reading and mayber answering ! (and thanks another time to the Julia’s developpers 😃 )

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [March 23, 2019, 12:46pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/2 "2019-03-23T12:46:00Z")

</div>

Some answers for the questions I know:

- can you compile —\> yes up to a certain extent, check out BinaryBuilder.jl and PackageCompiler.jl ([GitHub - JuliaPackaging/BinaryBuilder.jl: Binary Dependency Builder for Julia](https://github.com/JuliaPackaging/BinaryBuilder.jl),  
[https://github.com/JuliaLang/PackageCompiler.jl](https://github.com/JuliaLang/PackageCompiler.jl))
- function type is `Function` to the best of my knowledge there is no direct way to have a function type including argument/output types so something like `Function{Int64,Int64}` this has been discussed but probably someone with better knowledge may be able to give better pointers
- regex, yes try `Regex(...)` to define a pattern (or `r“...”`) and functions like `match`, `eachmatch`, `replace` etc see also the docs: [Strings · The Julia Language](https://docs.julialang.org/en/v1/manual/strings/index.html)

For the other questions, I didn’t understand the first one, the one on OCaml I think the answer is « no », and the question about arguments you might want to consider [ArgParse — Module for command-line argument parsing — ArgParse.jl package for the Julia language 0.3 documentation](https://argparsejl.readthedocs.io/en/latest/argparse.html) but others may give better input

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 23, 2019, 1:48pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/3 "2019-03-23T13:48:48Z")

</div>

Regarding the first two questions:

1. nope, you don’t need to `import` to define a method, you can also quality a name, eg

2. See [this discussion](https://discourse.julialang.org/t/functions-and-code-warntype/16734) about function types for pointers.

---

<div class="post-metadata">

**Author:** ![maestox](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@maestox](https://discourse.julialang.org/u/maestox)\
**Post date:** [March 23, 2019, 4:01pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/4 "2019-03-23T16:01:05Z")

</div>

- Thanks, that seems to do what I want !
- ok 🙂
- I meant that I wanted the abstract syntax of the right regex in Julia language. It seemed to me that there could be little differences in the regex syntax among the languages. Am I wrong ?

---

<div class="post-metadata">

**Author:** ![maestox](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@maestox](https://discourse.julialang.org/u/maestox)\
**Post date:** [March 23, 2019, 4:02pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/5 "2019-03-23T16:02:49Z")

</div>

- What is the hidden behaviour of Julia indeed ?

- Errr, this discussion is a little bit empty, linkless. If I ask, that means that I didn’t find answers, and I don’t have really time in order to read a thesis.

---

<div class="post-metadata">

**Author:** ![rdeits](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/rdeits/32/286_2.png) [@rdeits](https://discourse.julialang.org/u/rdeits)\
**Post date:** [March 23, 2019, 4:15pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/6 "2019-03-23T16:15:15Z")

</div>

> [@maestox](#):
>
> That means that I can’t tell, in some syntax `example(f::Function{Int64,Int64}, arg::Int64) = f(x+1) - 1` which `Function{Int64,Int64}` is the function type `Int64 -> Int64` ?

Correct, that’s not a feature of Julia right now. In most cases, we deal with this by [duck-typing](https://en.wikipedia.org/wiki/Duck_typing) (that is, just accepting any function and throwing an error later on if it turns out to not accept the desired type).

If you really need to specify a particular method with specific input and output types, consider [GitHub - yuyichao/FunctionWrappers.jl](https://github.com/yuyichao/FunctionWrappers.jl)

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 23, 2019, 4:49pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/7 "2019-03-23T16:49:38Z")

</div>

> [@maestox](#):
>
> I don’t have really time in order to read a thesis

Yet the people who answered your questions had time to read them, even though you put 5 of them in a single topic.

Some questions don’t have single-paragraph answers.

---

<div class="post-metadata">

**Author:** ![Tamas\_Papp](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tamas_papp/32/25949_2.png) [@Tamas\_Papp](https://discourse.julialang.org/u/Tamas_Papp)\
**Post date:** [March 23, 2019, 4:54pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/8 "2019-03-23T16:54:11Z")

</div>

> [@maestox](#):
>
> What is the hidden behaviour of Julia indeed ?

If you are referring to either explicit import or qualified method names, it has a simple explanation.

Consider

```julia
module Foo
using Bar # has no function baz
baz() = 1
end

```

Now imagine that the developers of `Bar` introduce their own function `baz` and export it. From that point you would be adding/overwriting methods to that, which can lead to bugs (search for type piracy).

**EDIT** I just realized that this is [covered in the FAQ](https://docs.julialang.org/en/v1/manual/faq/#What-is-the-difference-between-%22using%22-and-%22import%22?-1).

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [March 23, 2019, 8:55pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/9 "2019-03-23T20:55:55Z")

</div>

From the doc I linked to, first paragraph of the regex section:

> Julia has Perl-compatible regular expressions (regexes), as provided by the [PCRE](http://www.pcre.org/) library.

---

<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:** [March 23, 2019, 9:43pm UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/10 "2019-03-23T21:43:43Z")

</div>

This page has the PCRE syntax:

[http://www.pcre.org/current/doc/html/pcre2syntax.html](http://www.pcre.org/current/doc/html/pcre2syntax.html)

If anyone feels like making a contribution, adding a direct link to that to the docs would be great.

---

<div class="post-metadata">

**Author:** ![tlienart](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/tlienart/32/7640_2.png) [@tlienart](https://discourse.julialang.org/u/tlienart)\
**Post date:** [March 24, 2019, 1:38am UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/11 "2019-03-24T01:38:57Z")

</div>

[done](https://github.com/JuliaLang/julia/pull/31463).

---

<div class="post-metadata">

**Author:** ![maestox](https://avatars.discourse-cdn.com/v4/letter/m/cdc98d/32.png) [@maestox](https://discourse.julialang.org/u/maestox)\
**Post date:** [March 24, 2019, 10:40am UTC](https://discourse.julialang.org/t/questions-ss-about-function-import-and-type-parsing-ocaml-code-importing-compiling-and-regex-syntax/22241/12 "2019-03-24T10:40:28Z")

</div>

Thanks ! It’s exactly what I searched !
