morganey-lang / Morganey

Lambda Calculus based, interpreted programming language that recognizes Church encoded structures.
43 stars 4 forks source link

Reimplementation of morganey's quasiqotes #345

Open keddelzz opened 7 years ago

keddelzz commented 7 years ago

I suggest to add another feature to morganey's quasiquotation.

Current situation

The current implementation of the quasiquotes allows some nice operarations on LambdaTerms.

val term = m"(append $v1 $v2)"


- extracting terms from other terms
```scala
val term1 = m"(42 42)"
val m"($twentyFour 42)" = term1
// use `twentyFour`
// twentyFour :: LambdaTerm

New feature

The .. in the quasiquote allows to spread the contents of a scala-list into lists (as shown in the example above).

keddelzz commented 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 :)

Todos

rexim commented 7 years ago

@keddelzz thank you very much for the proposal! I'll take a look into it a little bit later.

keddelzz commented 7 years ago

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.

rexim commented 7 years ago
  1. 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.

  2. 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.

  1. I don't understand why do we need this feature. Couldn't we just
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?

keddelzz commented 7 years ago

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

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.

rexim commented 7 years ago

Why can't we just do all of those list manipulations in Scala after converting Morganey lists to Scala lists?

keddelzz commented 7 years ago

Of course we're able to do so, but it gets quite tedious, if you've to do those things often.

rexim commented 7 years ago

@keddelzz ok, I'll take a look at the code a little bit later. Thanks!