[swift-evolution] [Pitch] Extending Swift Literals

Xiaodi Wu xiaodi.wu at gmail.com
Mon Jul 11 00:01:36 CDT 2016


Well, in my book, a thing without a representation isn't really a
'literal', which to me implies some degree of WYSIWYG :)
On Sun, Jul 10, 2016 at 23:56 Erica Sadun <erica at ericasadun.com> wrote:

>
> > On Jul 10, 2016, at 10:30 PM, Xiaodi Wu <xiaodi.wu at gmail.com> wrote:
> >
> > Questions/comments--
> >
> > What's your use case for these?
> >
> > For proposed literals like `point`, I'm having trouble visualizing how
> that could be literally represented. Since the difference between one point
> and another is its coordinate, would we just see a point floating on the
> screen?
> >
> > Something like `size` seems ill-suited for literal representation, as
> opposed to a shape (e.g. rectangle). Why is it a two-dimensional size
> anyway? Also, since literals have no type, is there any scenario in which a
> `size` literal of a certain width and height and a `point` literal with a
> certain x and y coordinate are meaningfully different?
> >
> > Finally, several of these look like string literals with types. For
> instance, `unicode` seems to reflect a desire to refer to characters by
> their official names. Perhaps that could be proposed instead as a new
> escaping syntax for strings? Something like `let string = "\u{{DOG FACE}}"`
> might be pretty handy.
>
> It doesn't have to be "represented". It can be used as `#literal.point(x:
> 3.5, y: 2.0)` without any "pretty" picture.
>
> A literal offers a typeless universal value that can be interpreted by a
> conforming type as a representation of itself, so you can have:
>
> let x: CGPoint = #literal.point(x: 3.5, y: 2.0)
> let x: NSPoint = #literal.point(x: 3.5, y: 2.0)
> let x: float2 = #literal.point(x: 3.5, y: 2.0)
>
> -- E
>
>
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <https://lists.swift.org/pipermail/swift-evolution/attachments/20160711/0e03db63/attachment.html>


More information about the swift-evolution mailing list