prerano
prerano copied to clipboard
Ordinary code in template-strings
Allow ordinary code in template-strings (like in ES6+; incl. nested templates):
`Todays numbers are ${list.map(x => x * 2).join(', ')}`
Nested strings (nested Backticks):
`Todays numbers are ${list.map(x => x * 2).join(`${separator} `)}`
Compex example:
echo `
<VirtualHost{$ips.map(ip => ` {$ip}:80`)}>
ServerName {strtolower($serverName)}
{$includes |> map(include => "Include {$include}\n")}
</VirtualHost>` |> stripMargin()
This is already possible with ECMAScript:
`<VirtualHost ${def.ips.map(ip => `${ip}:80`).join(" ")}> ...`
No special need for backticks - code in templates could (should?) be possible with double-quote-strings.
Definitely. Haven't started thinking about string interpolation, but definitely like the idea of ruby/es6 expressions.
The one other thing I'm thinking about is native support for Hack's XHP style embedded markup. So that html would be generated inline:
$html = <a href="${$obj->getLink()}">${$obj->body}</a>;
Something along those lines...
I am not sure about XHP. Would be a nice addition nontheless. But you should postpone XHP until you're sure, you wont need those syntax-structures otherwise. Having both native XML and native JSON would cover my needs a lot.