Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111374 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 15629 invoked from network); 8 Aug 2020 13:45:50 -0000 Received: from unknown (HELO localhost.localdomain) (76.75.200.58) by pb1.pair.com with SMTP; 8 Aug 2020 13:45:50 -0000 To: internals@lists.php.net References: Date: Sat, 8 Aug 2020 14:44:30 +0200 User-Agent: Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:52.0) Gecko/20100101 Firefox/52.0 SeaMonkey/2.49.2 MIME-Version: 1.0 In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 8bit X-Posted-By: 46.59.72.204 Subject: Re: Proposal: shorthand syntax for initializing arbitrary-precision("bigint") numbers? From: ajf@ajf.me (Andrea Faulds) Message-ID: Hi Tyson, tyson andre wrote: > What are your thoughts on making `123_456_000_000_000_000_000_000n` a shorthand for `gmp_init('123456000000000000000000')` (or a call with equivalent results) > (similar to existing backtick string syntax is a shorthand for `shell_exec()`) We could do that, but maybe this is a good opportunity to do something with a wider benefit than GMP by having a generalised solution? GMP is already special in some ways and it would be a shame to have even more functionality that privileges it. For example, what if we allowed string prefixes to have special user-defined meanings, like: n"123_456" // expands to: gmp_init('123_456') u"foo bar" // expands to: new UnicodeString("foo bar") (some class I made up) d"123.456" // expands to: new Decimal("123.456") (also an imaginary class) This would be a similar idea to JavaScript's template string tags: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Template_literals How you'd define the mappings from prefixes to executed code, I'm not sure, but we could just make it call a function by that name in the current namespace… though that would prompt the question “why not just write `d("123.456")`, which is already possible?” and I don't have a good answer to that :) Regards, Andrea