Proposal to adding the statement/expression "object. {}" #9032
Labels
area-language
Dart language related items (some items might be better tracked at github.com/dart-lang/language).
closed-not-planned
Closed as we don't intend to take action on the reported issue
This issue was originally filed by andrew.m...@gmail.com
I propose to add a new language construct.
This can be treated at least as the statement.
Or in the best case it can be treated as the expression.
I am talking about a modified design "with(object){}".
The proposed innovation is "object.{}".
Examples of the practical application.
// When subject implementation is only statement
html = new HtmlBuilder();
html .{
head .{
title = 'Page title';
}
body .{
input .{
attributes = {'type': 'button', 'value': 'Click me!'}
}
table .{
for(var item in items) {
rows.add() .{
cells.add() .{
innerHtml = escape(item.text);
}
}
}
}
}
}
// Another example
var cfg = new CfgBuilder();
cfg .{
bits = '0';
compiler .{
includes = ['{$DART_SDK}/include'];
inputFiles = ['sample_extension.cc'];
}
clean = [ '.exp', '.lib', '.o', '.obj'];
platforms .{
linux .{
compiler .{
arguments = ['-fPIC', '-Wall'];
}
linker .{
arguments = ['-dynamiclib', '-undefined', 'dynamic_lookup'];
output_file = 'libsample_extension.dylib';
}
}
macos .{
compiler .{
arguments = ['-fPIC', '-Wall'];
}
linker .{
arguments = ['-dynamiclib', '-undefined', 'dynamic_lookup'];
output_file = 'libsample_extension.dylib';
}
}
windows .{
compiler .{
defines = {'DART_SHARED_LIB':};
input_files = ['sample_extension_dllmain_win.cc'];
}
linker .{
arguments = ['/DLL'];
input_files .{
add('dart.lib');
add('sample_extension_dllmain_win');
}
libpaths = ['{$DART_SDK}/bin'];
output_file = 'sample_extension.dll';
}
}
}
// And expmles when subject realizing both options as statements and expressions
var person = new Person() .{
name = 'John';
city = 'London';
print(name);
};
foo() => new Person().{ name = 'John'; city = 'London'; };
print(person.runtimeType == person.{ /**/ }.runtimeType); // true
var obj1 = obj2.{ /* use obj2 / }.{ / use obj2 / }.{ / use obj2 */ };
The text was updated successfully, but these errors were encountered: