<pre class="lang-none prettyprint-override"><code>DEFINE FUNCTION change_directory(FilePath ipath)
…
…
DEFINE FUNCTION print_working_directory()
…
…
DEFINE FUNCTION remove(FilePath ipath)
</code></pre>
<hr />
<p>Traditionally, labels used in function calls are identical to labels used in function definitions.</p>
<p>However, in order to improve language-ergonomics it might help if, for each label used in a function definition, we assign a regular expression to a set of labels that we allow in function calls.</p>
<p>This might assist students to focus on the content of their writing instead of the syntax or spelling.</p>
<hr />
<p>Suppose that we associate the function label <code>change_directory</code> with the regular expression <code>c?h?a?n?g?e?_?d?i?r?e?c?t?o?r?y?</code></p>
<p>Then, all of the following function calls would map to the function definition for <code>change_directory</code>...</p>
<pre class="lang-none prettyprint-override"><code>CALL cd(&quot;dir\subdir\subsubdir&quot;)
CALL changedir(&quot;dir\subdir\subsubdir&quot;)
CALL chng_dir(&quot;dir\subdir\subsubdir&quot;)
CALL change_dr(&quot;dir\subdir\subsubdir&quot;)
</code></pre>
<p>—------------------------------------------------------</p>
<p>Then, all of the following function calls would map to the function definition for <code>print_working_directory</code>...</p>
<pre class="lang-none prettyprint-override"><code>CALL pwd()
CALL print_working_directory()
CALL prnt_wrk_dir()
CALL prnt_wrk_dr()
</code></pre>
<p>—----------------------</p>
<p>All of the following could be valid calls to the <code>remove</code> command when our regex is <code>r?e?m?o?v?e?</code>...</p>
<pre><code>CALL rm()
CALL remove()
CALL rmv()
CALL rmve()
</code></pre>
<hr />
<p>What is one example of a standard approach to implementing a compiler in which function labels for function calls can be different abbreviations of function labels used in function definitions?</p>
<p>Please keep in mind that we must generate reasonable compiler error messages in case of name-conflicts.</p>
<p>For example, the string of text <code>is_permble</code> matches the both of the regular expressions for <code>is_permi?s?s?i?ble</code> and <code>is_permi?t?t?able</code>.</p>
<hr />
<p>Would it make sense to iteratively revise the regular expressions until the regulars expressions partition the set of function abbreviations (the regular expression must be mutually exclusive?</p>
<p><span class="math-container">$A_{2} = + A_{1} - B_{1} - C_{1}$</span><br>
<span class="math-container">$B_{2} = + B_{1} - A_{1} - C_{1}$</span><br>
<span class="math-container">$C_{2} = + C_{1} - A_{1} - B_{1}$</span><br></p>
<p>The set of strings <span class="math-container">$A$</span> at iteration <span class="math-container">$2$</span> can be the set of strings <span class="math-container">$A$</span> at iteration <span class="math-container">$1$</span>, with the strings in sets <span class="math-container">$B$</span> and <span class="math-container">$C$</span> subtract, or removed.</p>
<p>Maybe a regex-simplifying algorithm can ensure that the regular expressions are not millions of characters in length.</p>

<language-design><compilers><lexing><tokens><language-ergonomics>
Implementing a compiler that allows function calls to be different than the label in the function definition?
CC BY-SA 4.0
2024-10-12T22:52:40.237Z
And which function does `r(some_path)` map to? It matches both `c?h?a?n?g?e?_?d?i?r?e?c?t?o?r?y?` and `r?e?m?o?v?e?`, and the argument doesn't help to disambiguate. Is it an error? In that case, a later declaration of a new function might match function calls in previously-existing code, so the original code may compile without errors, or cause errors, depending on what appears to be completely unrelated code. The "best practice" would be to run away from a language which does this, as fast as you can.
kaya3
CC BY-SA 4.0
2024-10-12T22:52:45.180Z
It's not exactly what you're asking about (I think), but regular-expression-style method labels *were* treated in [From APIs to Languages: Generalising Method Names](https://mwh.nz/pubs/dls2015), albeit with whole words rather than characters as the primitive symbols (i.e. operates over multi-part method names). It does discuss some ambiguity strategies and ensuring a unique match. Is that something that fits your underlying question, or are the character-level regular expressions the critical element for you? I don't believe there *is* an "industry" best practice, because nobody does this.
Michael Homer
CC BY-SA 4.0
2024-10-12T23:07:50.827Z
This is reminiscent of DWIM, which was famously part of InterLisp. You might want to research its design.
Barmar
CC BY-SA 4.0
2024-10-13T07:15:12.477Z
Note that something similar is [not uncommon for command line arguments](https://docs.python.org/3/library/argparse.html#allow-abbrev). It’s a *major* footgun for backwards compatibility since unrelated options affect each others' valid names and mean that the same command can silently change to meaning something completely different even without a direct conflict. And that is due a more conservative approach on a commonly smaller namespace than what you consider.
MisterMiyagi
CC BY-SA 4.0
2024-10-13T10:42:00.097Z
This is probably best done inside the text editor using context-aware autocomplete. That way the programmer can confirm what they typed actually results in the function they meant to call, and the maintainer isn't met by unreadable strings of ad hoc abbreviations that they have to look up using a specialised program.
Jasmijn
CC BY-SA 4.0
2024-10-13T13:17:30.773Z
Th prblm wth ths s tht t mks rdng th cd vr hrd, nd dds lts f pssblts fr mbgts.
G. Sliepen
CC BY-SA 4.0
2024-10-14T22:07:57.290Z
"in order to improve language-ergonomics" You keep using that word. I do not think it means what you think it means.
talex
CC BY-SA 4.0
2024-10-29T21:24:47.890Z
Inform 7 allows for function names with variations, though not full regexes.
curiousdannii
CC BY-SA 4.0
2024-11-01T21:18:04.217Z
This would also allow for a call to `hang_toy`, or `can_die`, or `changed`. This sort of thing makes it much harder to determine what will be called. Code is read far more often than it is written. It also introduces the potential for ambiguity.
Karl Knechtel
# Implementing a compiler that allows function calls to be different than the label in the function definition?
Posted by: username_0 on 2024-10-12
DEFINE FUNCTION change_directory(FilePath ipath)
…
…
DEFINE FUNCTION print_working_directory()
…
…
DEFINE FUNCTION remove(FilePath ipath)


Traditionally, labels used in function calls are identical to labels used in function definitions.
However, in order to improve language-ergonomics it might help if, for each label used in a function definition, we assign a regular expression to a set of labels that we allow in function calls.
This might assist students to focus on the content of their writing instead of the syntax or spelling.

Suppose that we associate the function label change_directory with the regular expression c?h?a?n?g?e?_?d?i?r?e?c?t?o?r?y?
Then, all of the following function calls would map to the function definition for change_directory...
CALL cd("dir\subdir\subsubdir")
CALL changedir("dir\subdir\subsubdir")
CALL chng_dir("dir\subdir\subsubdir")
CALL change_dr("dir\subdir\subsubdir")

—------------------------------------------------------
Then, all of the following function calls would map to the function definition for print_working_directory...
CALL pwd()
CALL print_working_directory()
CALL prnt_wrk_dir()
CALL prnt_wrk_dr()

—----------------------
All of the following could be valid calls to the remove command when our regex is r?e?m?o?v?e?...
CALL rm()
CALL remove()
CALL rmv()
CALL rmve()


What is one example of a standard approach to implementing a compiler in which function labels for function calls can be different abbreviations of function labels used in function definitions?
Please keep in mind that we must generate reasonable compiler error messages in case of name-conflicts.
For example, the string of text is_permble matches the both of the regular expressions for is_permi?s?s?i?ble and is_permi?t?t?able.

Would it make sense to iteratively revise the regular expressions until the regulars expressions partition the set of function abbreviations (the regular expression must be mutually exclusive?
$A_{2} = + A_{1} - B_{1} - C_{1}$
$B_{2} = + B_{1} - A_{1} - C_{1}$
$C_{2} = + C_{1} - A_{1} - B_{1}$
The set of strings $A$ at iteration $2$ can be the set of strings $A$ at iteration $1$, with the strings in sets $B$ and $C$ subtract, or removed.
Maybe a regex-simplifying algorithm can ensure that the regular expressions are not millions of characters in length.
**Tags:** language-design compilers lexing tokens language-ergonomics
> **Comments:**
> **username_1**: And which function does `r(some_path)` map to? It matches both `c?h?a?n?g?e?_?d?i?r?e?c?t?o?r?y?` and `r?e?m?o?v?e?`, and the argument doesn't help to disambiguate. Is it an error? In that case, a later declaration of a new function might match function calls in previously-existing code, so the original code may compile without errors, or cause errors, depending on what appears to be completely unrelated code. The "best practice" would be to run away from a language which does this, as fast as you can.  
> **username_2**: It's not exactly what you're asking about (I think), but regular-expression-style method labels *were* treated in [From APIs to Languages: Generalising Method Names](https://mwh.nz/pubs/dls2015), albeit with whole words rather than characters as the primitive symbols (i.e. operates over multi-part method names). It does discuss some ambiguity strategies and ensuring a unique match. Is that something that fits your underlying question, or are the character-level regular expressions the critical element for you? I don't believe there *is* an "industry" best practice, because nobody does this.  
> **username_3**: This is reminiscent of DWIM, which was famously part of InterLisp. You might want to research its design.  
> **username_4**: Note that something similar is [not uncommon for command line arguments](https://docs.python.org/3/library/argparse.html#allow-abbrev). It’s a *major* footgun for backwards compatibility since unrelated options affect each others' valid names and mean that the same command can silently change to meaning something completely different even without a direct conflict. And that is due a more conservative approach on a commonly smaller namespace than what you consider.  
> **username_5**: This is probably best done inside the text editor using context-aware autocomplete. That way the programmer can confirm what they typed actually results in the function they meant to call, and the maintainer isn't met by unreadable strings of ad hoc abbreviations that they have to look up using a specialised program.  
> **username_6**: Th prblm wth ths s tht t mks rdng th cd vr hrd, nd dds lts f pssblts fr mbgts.  
> **username_7**: "in order to improve language-ergonomics" You keep using that word. I do not think it means what you think it means.  
> **username_8**: Inform 7 allows for function names with variations, though not full regexes.  
> **username_9**: This would also allow for a call to `hang_toy`, or `can_die`, or `changed`. This sort of thing makes it much harder to determine what will be called. Code is read far more often than it is written. It also introduces the potential for ambiguity.  
---
## 0 answers
