Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

consider Evil Mode #11

Closed
glathoud opened this issue Jul 7, 2018 · 5 comments
Closed

consider Evil Mode #11

glathoud opened this issue Jul 7, 2018 · 5 comments

Comments

@glathoud
Copy link
Owner

glathoud commented Jul 7, 2018

The sortedSearch example shows the suffering of having a great tool like new Function(...) but no access to the local context.

Until JS has tools similar to D's template mixins and string mixins, we might consider an optional activation of the One Evil Thing.

For more background, see the discussion on comp.lang.javascript.

Result

Added a .getImplEval method to support eval, as in:

    // First "declare" all functions so that co-dependencies can be
    // solved.
    //
    // Use `mfunD` to debug
    var improveFirst = mfun( improveFirst )
    ,   improveLast  = mfun( improveFirst, improveLast )
    ;
    
    // Now we can implement them, using evil access to the local
    // lexical scope so that we do not need to write parameters
    // repeatedly 5 times (see above `function sortedSearch(...)`).
    improveFirst = eval( improveFirst.getEvalImpl() );
    improveLast  = eval( improveLast.getEvalImpl() );

For a complete use case see sorted_search_local about here

@glathoud
Copy link
Owner Author

glathoud commented Jul 7, 2018

The first thing would be to check the current behaviour of The Evil One in the current JS engines.

@glathoud
Copy link
Owner Author

glathoud commented Jul 7, 2018

Maybe it's cleaner and easier to do the "half thing", as in:

function sortedSearch(sortedArray, x, /*?fun?*/less, /*?fun?*/equal)
{
     // ....
      return improveFirst(  // UNCHANGED
            sortedArray, x, less, equal, isFirstFound, isLastFound
            , first_found, last_found, i, j, imax, jmin
        );
}

// ...

   // --- Private details

    function improveFirst(  // UNCHANGED
        sortedArray, x, less, equal, isFirstFound, isLastFound
        , first_found, last_found, i, j, imax, jmin
    )
    {
 // ...
  return mret(  // CHANGED
            improveLast
            , fext.__inputArgs__
        );
    }

for a partial use we could also have return mret( otherFun, a, b, c, fext.__restInputArgs__ );

Thanks to Julio Di Egidio for his inspiring comment.

@glathoud glathoud mentioned this issue Jul 9, 2018
@glathoud
Copy link
Owner Author

glathoud commented Jul 9, 2018

won't do it for now

@glathoud glathoud closed this as completed Jul 9, 2018
@glathoud glathoud reopened this Jul 9, 2018
@glathoud
Copy link
Owner Author

glathoud commented Jul 9, 2018

won't do the argument macros either, impossible to implement in debug mode

@glathoud glathoud closed this as completed Jul 9, 2018
glathoud added a commit that referenced this issue Jul 10, 2018
glathoud added a commit that referenced this issue Jul 10, 2018
glathoud added a commit that referenced this issue Jul 10, 2018
@glathoud
Copy link
Owner Author

Actually did it, including support for debug mode :)

See top comment of #11, and sorted_search_local use case about here

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant