question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Inline functions: scoping, and name

See original GitHub issue

I 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:closed
  • Created 5 years ago
  • Comments:16 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
kelleyvanevertcommented, Apr 9, 2018

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:

const A = Algebra(4,1);
const scope = A.scope(); // or .namespace()
scope.ei = scope.def(() => 1e4 + 1e5)();
scope.f = scope.def(() => ei + 5);

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:

scope.def = f => return eval("(() => with(scope) { return " + magic(f.toString()) + "; })()");
1reaction
enkimutecommented, Apr 9, 2018

yes. easy-peasy.

it’s just string magic - no logic going on there 😉

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found