4 ms·
The defer syntax feels wrong to me, I think because it looks like a function call but doesn't behave like one (because it assigns to its arguments). If it behav
by extension 15y ago
The defer syntax feels wrong to me, I think because it looks like a function call but doesn't behave like one (because it assigns to its arguments). If it behaves different then it should look different.
Since it creates a continuation, perhaps it should resemble the syntax for creating a function, like this:
await resolve "host.com", (ip, err) ~>
console.log "#{ip} #{err}"
or this:
await resolve "host.com", (ip, err) <-
console.log "#{ip} #{err}"
Introducing an operator like this would also avoid some name collisions.
And does the callcc really have to be able to assign to things? Make it work just like a formal parameter list, and then you can actually compile it into one, avoiding all that pass-by-reference hoopla.
The autocb thing is even weirder. Magic variable names? I've never heard of a language that resorted to this. Why not just some new syntax to mark a parameter as the callback? Perhaps some postfix modifier, to match the splat syntax?
resolve = (host, callback <-) ->
...
return ip, err
or overload a keyword?
resolve = (host, return callback) ->
...
return ip, err
- DanielRibeiro 15y agoIf I understood correctly, they would become keywords, like 'return', 'true', 'false' are in javascript, and 'class' is in coffeescript. The problem with it is that any functions called defer would have to be renamed in order to work on this version of Coffeescript, possibly breaking some existing code.
- tikhonj 15y agoThis is really pedantic, but I also think it's important: class is a keyword (well, really just a reserved word) in JavaScript as well. The reason it's important is that some engines will actually have issues if you use syntax like this[1]: var obj = {class : "blarg"}; [1]: https://developer.mozilla.org/en/JavaScript/Reference/Reserved_Words https://developer.mozilla.org/en/JavaScript/Reference/Reserv...
- DanielRibeiro 15y agoYeah, we are kinda splitting hairs here, but strictly speaking, 'class' is reserved word in JS. It will become a keywords when they start using it. The link you provided does make this distinction: reserved as future keywords.