r29110 - docs/Perl6/Spec
Author: lwall Date: 2009-11-17 18:28:47 +0100 (Tue, 17 Nov 2009) New Revision: 29110 Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S09-data.pod Log: [S02,S09] break the assumption that Rats should be symmetrical Add Ratio for performance-destroying but truly arbitrary-precision rationals rename STASH to Stash for consistency Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-17 16:09:39 UTC (rev 29109) +++ docs/Perl6/Spec/S02-bits.pod2009-11-17 17:28:47 UTC (rev 29110) @@ -13,8 +13,8 @@ Created: 10 Aug 2004 -Last Modified: 09 Nov 2009 -Version: 187 +Last Modified: 17 Nov 2009 +Version: 188 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -674,13 +674,23 @@ However, for pragmatic reasons, CRat values are guaranteed to be exact only up to a certain point. By default, this is the precision -that would be represented by a Crat64 type, that is, with a numerator -and denominator consisting of Cint64 values. CRats that would require -more than 64 bits of storage in either numerator or denominator are -automatically converted to CNums. (If rationals are defined by a -role, it may be possible to instantiate a CRat type with a different -maximum precision.) +that would be represented by the CRat64 type, which has a numerator +of CInt but is limited to a denominator of Cint64. A CRat64 that +would require more than 64 bits of storage in the denominator is +automatically converted either to a CNum or to a lesser-precision +CRat, at the discretion of the implementation. (Native types such +as Crat64 limit the size of both numerator and denominator, though +not to the same size. The numerator should in general be twice the +size of the denominator to support user expectations. For instance, +a Crat8 should actually support Cint16/int8, allowing +numbers like C100.01 to be represented, and a Crat64, +defined as Cint128/int64, can hold the number of seconds since +the Big Bang with picosecond precision. Though perhaps not with +picosecond accuracy...) +For applications that really need arbitrary precision denominators +as well as numerators, CRatio may be used, which is defined as CInt/Int. + =item * Perl 6 should by default make standard IEEE floating point concepts @@ -959,6 +969,7 @@ int native signed integer uintnative unsigned integer (autoboxes to Int) buf native buffer (finite seq of native ints or uints, no Unicode) +rat native rational num native floating point complex native complex number boolnative boolean @@ -1073,8 +1084,9 @@ Str Perl string (finite sequence of Unicode characters) Bit Perl single bit (allows traits, aliasing, undef, etc.) Int Perl integer (allows Inf/NaN, arbitrary precision, etc.) -Num Perl number (approximate Real) -Rat Perl rational (exact Real) +Num Perl number (approximate Real, generally via floating point) +Rat Perl rational (exact Real, limited denominator) +Ratio Perl rational (unlimited precision in both parts) Complex Perl complex number BoolPerl boolean Exception Perl exception @@ -1115,7 +1127,8 @@ native TAI value. In numeric context a CDuration happily returns a CNum representing seconds. If pressed for a number, an CInstant will return the length of time in atomic seconds from the TAI epoch, -but it will be unhappy about it. Systems which cannot provide +but it will be unhappy about it. (The time will be returned as a CRat +to preserve maximal precision and accuracy.) Systems which cannot provide a steady time base, such as POSIX systems, will simply have to make their best guess as to the correct atomic time. @@ -1128,6 +1141,7 @@ Int Numeric Integral Num Numeric Real Rat Numeric Real +Ratio Numeric Real Complex Numeric BoolBoolean Exception Failure @@ -1169,7 +1183,7 @@ Macro Perl compile-time subroutine Regex Perl pattern Match Perl match, usually produced by applying a pattern -STASH A symbol table hash (package, module, class, lexpad, etc) +Stash A symbol table hash (package, module, class, lexpad, etc) SoftRoutine A routine that is committed to staying mutable The CKeyHash role differs from a normal CAssociative hash in how it handles default @@ -1231,7 +1245,7 @@ Macro Callable Regex Callable Match Positional Associative -STASH Associative +Stash Associative SoftRoutine Routine See LS06/Wrapping for a discussion of soft vs. hard routines. Modified: docs/Perl6/Spec/S09-data.pod
r29111 - docs/Perl6/Spec
Author: lwall Date: 2009-11-17 18:43:12 +0100 (Tue, 17 Nov 2009) New Revision: 29111 Modified: docs/Perl6/Spec/S02-bits.pod Log: [S02] more Rat and Ratio clarification Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-17 17:28:47 UTC (rev 29110) +++ docs/Perl6/Spec/S02-bits.pod2009-11-17 17:43:12 UTC (rev 29111) @@ -649,12 +649,11 @@ machines that are not natively 2's complement. You must convert to and from CInt to do portable bitops on such ancient hardware.) -(CNum may support arbitrary-precision floating-point arithmetic, but -is not required to unless we can do so portably and efficiently. CNum -must support the largest native floating point format that runs at full -speed.) +CNum must support the largest native floating point format that +runs at full speed. It may be bound to an arbitrary precision type, +but by default it is the same type as a native Cnum. See below. -CRat supports arbitrary precision rational arithmetic. +CRat supports extended precision rational arithmetic. Dividing two CInt objects using C infix:/ produces a a CRat, which is generally usable anywhere a CNum is usable, but may also be explicitly cast to CNum. (Also, if either side is @@ -688,8 +687,14 @@ the Big Bang with picosecond precision. Though perhaps not with picosecond accuracy...) -For applications that really need arbitrary precision denominators -as well as numerators, CRatio may be used, which is defined as CInt/Int. +For applications that really need arbitrary precision denominators as +well as numerators at the cost of performance, CRatio may be used, +which is stored as CInt/Int, that is, as arbitrary precision in +both parts. There is no literal form for a CRatio, so it must +be constructed using CRatio.new($nu,$de). In general, only math +operators with at least one CRatio argument will return another +CRatio, to prevent accidental promotion of reasonably fast CRat +values into arbitrarily slow CRatio values. =item *
r29112 - docs/Perl6/Spec
Author: lwall Date: 2009-11-17 19:22:58 +0100 (Tue, 17 Nov 2009) New Revision: 29112 Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S04-control.pod docs/Perl6/Spec/S06-routines.pod docs/Perl6/Spec/S11-modules.pod Log: [specs] s/CONTEXT/DYNAMIC/ to avoid confusion of concepts Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-17 17:43:12 UTC (rev 29111) +++ docs/Perl6/Spec/S02-bits.pod2009-11-17 18:22:58 UTC (rev 29112) @@ -14,7 +14,7 @@ Created: 10 Aug 2004 Last Modified: 17 Nov 2009 -Version: 188 +Version: 189 This document summarizes Apocalypse 2, which covers small-scale lexical items and typological issues. (These Synopses also contain @@ -2030,7 +2030,7 @@ PROCESS # Process-related globals (superglobals) COMPILING # Lexical symbols in the scope being compiled CALLER # Contextual symbols in the immediate caller's lexical scope -CONTEXT # Contextual symbols in my or any caller's lexical scope +DYNAMIC # Contextual symbols in my or any caller's lexical scope The following relative names are also reserved but may be used anywhere in a name: @@ -2283,18 +2283,18 @@ =item * -The CCONTEXT pseudo-package is just like CCALLER except that +The CDYNAMIC pseudo-package is just like CCALLER except that it starts in the current dynamic scope and from there scans outward through all dynamic scopes until it finds a contextual variable of that name in that dynamic context's associated lexical pad. (This search is implied for variables with the C* twigil; hence C$*FOO is -equivalent to C CONTEXT::$*FOO .) If, after scanning outward +equivalent to C DYNAMIC::$*FOO .) If, after scanning outward through all those dynamic scopes, there is no variable of that name in any immediately associated lexical pad, it strips the C* twigil out of the name and looks in the CGLOBAL package followed by the CPROCESS package. If the value is not found, it returns failure. -Unlike CCALLER, CCONTEXT will see a contextual variable that is +Unlike CCALLER, CDYNAMIC will see a contextual variable that is declared in the current scope, since it starts search 0 scopes up the stack rather than 1. You may, however, use C CALLER::$*foo to bypass a contextual definition of C$*foo in your current context, Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-11-17 17:43:12 UTC (rev 29111) +++ docs/Perl6/Spec/S04-control.pod 2009-11-17 18:22:58 UTC (rev 29112) @@ -13,8 +13,8 @@ Created: 19 Aug 2004 -Last Modified: 12 Nov 2009 -Version: 87 +Last Modified: 17 Nov 2009 +Version: 88 This document summarizes Apocalypse 4, which covers the block and statement syntax of Perl. @@ -634,8 +634,8 @@ Although a bare block occuring as a single statement is no longer a do-once loop, it still executes immediately as in Perl 5, as if it were immediately dereferenced with a C.() postfix, so within such a -block CCONTEXT:: refers to the scope surrounding the block. But unlike -an explicit call, CCALLER:: doesn't count it as a routine boundary. +block CCALLER:: refers to the dynamic scope associated +with the lexical scope surrounding the block. If you wish to return a closure from a function, you must use an explicit prefix such as Creturn or Csub or C - . Modified: docs/Perl6/Spec/S06-routines.pod === --- docs/Perl6/Spec/S06-routines.pod2009-11-17 17:43:12 UTC (rev 29111) +++ docs/Perl6/Spec/S06-routines.pod2009-11-17 18:22:58 UTC (rev 29112) @@ -2140,9 +2140,9 @@ CCapture object is generated, not when it is later bound (which could happen more than once). -=head2 The Ccontext and Ccaller functions +=head2 The Cdynamic and Ccaller functions -The Ccontext function takes a list of matchers and interprets them +The Cdynamic function takes a list of matchers and interprets them as a navigation path from the current context to a location in the dynamic scope, either the current context itself or some context from which the current context was called. It returns an object @@ -2153,18 +2153,18 @@ The current context is accessed with a null argument list. -say file , context().file, - line , context().line; +say file , dynamic().file, + line , dynamic().line; which is equivalent to: -say file , CONTEXT::$?FILE, - line , CONTEXT::$?LINE; +say file , DYNAMIC::$?FILE, + line , DYNAMIC::$?LINE; The immediate caller of this context is accessed by skipping one level: -say file , context(1).file, - line , context(1).line; +say file , dynamic(1).file, + line , dynamic(1).line; You might think that that must be the current function's caller,
r29113 - docs/Perl6/Spec
Author: lwall Date: 2009-11-17 19:37:41 +0100 (Tue, 17 Nov 2009) New Revision: 29113 Modified: docs/Perl6/Spec/S02-bits.pod Log: [S02] more clarifications from TheDamian++ Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-17 18:22:58 UTC (rev 29112) +++ docs/Perl6/Spec/S02-bits.pod2009-11-17 18:37:41 UTC (rev 29113) @@ -2735,10 +2735,11 @@ =item * -Complex literals are similarly indicated by writing an addition of +Complex literals are similarly indicated by writing an addition or subtraction of two real numbers without spaces: 5.2+1e42i +3-1i As with rational literals, constant folding would produce the same complex number, but this form parses as a single term, ignoring @@ -2870,6 +2871,7 @@ a = $a :$a a = @a :@a a = %a :%a +a = a :a a = $$a:$$a a = @$$a :@$$a (etc.) a = %fooa%fooa:p @@ -3500,10 +3502,10 @@ foo:# label -- must be label at statement boundary. -- ILLEGAL otherwise foo: bar: # two labels in a row, okay -.foo: # $_.foo: 1 -- must be dot method with : args +.foo: 1 # $_.foo: 1 -- must be dot method with : args .foo(1) # $_.foo(1) -- must be dot method with () args .foo# $_.foo() -- must be dot method with no args -.$foo: # $_.$foo: 1-- indirect dot method with : args +.$foo: 1# $_.$foo: 1-- indirect dot method with : args foo bar: 1 # bar.foo(1)-- bar must be predecl as class -- sub bar allowed here only if 0-ary -- otherwise you must say (bar): @@ -3586,6 +3588,8 @@ __END__ =begin END __DATA__=begin DATA +[Note: this paragraph is speculative and subject to drastic change +as S26 evolves.] The C=begin END Pod stream is special in that it assumes there's no corresponding C=end END before end of file. The CDATA stream is no longer special--any Pod stream in the current file
r29121 - docs/Perl6/Spec
Author: lwall Date: 2009-11-18 01:53:40 +0100 (Wed, 18 Nov 2009) New Revision: 29121 Modified: docs/Perl6/Spec/S02-bits.pod docs/Perl6/Spec/S09-data.pod Log: [S02,S09] more tweakage of rat semantics Rat types are instantiations of a Rational role as suggested by moritz_++ Modified: docs/Perl6/Spec/S02-bits.pod === --- docs/Perl6/Spec/S02-bits.pod2009-11-17 23:59:27 UTC (rev 29120) +++ docs/Perl6/Spec/S02-bits.pod2009-11-18 00:53:40 UTC (rev 29121) @@ -629,12 +629,15 @@ are generally not used directly as object types. For instance all the numeric types perform the CNumeric role, and all string types perform the CStringy role, but there's no -such thing as a Numeric object. Common roles include: +such thing as a Numeric object, since these are generic +types that must be instantiated with extra arguments to produce +normal object types. Common roles include: Stringy Numeric Real Integral +Rational Callable Positional Associative @@ -654,7 +657,7 @@ but by default it is the same type as a native Cnum. See below. CRat supports extended precision rational arithmetic. -Dividing two CInt objects using C infix:/ produces a +Dividing two CIntegral objects using C infix:/ produces a a CRat, which is generally usable anywhere a CNum is usable, but may also be explicitly cast to CNum. (Also, if either side is CNum already, C infix:/ gives you a CNum instead of a CRat.) @@ -673,7 +676,8 @@ However, for pragmatic reasons, CRat values are guaranteed to be exact only up to a certain point. By default, this is the precision -that would be represented by the CRat64 type, which has a numerator +that would be represented by the CRat64 type, which is an alias for +CRational[Int,int64], which has a numerator of CInt but is limited to a denominator of Cint64. A CRat64 that would require more than 64 bits of storage in the denominator is automatically converted either to a CNum or to a lesser-precision @@ -681,21 +685,36 @@ as Crat64 limit the size of both numerator and denominator, though not to the same size. The numerator should in general be twice the size of the denominator to support user expectations. For instance, -a Crat8 should actually support Cint16/int8, allowing +a Crat8 actually supports CRational[int16,int8], allowing numbers like C100.01 to be represented, and a Crat64, -defined as Cint128/int64, can hold the number of seconds since -the Big Bang with picosecond precision. Though perhaps not with -picosecond accuracy...) +defined as CRational[int128,int64], can hold the number of seconds since +the Big Bang with attosecond precision. Though perhaps not with +attosecond accuracy...) For applications that really need arbitrary precision denominators as -well as numerators at the cost of performance, CRatio may be used, -which is stored as CInt/Int, that is, as arbitrary precision in -both parts. There is no literal form for a CRatio, so it must -be constructed using CRatio.new($nu,$de). In general, only math -operators with at least one CRatio argument will return another -CRatio, to prevent accidental promotion of reasonably fast CRat -values into arbitrarily slow CRatio values. +well as numerators at the cost of performance, CFatRat may be used, +which is defined as CRational[Int,Int], that is, as arbitrary precision in +both parts. There is no literal form for a CFatRat, so it must +be constructed using CFatRat.new($nu,$de). In general, only math +operators with at least one CFatRat argument will return another +CFatRat, to prevent accidental promotion of reasonably fast CRat +values into arbitrarily slow CFatRat values. +Although most rational implementations normalize or reduce fractions +to their smallest representation immediately through a gcd algorithm, +Perl allows a rational datatype to do so lazily at need, such as +whenever the denominator would run out of precision, but avoid the +overhead otherwise. Hence, if you are adding a bunch of CRats that +represent, say, dollars and cents, the denominator may stay 100 the +entire way through. The C.nu and C.de methods will return these +unreduced values. You can use C$rat.=norm to normalize the fraction. +The C.perl method will produce a decimal number if the denominator is +a multiple of 10. Otherwise it will normalize and return a rational +literal of the form -47/3. Stringifying a rational always converts +to CNum and stringifies that, so the rational internal form is +somewhat hidden from the casual user, who would generally prefer +to see decimal notation. + =item * Perl 6 should by default make standard IEEE floating point concepts @@ -1091,7 +1110,7 @@ Int Perl integer (allows Inf/NaN, arbitrary precision, etc.) Num Perl number (approximate Real, generally via floating point) Rat Perl rational (exact Real, limited denominator) -
Re: r29113 - docs/Perl6/Spec
On Tue, 17 Nov 2009, pugs-comm...@feather.perl6.nl wrote: +++ docs/Perl6/Spec/S02-bits.pod 2009-11-17 18:37:41 UTC (rev 29113) @@ -2735,10 +2735,11 @@ =item * -Complex literals are similarly indicated by writing an addition of +Complex literals are similarly indicated by writing an addition or subtraction of two real numbers without spaces: 5.2+1e42i +3-1i As with rational literals, constant folding would produce the same complex number, but this form parses as a single term, ignoring What happens then to negation of a literal? -5-2i or even - 5-2i Unless that's also a single term, you'd wind up negating the -2i back to +2i, which is almost certainly not what's wanted. Perhaps we could just stick to the + form, and add a prefix conjugation operator? Some possible spellings include: conj ⎺ high bar (reminiscent of the mathematical over-bar notation) ⌇ verticle squiggly line ⇅ up-and-down arrow (since it inverts imaginary but not real parts) -Martin