Inline functions: scoping, and name
See original GitHub issueI really love the “inline functions”: instead of a complete DSL, or dealing with a clunky javascript API, you just add operator overloading to otherwise normal javascript code by a clever preprocessing step acting by inflection on the function’s defining string. Nice 😃 This does bring an unintuitive problem though: it breaks lexical scoping:
const a = 5;
console.log(CGA3D.inline(() => {
return a; // nope
})());
A way to deal with this, though a bit cumbersome, is:
const api = { a: 5 };
console.log(CGA3D.inline((api) => {
return api.a; // OK
})(api));
…but might there be a way to reconcile “inline functions” with lexical scoping?
Also, but less important, I’m not sure if “inline functions” is the most logical naming for this feature. What is its rationale?
Issue Analytics
- State:
- Created 5 years ago
- Comments:16 (8 by maintainers)
Top Results From Across the Web
C++ scope of inline functions - Stack Overflow
An unnamed namespace is the preferred way of doing it in C++, at least according to the standard: static is deprecated. Save this...
Read more >What Is Inline Function In C++? Explained With Examples
Inline function in C++ is an enhancement feature that improves the execution time ... You can use scope resolution (::) for this purpose....
Read more >inline specifier - cppreference.com
The inline specifier, when used in a function's decl-specifier-seq, declares the function to be an inline function.
Read more >How do C++ inline functions work in terms of function scope?
The inline keyword is just a hint to the compiler indicating that you think performance would be better if that function's body were...
Read more >Inline function - Wikipedia
In the C and C++ programming languages, an inline function is one qualified with the keyword ... A function defined inline requires exactly...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Another road to take, would be to go less “it’s just code” and more “register a collection of functions in a defined space”, say something like:
Not really the original goal you had in mind, but at least it has a clear and clean API and the other advantages are kept. Of course you’d implement it something like:
yes. easy-peasy.
it’s just string magic - no logic going on there 😉