<div dir="ltr">Maybe we could implement a template system like C++ </div><div class="gmail_extra"><br><div class="gmail_quote">On Sat, Dec 26, 2015 at 3:20 PM, Dmitri Gribenko via swift-evolution <span dir="ltr"><<a href="mailto:swift-evolution@swift.org" target="_blank">swift-evolution@swift.org</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><span class="">On Sat, Dec 26, 2015 at 3:59 PM, Radosław Smogura <<a href="mailto:rsmogura@icloud.com">rsmogura@icloud.com</a>> wrote:<br>
> So,<br>
><br>
> What do you think about syntax like this:<br>
><br>
> // Declaration<br>
> @AttributeUsage(RUNTIME) //Can be SOURCE - attribute not emitted into binary<br>
> @AttributeTarget(PROPERTY) //Other CLASS, ENUM, METHOD, INIT<br>
> @attribute JSONProperty {<br>
> var name:String!;<br>
> var serializable:Bool? = true;<br>
> var deserializable:Bool? = true;<br>
> }<br>
<br>
</span>Is this a new declaration kind? Do you think we could make it work<br>
with existing language constructs instead, like structs? Any<br>
downsides to that?<br>
<span class=""><br>
> // Usage<br>
> @JSONProperty(name=“id”)<br>
> var id:Int;<br>
><br>
><br>
> Attributes should be module aware (actual attributes should be redefined as Swift attribute, for beginning still can be hardcoded).<br>
<br>
</span>Sorry, I'm not sure what this means.<br>
<span class=""><br>
> The attribute’s name have to be unique in module. It’s compile time error if attribute, class, enum, struct, etc has same name.<br>
><br>
> Attribute’s properties are read only and can’t be assigned - so during reflection no-one would change ‘shared’ values.<br>
<br>
</span>I think using structs and requiring that attributes are value types<br>
would solve both issues.<br>
<span class=""><br>
> Attribute’s properties can only support basic types: primitives, strings, types, and other attributes (optional).<br>
<br>
</span>Well, there is no such thing as "basic types" in Swift. Strings,<br>
integers etc. are defined in the standard library and the compiler<br>
does not know anything special about them.<br>
<span class=""><br>
> When declaring attributes, properties can be set to constant values (static let) or enum values, however the final value is stored in binary, not a reference to it.<br>
<br>
</span>Again, given that strings are defined in the standard library, and<br>
that the language does not have a notion of a constant expression, I'm<br>
not sure how this would work. I'm not saying it can't, I'm just<br>
saying you need to introduce a lot of new language concepts and<br>
compiler machinery.<br>
<span class=""><br>
> The compiler has build in support for core attributes, which can affect code generation. Compiler may perform additional checks on core attributes.<br>
<br>
</span>OK.<br>
<br>
Another question is, how would you inspect attributes at runtime?<br>
<div class="HOEnZb"><div class="h5"><br>
Dmitri<br>
<br>
--<br>
main(i,j){for(i=2;;i++){for(j=2;j<i;j++){if(!(i%j)){j=0;break;}}if<br>
(j){printf("%d\n",i);}}} /*Dmitri Gribenko <<a href="mailto:gribozavr@gmail.com">gribozavr@gmail.com</a>>*/<br>
_______________________________________________<br>
swift-evolution mailing list<br>
<a href="mailto:swift-evolution@swift.org">swift-evolution@swift.org</a><br>
<a href="https://lists.swift.org/mailman/listinfo/swift-evolution" rel="noreferrer" target="_blank">https://lists.swift.org/mailman/listinfo/swift-evolution</a><br>
</div></div></blockquote></div><br><br clear="all"><div><br></div>-- <br><div class="gmail_signature"><div dir="ltr"><div><div dir="ltr"><div dir="ltr"><div><span style="font-size:16px;line-height:19.2px"></span><span style="font-size:12.8px"> Wizard</span><br></div><div><a href="mailto:james@supmenow.com" target="_blank">james@supmenow.com</a></div><div>+44 7523 279 698</div></div></div></div></div></div>
</div>