Open danielo515 opened 6 years ago
It looks like the arguments to Droid
aren't being enforested. It will work if you wrap the constructor call in parens:
let bb8 = (new Droid('BB-8', 'orange'));
console.log(bb8.beep());
Hello @gabejohnson Thanks for your answer.
Seems that you know how to workaround the possible problems that could emerge. Could you please help me building a very simple macro ? I just want to simulate the apply operator from haskell. So:
add $ 1 2
// becomes
add (1) (2)
I made several attempts, but none of them succeed compiling. Regards
@danielo515 You're going to need to use the operator
keyword as outlined https://www.sweetjs.org/doc/tutorial#sweet-operators
This is what I came up with
operator $ right 0 = (left, right) =>
#`
${left}(${right})
`;
log $ 1; // log(1);
You're not going to be able to support something like log $ 1 2
though as the second argument to $
is an already fully expanded expression. log $ 1 $ 2
should work though.
@gabejohnson "space" does not play in precedence resolution, right?
@vendethiel not certain what you mean, but the space b/w 1 2
should just result in a syntax error. But sweet resolves it by putting 2
in a separate statement.
Hello @gabejohnson , That's something I tried already. Since writing one dollar sing instead of two parents is less typing, the final result will be equally ugly. This seems to be a great challenge for everything I tried so far: babel-macros, livescript, babel plugins, sweet....
Hello,
Taking several of the basic examples and trying to run them on the online editor produces errors. For example:
yields the following error:
Same thing happens if I install sweet from npm and try to compile it. I also tried to build a basic macro, but I'm only getting errors related to unknow objects to JSON.parse and that stuff.
The project seems to be a great potential, but I think it does not play well with the latest JS features like spread operator and template literals.
Regards