Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:111376 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 26040 invoked from network); 8 Aug 2020 16:00:58 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 8 Aug 2020 16:00:58 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 903A51804CD for ; Sat, 8 Aug 2020 07:59:38 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-wr1-f51.google.com (mail-wr1-f51.google.com [209.85.221.51]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Sat, 8 Aug 2020 07:59:38 -0700 (PDT) Received: by mail-wr1-f51.google.com with SMTP id r2so4231620wrs.8 for ; Sat, 08 Aug 2020 07:59:38 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=subject:to:references:from:message-id:date:user-agent:mime-version :in-reply-to:content-transfer-encoding:content-language; bh=4TaBHvpQXM3Dy99rO4q8eflpOIlmyzpuEd9rt/H1P1c=; b=T6qK5G61H8VIXQAutW263pQe/WVgFSWKDaPoaw9MJzIQazrxIdwDk1oy0WisuHH7Vk CQbsiXgfffDhhPFuGYyB9CqykbVr82KP3RyVf7zSzP9NJG+X3USR8/mXTG/a+DCR4JND 5xjElZxwH3pcqiV1Lrh0RaTDMj+jW/nvg31MFbNRqdYI/w2SR3d/w5hnKn8C4LYAsobt lQI1AvCYdoU3usZGOsXa03yqS0jNDuF+91DgbTUZrh9tJo27DrznDeVXDHopt4Mukl9P NPhXh2b6YJNcmLCv+LY/1GhA5QwrnCbJ2ALoeLPBfFevuJPk5AgMP5QQmoQ2RD7MlIEP OQAQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:subject:to:references:from:message-id:date :user-agent:mime-version:in-reply-to:content-transfer-encoding :content-language; bh=4TaBHvpQXM3Dy99rO4q8eflpOIlmyzpuEd9rt/H1P1c=; b=uJBh6duSB3K5HCQcVVtIJZj6yLbmp0/v0Hpd5fYBcrn9SowccZaIKdSSavzlheA/XA H7/DYgbDJDoZ79K9meCYKfOdDlCBEHSh/koDmPBbOPar2OFTzngstT65MEeIddk7Tj1W Ije0fO3Glm8WCPNoW7qI3vqNJLlmJ1vzJC2ABDTohlQc8WotyzQGjS9TqDaWvy3JrR4d JIso449XNgDDZYPanWswzoP/ab6BxIkYw4bXrdVi2WaFfFqz3cw7qQV1cE6+qheFocb/ wHQR9l7JSjXcy5qkvZgs/v8NPCsMVJAfSN4DFATuFEcLsMUaAZ1/tzOEqo9yUQz3iojB 2VMA== X-Gm-Message-State: AOAM532yed1gcwdWwX7vcVfv6QgzDhbvhKylWyTJoCw8oFhmd5vTBbhY hKug69fRGx2JICzDgtmdr/9x1vkM X-Google-Smtp-Source: ABdhPJyqdKlGzdu//HHFgs3HdCOMaDtHzIXWA6/XWEMWtDoBRPLH425V7gg93Wf+sfbxr+KOVTIpFQ== X-Received: by 2002:adf:fd41:: with SMTP id h1mr17846436wrs.124.1596898776591; Sat, 08 Aug 2020 07:59:36 -0700 (PDT) Received: from [192.168.0.22] (cpc84253-brig22-2-0-cust114.3-3.cable.virginm.net. [81.108.141.115]) by smtp.googlemail.com with ESMTPSA id m126sm14588180wmf.3.2020.08.08.07.59.35 for (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Sat, 08 Aug 2020 07:59:35 -0700 (PDT) To: internals@lists.php.net References: <5f2e9e38.1c69fb81.a2272.df96SMTPIN_ADDED_MISSING@mx.google.com> Message-ID: <639cc522-998c-5886-8ed7-39086c91b0dd@gmail.com> Date: Sat, 8 Aug 2020 15:59:31 +0100 User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:68.0) Gecko/20100101 Thunderbird/68.11.0 MIME-Version: 1.0 In-Reply-To: <5f2e9e38.1c69fb81.a2272.df96SMTPIN_ADDED_MISSING@mx.google.com> Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8bit Content-Language: en-GB Subject: Re: [PHP-DEV] Re: Proposal: shorthand syntax for initializing arbitrary-precision("bigint") numbers? From: rowan.collins@gmail.com (Rowan Tommins) On 08/08/2020 13:44, Andrea Faulds wrote: > 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 That reminds me more of C++'s "user-defined literals"; https://docs.microsoft.com/en-us/cpp/cpp/user-defined-literals-cpp?view=vs-2019 has a decent introduction, and https://stackoverflow.com/q/237804/157957 some discussion of their advantages. As you say, they are basically sugar around a function call (implemented in C++ as an operator overload, because that's a hammer they had available). An interesting advantage in PHP would come if we could limit literals to be computable at compile-time: * They could be pre-computed and cached on compilation, saving a function call. * They could be used in restricted contexts such as constant definitions and parameter defaults. Initially, this would probably mean restricting them to built-in types, but could potentially be opened up to userland later once some other pieces were in place (structs feel closely related). Regardless of the syntax, having a BigNum type constructible at compile-time would be a big advantage over GMP, especially if it could be generalised to expressions of multiple BigNums: const GOOGOL = 10_bignum ** 100; // type of result inferred from one operand, in the same way that 10*2 !== 10.0*2 const GOOGOLPLEX = 10 ** GOOGOL; // type of result inferred from existing constant function waste_time(BigNum $iterations = GOOGOLPLEX) { ... } Regards, -- Rowan Tommins (né Collins) [IMSoP]