Coder Social home page Coder Social logo

eslisp-fancy-function's Introduction

eslisp-fancy-function

An eslisp macro that works like an the usual lambda expression macro but also

  • parses splats (atoms starting with ...) in the arguments and turns them into appropriate variable assignments prepended to the function body, and
  • implicitly returns the last thing in the body if it's an expression.

Note that despite the name, this module is strictly a function expressions (lambda-ish) macro, not a function declaration. I'll rearrange that eventually.

Example

(macro fun (require "eslisp-fancy-function"))
(fun (a b ...c d) (* a b d))

(function (a, b) {
    var c = Array.prototype.slice.call(arguments, 2, -1);
    var d = arguments[arguments.length - 1];
    return a * (b * d);
});

See the tests for fuller usage.

License

ISC.

eslisp-fancy-function's People

Contributors

anko avatar

Watchers

 avatar  avatar  avatar

Forkers

seepel

eslisp-fancy-function's Issues

TypeError: splatAndAfter.filter is not a function

I was just trying out fancy-function for the first time. I ran this code and got the following error.

(macro fun (require "eslisp-fancy-function"))
(fun (a b ...c d) (* a b d))
λ eslc main.lisp
C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\lib\cli.js:102
      throw err;
      ^

TypeError: splatAndAfter.filter is not a function
    at env.module.exports (C:\Projects\TheButtonMobile\ESLisp\node_modules\eslisp-fancy-function\index.js:14:33)
    at listToEstree (C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\lib\compile.js:177:27)
    at astToEstree (C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\lib\compile.js:236:25)
    at C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\lib\translate.js:35:14
    at C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\node_modules\prelude-ls\lib\List.js:158:21
    at C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\node_modules\prelude-ls\lib\List.js:161:4
    at C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\node_modules\prelude-ls\lib\List.js:665:42
    at module.exports (C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\lib\translate.js:36:7)
    at toEstree (C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\lib\index.js:9:10)
    at compile (C:\Users\ktodyruik\AppData\Roaming\npm\node_modules\eslisp\lib\index.js:17:12)

Fails when nested

Reported by @kiasaki in chat.

(var fun (require "eslisp-fancy-function"))
(fun () (fun () x))

—errors when it should give function() { return function() { return x; } }.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.