Closed WiseIndian closed 4 years ago
Generating pattern matching, while it is doable, there is some hassle. A simpler way is to generate if/then/else
, which is a little verbose, but semantically equivalent.
Oh yeah.. that's right we are only testing an Int in the end. Good idea. Thanks
I tried to generate the continue method of the Coroutine class. In our design we wanted that the Coroutine class implementations look something like this.
In order to generate the code of the continue method of the Coroutine class I experimented three possible ways this weekend. Sadly none compiled in the end.
The first way was this one:
I use a foldLeft in order to create the different cases of this match expression. At each iteration of the foldLeft I add a new case to the previous expressions (previous cases) encapsulated in the accumulator of the foldLeft.
In this case the compiler complains with this error:
Although we're within a quote surrounding the code which create a "new Coroutine" we are not allowed to generate code with a splice inside the match.
Given that, I thought I could make use of the tasty API in order to go at a lower level of abstraction. So I wrote code like this:
Sadly it seems that it is not possible to create a CaseDef in this way:
So I tried a last way which consisted in Invoking the CaseDef apply method:
This seems to work better as the compiler now complains about such an error where "f$" is not found. Here what I tried to achieve was a function call using the identifier of a function "fi" where i is the index of the function.