Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:104750 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 41360 invoked from network); 15 Mar 2019 18:36:05 -0000 Received: from unknown (HELO mail-io1-f67.google.com) (209.85.166.67) by pb1.pair.com with SMTP; 15 Mar 2019 18:36:05 -0000 Received: by mail-io1-f67.google.com with SMTP id p17so8536846iol.7 for ; Fri, 15 Mar 2019 08:26:44 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=4eOl7oWOrbUCS9i3jmGcYPHIJeIsD85+rzaVpQB7p18=; b=uvrTR6D+Uchx+23JA1cea/11YwO+JYS82ZtdHVyHPdtRGn3oCkfn1pCTJiae0Gf14V iQucKTt5DQIUvgZ9Cpfl3QPcpPIJb4JEwya39qQSGxOzL4A7X4dPSfyWVkzslsUYL5be apcrF4M4m/7mOspbc8On2H1WSesV6WzrtnW+8pChaOYR7hzGDitiqbC7JXTAq+mf4+Cf Bktih/G/WoB7IuJ88xlAk/a04XdhHgEHp0k+y7YWOORIiwJIkg9lGgDxmzhQVMGunU+V n+2lfXrit4hd1lf2YEanwE9qgItbHOr3ATPTVLmxacDt9Pyqy2Ondlz5M45mlSWnUiva HY5w== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=4eOl7oWOrbUCS9i3jmGcYPHIJeIsD85+rzaVpQB7p18=; b=AGYrtQTGNuHT2MJCrFuv0UCERAX6cDFGdNH4xwzz2rME/THZJU5pNVd8aUMT2ePrId BZ2GBKulFL04tlfUcGQrlwpJ0qEo9ufb5Iok9ExKhy7gZUp+LyQYGRfXn3gBI049Ehai un7aQQLtEJpCc6BMf3CIOMs7LMne5jTwSVuvhs7nYX0SQ6jWcS+unXQsTUw3gMgwJtFD WOQE4HvmMDGXmuigFooQwRRvkhZVBBzXUlZVAxfhLvxmDX19z3gIb2DKhs70fsVSJqCG GTV7ykEI0gb4MAmIHDMwnf+Rv5RkIMVZ66IoUr6BYX2RhZSYYdLyKC2wQDAuNmiHvUEk cB1g== X-Gm-Message-State: APjAAAX+I0g3PnwnOvxxTfrfcCe7rxOpu+2G+xSPes0clOJE+axk0tHz TO+vgkY2HOrZtINmzLZn9Dk4aXm1F5xdppG/c90= X-Google-Smtp-Source: APXvYqwKhxY+LnzpVWy3ae1APMO1bo3ev2t679R3PWuiFOf8V7awQgfUolEGadhiWQt/2h07DlyDcmqUPoSunvWOmNE= X-Received: by 2002:a5d:91d3:: with SMTP id k19mr2627788ior.258.1552663604502; Fri, 15 Mar 2019 08:26:44 -0700 (PDT) MIME-Version: 1.0 References: <5c8b20af.1c69fb81.c8b33.d2faSMTPIN_ADDED_MISSING@mx.google.com> In-Reply-To: Date: Fri, 15 Mar 2019 16:26:27 +0100 Message-ID: To: Levi Morrison Cc: Kenneth Ellis McCall , internals Content-Type: multipart/alternative; boundary="0000000000009a28c4058423aa14" Subject: Re: [PHP-DEV] [Proposal] Struct Data Types From: nikita.ppv@gmail.com (Nikita Popov) --0000000000009a28c4058423aa14 Content-Type: text/plain; charset="UTF-8" On Fri, Mar 15, 2019 at 4:16 PM Levi Morrison wrote: > Personally, I think pass by-value with copy-on-write semantics like > arrays is the sweet spot. Mutability is fine if it is localized. > If we introduce something like this, I think it is very important that it does not use the same property access syntax as ordinary objects, which are not copy-on-write. I do not want to be second guessing whether $x->y = $z is going to copy or not. Possibly such struct types should indeed use the array access syntax, because array access is generally copy-on-write (the exception being ArrayAccess objects). > I think having a no-constructor construction syntax is also a good > idea. I've discussed it with a few people, but don't can't remember if > it's ever been brought up on-list. Basically, the idea is to use a > JSON-like syntax with the type-name in front, and I think it can be > fine to use on regular classes that don't have a constructor too: > > struct Point2d { > float $x; > float $y; > } > > $origin = Point2D { x: 0, y: 0 }; > > This syntax has no conflicts. We could also add an object literal > syntax for creating ad-hoc stdClass objects like so: `$obj = { x: 1, > y: 1}`. This has an ambiguity, but I believe I have solved the issue > without too much trouble once before. > This syntax has no conflicts in the sense that the grammar is unambiguous, but I believe it does conflict under LR(1). The problem is the alternative array access syntax, which makes Point2D { x } currently valid syntax. We can distinguish it at the ":", but by this point a shift/reduce descision on "{" must have already been made. (We can likely hack around this.) Nikita --0000000000009a28c4058423aa14--