Giter VIP home page Giter VIP logo

ki's People

Contributors

fasterthanlime avatar lantiga avatar orlin avatar sleepyfox avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

ki's Issues

REPL Support?

Any way to work on ki type code with REPL integration? To eval one block at a time similar to clojure REPL/Cider in Emacs?

Error handling

We could consider relying on the AST for catching the most frequent macroexpand-time errors and emit proper errors with line numbers etc (as in source maps).

Install instructions

I think that the instructions should add

npm install mori

otherwise, npm will resolve mori as a dependency of ki, but it won't be found by the require()

either that, or the example is changed to use

var mori = require('ki/node_modules/mori')

(or you make each ki statement generate a new require of mori, thus removing the burden of ki-users to deal with it, this shouldn't be a problem performance-wise)

ki exit code

The exit code of the ki command should be 1 (or non-0) when there are errors. This way one could use tools such as gulp-notify or nanybar to get notified about compilation status.

Source map accuracy

This may be a sweet.js issue but since I've only encoutered it with the ki compiler so far, I'd like to track it here if it's okay with you @lantiga.

Here's a simple test case: https://gist.github.com/fasterthanlime/4c348adeca79370bf58c

And here's the stack trace Chrome gives:

screen shot 2014-11-04 at 18 21 59

The file/line number is correct for problem4, problem3, problem2, but for problem and the top-level scope, they're completely wrong (863, 530).

It might not be a huge problem, it just means top-level code should always be wrapped in a function to get correct stack traces, but I was wondering if it's something the ki compiler do that throws off sweet.js source map generation.

AST transformer

Make reading keywords and object property notation more robust by relying on ranges (as in react.hiccup).

(apply f x args)

Ki's implementation of apply differs from Clojure. According to ClojureDocs apply "applies fn f to the argument list formed by prepending intervening arguments to args". Only prepending. I'm interested in the second signature (apply f x args). Here is an example:

  (def pick (js require("lodash").pick))

  (defn pick1 [what key]
    (pick what key))

  (defn pickm [what keys]
    (apply pick what keys))

  (.log console (pick1 {$ "a" 1 "b" 2} "a")) // { a: 1 }
  (.log console (pickm {$ "a" 1 "b" 2 "c" 3 } [$ "a" "b"])) // {}
  (.log console (pick {$ "a" 1 "b" 2 "c" 3 } "a" "b")) // { a: 1, b: 2 }

The pick of lodash is same as underscore's and I don't think mori has an equivalent fn. If apply with three arguments worked like Clojure's apply, I believe the second console.log would have matched the third. I'm not very skilled with lispy tricks, so I wrote my own pick like so:

  (defn pick [from keys]
    (let [res {$}]
      (loop [key (.pop keys)]
        (if (js key == undefined)
          res
          (do
            (js res[key] = from[key])
            (recur (.pop keys)))))))

It would be cool if ki functions / special forms named same as Clojure / ClojureScript worked the same.

mori runtime dependency

I'm working on datomiki, a datomic rest client written in ki, and I just realized I need mori in order to use it - the compiled code can't run on its own. Or I figured it's better to depend on ki, so that a newer mori does not break things. Here is the error from [email protected]:

/Users/om/Dev/apf/node_modules/datomiki/datomiki.js:115
                    return mori;
                           ^
ReferenceError: mori is not defined
    at _ki.modules.mori (/Users/om/Dev/apf/node_modules/datomiki/datomiki.js:115:28)
    at Object.<anonymous> (/Users/om/Dev/apf/node_modules/datomiki/datomiki.js:118:10)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/Users/om/Dev/apf/context/routes/api/sources/index.js:1:71)
    at Module._compile (module.js:456:26)

Is this intentional? Maybe ki could --include mori in the output? Perhaps with a new convenient option e.g. -a, --autonomous?

Incorrect parsing of negative literals

Negative numeric literals are not parsed correctly.
E.g. [-1 -2] gets parsed as vector(-1,2), (def a -1) produces def(1).

Workaround for now is enclose negative numeric literals in a unary minus (-1) form.

Promises

Does ki handles promises?

I've tried to play around with Fetch API, fetch function does return promise, but I can't figure out what is the proper syntax for .then().catch() in ki.

dot notation does not work in partial application, function composition

From the docs, you can chain dot notation in the following way:

ki require core
var r1 = ki (threadf "lol r1" (.toUpperCase) (.trim));
console.log(r1); // "LOL R1"

However, sometimes you want to move this behavior into a function for reuse. Honestly I feel this should work, but it doesn't compile:

var r2 = ki (comp (.toUpperCase) (.trim));
// Unexpected token .

(Neither does (comp .toUpperCase .trim), but that fails with a runtime error)

If you want the same behavior composed, or partially applied, you have to do the following:

var toUpper = function(x){ return x.toUpperCase(); };
var toTrim = function(x){ return x.trim(); };
var r3 = ki (curry pipeline toUpper toTrim);
console.log(r3("lol r3")); // "LOL R3"
var r4 = ki (comp toUpper toTrim);
console.log(r4("lol r4")); // "LOL R4"

On a related note, threadf also doesn't work with curry. The following compiles but results in a runtime error:

var r5 = ki (curry threadf toUpper toTrim);
console.log(r5("lol r5"));
// ReferenceError: threadf is not defined

It kind of makes sense if you think of threadf as a special form, but it doesn't appear dot notation should be. Dot notation works as an argument to threadf, but not in any other situations?

bind

Explore alternatives to calling bind(this) in IIFN, e.g. in letv. Native bind has potential performance issues compared to using closures.

See StackOverflow discussion.

  • benchmark iifn+bind / iifn+no bind / noiifn using jsperf

arguments var missing in ki functions

Sometimes it's useful to have the arguments var available, just like js functions offer. Some cases can't quite be covered with variadic arity / multimethod functions. For example variable args with last arg a callback, or whatever other edge-case scenario. In any case, people could write their functions in ki without missing javascript's arguments or falling back to javascript for that reason. Otherwise useful just for the sake of matching-up the host language.

macro expansion problem

With this input file:

var mori = require('mori');
var foo = ki (vector 1 2 3)
console.log(foo);

I obtain this:

var mori$610 = require('mori');
var foo$620 = mori$499.vector(1, 2, 3);
console.log(foo$620);

which is obviously incorrect

I never used sweet.js before, so I'm not sure why is it expanding the whole file as a macro, and not only the ki statement

(fn can't take name)

I was trying to write this:

ki require core
var f = ki (fn self ([] (self "World")) ([who] (str "Hello " who "!"))) 
console.log('calling ki', f())

compiler says the following:

[SyntaxError: [macro] Macro `_fnmap` could not be matched with `self , () , ()...`
219: ^]

I don't even know if this should be possible considering that this is not a Clojure clone, but in Clojure you could write:

user=> (def f (fn self ([] (self "World")) ([who] (str "Hello " who "!"))))
#'user/f
user=> (f)
"Hello World!"
user=> (f "Daniel")
"Hello Daniel!"

with javascript, is also posible:

> var x = function self(who) { if (!who) return self.call(this, "World!"); return "Hello " + who +  "!"; }
undefined
> x()
'Hello World!!'
> x("Daniel")
'Hello Daniel!'
> x
[Function: self]
> self
ReferenceError: self is not defined
    at repl:1:2
    at REPLServer.self.eval (repl.js:110:21)
    at Interface.<anonymous> (repl.js:239:12)
    at Interface.EventEmitter.emit (events.js:95:17)
    at Interface._onLine (readline.js:202:10)
    at Interface._line (readline.js:531:8)
    at Interface._ttyWrite (readline.js:760:14)
    at ReadStream.onkeypress (readline.js:99:10)
    at ReadStream.EventEmitter.emit (events.js:98:17)
    at emitKey (readline.js:1095:12)

Ki as a library?

One of the things I'd love to work out how to do is load ki as a library in Node, specifically to write a Webpack loader for easier development workflows. Any ideas where to start with that, as lib/ki_run.js seems to have a lot of code involved

defn can't return non-sexprs

The following:

(defn welcome [name]
  [:p "Welcome to " name])

Is valid Clojure/ClojureScript as far as I can tell, but it fails with:

[SyntaxError: [macro] Macro `_return_sexprs` could not be matched with `()...`
207:
           ^]

A workaround is to surround the vector literal with a (do ).

ki --autonomous #error

It gives me a SyntaxError: Unexpected token ;

r("mori.mutable.disj.fn",ge.K);;return this.mori;}.call({});});
                                                           ^

Update to latest Mori

Mori 0.3.0 has several improvements over previous versions and a few backwards incompatible changes (e.g. idiomatic function names). We should update ki and docs to Mori 0.3.0.

ki --watch #macros

The --watch option does not work for ki macro. And the --included code doesn't get watched at all. I ended up writing a little gulpfile.js, so I'd be able to play with macros. I imagine someone may write a gulp-ki plugin some day... Though this is just a few lines good-enough copy/paste fix that does the job.

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.