Open keddelzz opened 7 years ago
I have already toyed with the implementation of the feature. The (unfinished) results can be seen in this commit.
Even if this issue gets rejected, I had a lot of fun implementing this (unfinished) feature :)
LambdaTerms
val m"['H', 'e', 'l', 'l', 'o', ..${nameLetters: List[Char]}]" = m""" "Hello, Morganey" """
// `nameLetters` = List('M', 'o', 'r', 'g', 'a', 'n', 'e', 'y', '!')
@keddelzz thank you very much for the proposal! I'll take a look into it a little bit later.
Yesterday the quotation only worked in expression position. Now it works in pattern position as well (see Todo Unlifting and unsplicing LambdaTerms
above).
To see the changes you can look at this commit.
Please note, that I haven't extensively tested the code. There will be bugs. I will test the code if I find the time.
To make the process of code review easier for everyone you could've created a Pull Request — the mechanism developed by GitHub team specificly for that.
I believe there is a mistake in this comment:
val list = List('H', 'e', 'y') // :: List[Char] val term = m"[..$list]" // `term` is a morganey-list containing 1, 2 and 3
It should contains list of characters, not numbers.
val list = List(1, 2, 3)
val term = m"$list"
and get the Morganey list of numbers before? Is there anything we cannot perform using the current capabilities of quasiquotation?
To make the process of code review easier for everyone you could've created a Pull Request — the mechanism developed by GitHub team specificly for that.
Thank you for the reminder, I will create a PR now!
I believe there is a mistake in this comment
Fixed! Thanks for spotting that!
Is there anything we cannot perform using the current capabilities of quasiquotation?
Yes, there is! We cannot
val m"[..$head, 6, 7, 8]" = m"[1 .. 8]"
val m"[1, 2, 3, ..$tail]" = m"[1 .. 8]"
val m"['H', 'e', 'l', 'l', 'o', ',', ' ', ..${name: String}]" = m""" "Hello, Morganey" """
println(name) // > Morganey
or
val m"['H', 'e', 'l', 'l', 'o', ',', ' ', ..${name: Vector[Int]}]" = m""" "Hello, Morganey" """
println(name) // > Vector(77, 111, 114, 103, 97, 110, 101, 121)
All in all the new implementation lets us manipulate lists more easily.
We also cannot easily create nested applications and nested lambda functions using the quotation mechanism (This was meant by the first Todo above: Are there additional places (other than lists) where spreading multiple values/terms is reasonable?
). To be fair, we can't currently do that in the new implementation, but the groundwork was done to be able to do so.
Why can't we just do all of those list manipulations in Scala after converting Morganey lists to Scala lists?
Of course we're able to do so, but it gets quite tedious, if you've to do those things often.
@keddelzz ok, I'll take a look at the code a little bit later. Thanks!
I suggest to add another feature to morganey's quasiquotation.
Current situation
The current implementation of the quasiquotes allows some nice operarations on
LambdaTerm
s.putting terms into other terms
putting scala values into terms and let them automatically be converted to
LambdaTerm
s.val term = m"(append $v1 $v2)"
New feature
The
..
in the quasiquote allows to spread the contents of a scala-list into lists (as shown in the example above).