# Automated function and procedure names

**URL:** https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520
**Category:** General
**Tags:** ada
**Created:** [November 30, 2024, 10:36am UTC](https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520 "2024-11-30T10:36:50Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![cup](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cup/32/544_2.png) [@cup](https://forum.ada-lang.io/u/cup)
#### Post date: [November 30, 2024, 10:36am UTC](https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520/1 "2024-11-30T10:36:50Z")

</div>

Is there a built in string in Ada that gives you the name of a function? I am looking for the equivalent of \_\_FUNCTION \_\_ in C.

When I start wrting a program, I create all the function names and instead of null; I use put\_line(functtion\_name); For instance, instead of

```
procedure fred(x: integer) is
begin
    put_line("fred");
end fred;

```

I’d like to use

```
procedure fred(x: integer) is
begin
    put_line( __FUNCTION__ );
end fred;

```

Also, when logging, I’d like to do something like

```
put_line(
    file=>logfile,
    item=> __FUNCTION__ & ": " & ....);

```

Sometimes, during the design phase, I change procedure names and very often forget to change the put\_line. Search and replace doesn’t always work because the procedure name can be embedded in a middle of a word, which often leads to weird logging or comments and possibly compilation errors.

---

<div class="post-metadata">

### Author: ![Irvise](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/i/7ba0ec/32.png) [@Irvise](https://forum.ada-lang.io/u/Irvise)
#### Post date: [November 30, 2024, 11:38am UTC](https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520/2 "2024-11-30T11:38:20Z")

</div>

The `GNAT.Source_Info` library (specific to only GNAT) provides this functionality among others: The source file of the library can be found in [gcc.gnu.org Git - gcc.git/blob - gcc/ada/libgnat/g-souinf.ads](https://gcc.gnu.org/git/?p=gcc.git;a=blob;f=gcc/ada/libgnat/g-souinf.ads;h=bf4d991c70fb4130e1accf8b1e199047caf24f08;hb=HEAD)

The actual procedure name you are looking for from the library is `Enclosing_Entity`

Best regards,  
Fer

---

<div class="post-metadata">

### Author: ![JC001](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@JC001](https://forum.ada-lang.io/u/JC001)
#### Post date: [November 30, 2024, 12:03pm UTC](https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520/3 "2024-11-30T12:03:30Z")

</div>

You can get this portably with [`PragmARC.Reflection`](https://github.com/jrcarter/PragmARC/blob/b274d7294236c87f1781857f27ab20bda4c80c62/pragmarc-reflection.ads).

---

<div class="post-metadata">

### Author: ![cup](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cup/32/544_2.png) [@cup](https://forum.ada-lang.io/u/cup)
#### Post date: [November 30, 2024, 11:35pm UTC](https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520/4 "2024-11-30T23:35:36Z")

</div>

@Irvise Your solution works. Just needs

```ada
with GNAT.Source_Info; use GNAT.Source_Info;
...
    put_line(Enclosing_Entity);

```

This will print the module name and the function name.

---

<div class="post-metadata">

### Author: ![cup](https://forum.ada-lang.io/user_avatar/forum.ada-lang.io/cup/32/544_2.png) [@cup](https://forum.ada-lang.io/u/cup)
#### Post date: [December 1, 2024, 1:30am UTC](https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520/5 "2024-12-01T01:30:06Z")

</div>

@JC001 Looks like I need to download the whole package to get this to work. I can’t just download pragmarc.reflection.ads

---

<div class="post-metadata">

### Author: ![JC001](https://forum.ada-lang.io/letter_avatar_proxy/v4/letter/j/e56c9b/32.png) [@JC001](https://forum.ada-lang.io/u/JC001)
#### Post date: [December 1, 2024, 10:03am UTC](https://forum.ada-lang.io/t/automated-function-and-procedure-names/1520/6 "2024-12-01T10:03:40Z")

</div>

> [@cup](#):
>
> I can’t just download pragmarc.reflection.ads

You could if there were a file by that name:

1. Go to the repo main page: [GitHub - jrcarter/PragmARC: The PragmAda Reusable Components](https://github.com/jrcarter/PragmARC)
2. Click on the file name: pragmarc-reflection.ads
3. Above on the right side of the code box is a button with a downward-pointing arrow; when you put the cursor over it, you get a pop-up reading “Download raw file”. Clicking on this button will download the file.

Of course, you’ll also have to download the spec of package PragmARC and the spec and body of package PragmARC.Mixed\_Case, so you might find it easier to just download the zip file.
