Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Proposal to adding the statement/expression "object. {}" #9032

Closed
DartBot opened this issue Mar 10, 2013 · 2 comments
Closed

Proposal to adding the statement/expression "object. {}" #9032

DartBot opened this issue Mar 10, 2013 · 2 comments
Assignees
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

Comments

@DartBot
Copy link

DartBot commented Mar 10, 2013

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 */ };

@lrhn
Copy link
Member

lrhn commented Mar 10, 2013

It's not clear whether the change is intended to make all members of the object appear as variables (for both reading and writing), or just change the way assignments work.
In either case, it is problematic.

In the former case, it breaks with one of the core design choices of Dart: static lexical scope. If you write "var y, z; x.{ y = z; }", the meaning of both "y" and "z" depends on whether the object currently assigned to "x" has properties "y" and/or "z". I can almost guarantee that this will not be acceptable in Dart.

If instead "x.{y = 42;}" just change the meaning of all assignments to have an implicit "x." in front, i.e., "var y = 42;x.{y = 10; z = 42}" is equivalent to "var y = 42; (){.y=10; _.z = 42;}(x)", then it makes it impossible to assign to the "y" variable inside the block, with no workaround. That might not be very practical in practice, and it's very problematic that it changes the meaning of "y = 10;" without any hint in the syntax.

You can look at issue #7616 for another suggestion for scoping cascades.


Added Area-Language, Triaged labels.

@gbracha
Copy link
Contributor

gbracha commented Jan 3, 2015

Set owner to @gbracha.
Added NotPlanned label.

@DartBot DartBot added Type-Defect 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 labels Jan 3, 2015
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
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
Projects
None yet
Development

No branches or pull requests

3 participants