disnet / contracts.js

Contract library for JavaScript
http://www.contractsjs.org
MIT License
149 stars 8 forks source link

Provide parser for contracts.coffee-style syntax #13

Closed kennknowles closed 10 years ago

kennknowles commented 11 years ago

I would love for the following to be equivalent to writing out the AST longhand in Javascript.

var id = c.guard( c.parse('(Num) -> Num'),
    function(x) { return x; }
);

Eliding the call to parse using reflection is presumably safe as well?

disnet commented 11 years ago

Yes we should definitely do this! What do you mean by reflection?

kennknowles commented 11 years ago

Hardly qualifies as reflection in a dynamic language... https://github.com/kennknowles/python-rightarrow/blob/master/rightarrow/enforce.py#L7

disnet commented 11 years ago

Oh! You mean overload guard to check if it's a contract or a string (in which case parse the string into a contract). Yeah, that'd work.

joelmccracken commented 10 years ago

so, what if we used the function tostring method and parsed type signature information out of it? something like:

inc = c.guard(function(x){ 
  /* (Num) -> Num */ 
  return x+1;
});
disnet commented 10 years ago

We've moved to using macros so I don't think we need this anymore.