In Ruby, when you design an embedded DSL a very useful trick is to leverage instance_eval
. That way one can offer special statements within a certain block by implementing them as private methods on a special object. This is very nice for contextual stuff.
For an example see: https://robots.thoughtbot.com/writing-a-domain-specific-language-in-ruby
I was wondering what the closest equivalent would be in a Scala EDSL? More specifically how would I offer parts of the syntax only within a certain context that is delimited by a block?
If anybody's wondering: It looks like this is gonna be solve by so-called implicit function types. Here's a good write-up of the idea by Martin Odersky himself: https://www.scala-lang.org/blog/2016/12/07/implicit-function-types.html
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.