#1659 Inline parameter

Xan Fri 30 Sep 2011

Hi,

Just a simple question: Is it possible to do "Object method value" instead of "Object.method(value)?. Like in scala?

Thanks a lot, Xan.

brian Fri 30 Sep 2011

Nope - that sort of stuff makes the grammar a lot more complicated (and I personally think it leads to less consistent code)

DanielFath Fri 30 Sep 2011

I would like to see that happen if not for all methods than at least for bit operators like .and .xor. .or etc. Having a gazillion billion brackets doesn't help with the readability. I think there is something appealingly consistent about every sign being a possible method but it's not something Fantom really needs (not to mention the problems of having method/operator precedence in such cases).

Xan Fri 30 Sep 2011

I understand it, but it allows to have "decent" DSL like "verify (pressure>=300) within 10 onfail { display("pressure error") }

Read this (source

Thanks, Xan.

DanielFath Fri 30 Sep 2011

If you want to write DSL in Fantom you can use:

PressureDSL <| 
 verify (pressure>=300) within 10 onfail {
  display("pressure error")
 }
|>

However you need to write your own DSL which is slightly harder than writing embedded DSLs in Scala. See DSLs for more info. This isn't compiler plugin in lieu of scala i.e. need to restart compiler for it to work

Xan Fri 30 Sep 2011

@DanielFath

Can you follow the example? How can I write complete example? I don't understant completely DSL of Fantom.

Thanks, Xan

DanielFath Sun 2 Oct 2011

What DSLs of Fantom do if I'm not mistakes is translate one into another.

Regex <|foo|foo/(\d*)|>

and it's accompanying DSL

class RegexDslPlugin : DslPlugin
{
  new make(Compiler c) : super(c) {}

  override Expr compile(DslExpr dsl)
  {
    regexType := ns.resolveType("sys::Regex")
    fromStr := regexType.method("fromStr")
    args := [Expr.makeForLiteral(dsl.loc, ns, dsl.src)]
    return CallExpr.makeWithMethod(dsl.loc, null, fromStr, args)
  }
}

and add this to your build.fan

index = ["compiler.dsl.sys::Regex": "compiler::RegexDslPlugin"]

would become for compiler

//Regex <|foo|foo/(\d*)|> for reference
sys::Regex.fromStr(foo|foo/(\d*))

Unfortunately the compiler isn't that well documented due to frequent changes. Your example I'm unsure how it would work exactly. You'd need to use Expr or one of it's children.

See kaushik's examples for how to make DSLs https://bitbucket.org/ksat/fanbatis/src/952b4ac8bba3/fan/SqlDslPlugin.fan

TL;DR. To make a DSL you can't hack the language. You need to play with compiler a bit. It's a complicated since compiler often changes and it's documentation isn't up to par.

Xan Mon 3 Oct 2011

It's very hard so.

In other order of things, is there any plan for stabilize API? I think the most trouible in Fantom is the lack of examples in documentation. And if doc changes slowly than API, it's not possible to have good examples.

PErhaps in 1.2?

Thanks, Xan.

Login or Signup to reply.