# Fastest way to define high-level functions in a text file and use them in Julia after processing?

**URL:** https://discourse.julialang.org/t/fastest-way-to-define-high-level-functions-in-a-text-file-and-use-them-in-julia-after-processing/136061
**Category:** General Usage
**Created:** [March 6, 2026, 7:42am UTC](https://discourse.julialang.org/t/fastest-way-to-define-high-level-functions-in-a-text-file-and-use-them-in-julia-after-processing/136061 "2026-03-06T07:42:12Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![abhinavr](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/abhinavr/32/221103_2.png) [@abhinavr](https://discourse.julialang.org/u/abhinavr)
#### Post date: [March 6, 2026, 7:42am UTC](https://discourse.julialang.org/t/fastest-way-to-define-high-level-functions-in-a-text-file-and-use-them-in-julia-after-processing/136061/1 "2026-03-06T07:42:12Z")

</div>

I’m trying to design a system where users write function definitions in a `.txt` file, using some higher-level or simplified syntax. Then, in my Julia code, I want to read that file, process/parse those definitions, and use the resulting functions in Julia.

What would be the fastest or most idiomatic way to do this in Julia?

More specifically, I’m wondering:

- Should I parse the text and generate Julia expressions/functions dynamically?
- Is there a recommended approach for safely evaluating user-defined function definitions?
- Would macros, metaprogramming, or some kind of DSL be the right direction here?
- If performance matters, how should I structure this?

My main goal is to let users define functions in a simple text-based format, then make those functions usable from Julia code with minimal overhead.

---

<div class="post-metadata">

### Author: ![karei](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/karei/32/214809_2.png) [@karei](https://discourse.julialang.org/u/karei)
#### Post date: [March 6, 2026, 8:52am UTC](https://discourse.julialang.org/t/fastest-way-to-define-high-level-functions-in-a-text-file-and-use-them-in-julia-after-processing/136061/2 "2026-03-06T08:52:34Z")

</div>

Welcome to the Julia forum.

This sounds like a domain-specific language (DSL) problem.

1. Only if you really need a separate external syntax. Otherwise, I would strongly prefer an internal DSL in Julia, so users write a restricted high-level Julia-like syntax and you lower that to ordinary Julia code. In other words: if Julia can already parse the surface syntax, let Julia be the parser. You can move to an external DSL if you need a very non-Julia syntax or a fully separate language.

2. I’m not sure about this one.

3. Yes, this is basically a DSL problem. My default recommendation would be an **internal DSL** first, not a separate `.txt` language (external DSL). Macros/metaprogramming are useful if the user-facing syntax can stay close to valid Julia syntax.

4. Parse and lower once, then reuse many times, while ensuring that the generated Julia functions remain type-stable.

---

<div class="post-metadata">

### Author: ![impact-basin](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/impact-basin/32/220810_2.png) [@impact-basin](https://discourse.julialang.org/u/impact-basin)
#### Post date: [March 6, 2026, 11:50am UTC](https://discourse.julialang.org/t/fastest-way-to-define-high-level-functions-in-a-text-file-and-use-them-in-julia-after-processing/136061/3 "2026-03-06T11:50:14Z")

</div>

If you’re trying to design a system where users can write text to define functions using a high-level syntax, you’re defining a programming language, but you already have one in front of you 🙂.

Macros are extremely powerful. I would recommend using [MacroTools.jl](https://fluxml.ai/MacroTools.jl/dev/); see [here](https://github.com/impact-basin/PikaParser.jl/blob/master/src/macros.jl) for a recent example of some work, funnily enough, to define a DSL for parsing.

You could, in theory, define a macro to read a file, parse into Julia expressions (using PikaParser.jl or similar), and return that as a quote node, which would allow you to write in your desired syntax; for me, however, this would be a last resort.

What, exactly, are you trying to accomplish? More specifics would be helpful here, as advice can be more targeted.
