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

contract declarations on functions not of the form "function name(){}" #23

Open
joelmccracken opened this issue Oct 10, 2014 · 2 comments

Comments

@joelmccracken
Copy link

I can't seem to get anything to work except for the named function form. EX:

import @ from "contracts.js"

@ ({name: Str}, [...{loc: Num}]) -> Str
var calcAverageLoc =  }function(person, locArr) {
    var sum = locArr.reduce(function (l1, l2) {
        return l1.loc + l2.loc;
    });
    return "Average lines of code for " +
           person.name + " was " +
           sum / locArr.length;
}


var typoPerson = {nam: "Bob"};
calcAverageLoc(typoPerson, [{loc: 1000}, {loc: 789}, {loc: 9001}]);
SyntaxError: [macro] Macro `@` could not be matched with `() - > Str var...`
9: @ ({name: Str}, [...{loc: Num}]) -> Str
   ^
@disnet
Copy link
Owner

disnet commented Oct 10, 2014

Yeah we need some syntax to wrap an arbitrary expression in a contract. Here are some possibilities:

var f = @ wrap {
  function () { ... }
} in (Num) -> Num

var f = @ wrap {
  function () { ... }
} (Num) -> Num

var f = @ (Num) -> Num wrap {
  function () { ... }
} 

I'm not really excited about any of these. Any ideas?

@joelmccracken
Copy link
Author

Of all of them, I certainly like the last the best. I was thinking
something like:

@Wrap (Num) -> Num
Foo.prototype.inc = function(val) {...};

would read the next expression and wrap the first function expression it
comes to. I don't know how practical that would be though.

On Fri, Oct 10, 2014 at 6:29 PM, Tim Disney notifications@github.com
wrote:

Yeah we need some syntax to wrap an arbitrary expression in a contract.
Here are some possibilities:

var f = @ wrap {
function () { ... }} in (Num) -> Num
var f = @ wrap {
function () { ... }} (Num) -> Num
var f = @ (Num) -> Num wrap {
function () { ... }}

I'm not really excited about any of these. Any ideas?


Reply to this email directly or view it on GitHub
#23 (comment).

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

2 participants