Re: Array variables as formal parameters ???
HaloO, John M. Dlugosz wrote: I'm assuming that the container defines what item assignment means. At the very least, it will have the STORE method. But I want to have infix:= definable in general without having to make it masquerade as an Item Container. I strongly agree with that. It should not be the case that an assignment $x = $y; is compiled down to $x.STORE($y.FETCH); That is, the assignment is a mere syntactic device. The above procedure should be wrapped in the default implementation multi infix:= (Any $lhs is rw, Any $rhs) { $x.STORE($y.FETCH); } Note that due to contravariance the type constraint of $lhs should actually be the bottom type not Any. OTOH rw is invariant in general. Only here in assignment the $lhs is write-only. But Perl 6 hasn't specced that trait on parameters. Regards, TSa. -- The unavoidable price of reliability is simplicity -- C.A.R. Hoare Simplicity does not precede complexity, but follows it. -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan
Re: Array variables as formal parameters ???
HaloO, John M. Dlugosz wrote: Now back to straightening out my misconceptions about scalars _always_ holding item containers. If $x is bound to an Array, for example, the compiled code can't be doing the indirection innately. So it follows that the method forwarding is a property of the object that the method is originally called on. That is, the Scalar (and any tied item container implementations) are written to forward all methods to the contained object. The compiler sees $x.foo() and doesn't know anything about $x other than that it's some object, so it codes a message dispatch to it. If $x holds a normal object, the foo method gets called via the normal dispatching rules. But Scalar implements something that catches all methods and forwards them to the contained item. ===Right? I think that the implementation type of a Scalar can be compiled away in almost all cases that involve getting the value. And even in lvalue usage the only thing worth an actual runtime container is the type constraint closure to call prior to storing the rvalue. So after a $x = @a the scalar just contains the ID of the array object. That would imply that if a scalar happened to contain another scalar, e.g. my $x = Scalar.new; ($x is bound to a Scalar which contains a Scalar which contains undef) then any method called on $x would trigger the same behavior when the contained object gets it, and be forwarded all the way down, no matter how many Scalars I nested in this manner. Hmm, I think the Scalar class should not be available for generic instanciation. Scalar variables are handled through built-in features of the underlying engine and are optimized heavily. Arrays are handled by the same built-in mechanism, that is e.g. registers in Parrot. So how does VAR work? It can't just wrap another level around the original object to cancel out the automatic indirection. It can't tell the compiler to generate different code, since the code knows nothing about this interesting property of scalars. Instead it must return a proxy that knows how to trigger the actual methods on the scalar, avoiding the forwarding behavior of normal method calls. === Is that right? I would say no. The VAR instructs the compiler to use a special interface of the underlying engine facility. The interesting thing is that one needs VAR($x).readonly but can use @a.readonly directly. I would opt for VAR(@a).readonly for symmetry. Or actually this VAR interface should be all caps. Why should the Array class support a .readonly method in the first place? The compiler knows the readonly status of all variables from their lexically available definition! So does the programmer if she bothers to look them up. Regards, TSa. -- The unavoidable price of reliability is simplicity -- C.A.R. Hoare Simplicity does not precede complexity, but follows it. -- A.J. Perlis 1 + 2 + 3 + 4 + ... = -1/12 -- Srinivasa Ramanujan
Question for Larry
Can you tell me if I'm missing something fundamental here? Regarding item containers ... my @A = (1, 2, 3); my $x; # default to is Scalar $x = @A; Now $x is BOUND TO an item container of type Scalar, which CONTAINS an Array which itself CONTAINS 3 items of type Int. @A is BOUND TO a list container of type Array. my $y := @A; $y is BOUND TO the Array, same as @A is. --John
Re: Question for Larry
Em Seg, 2009-05-25 às 11:36 -0500, John M. Dlugosz escreveu: Can you tell me if I'm missing something fundamental here? While I'm not larry, I think I can help you out here ;) Regarding item containers ... my @A = (1, 2, 3); my $x; # default to is Scalar $x = @A; '$x' is the name of a variable that is in the lexpad. The sigil is part of the name, and means little at runtime... The sigil is only important at compile time for explicit context sensitiveness. So, at the end of this snippet, the lexpad contains a scalar stored at the name '$x', which then holds the array inside its cell. A few facts: * A Scalar in item context returns its value; * The dotty operator implies item context; * A list in item context returns itself; so... what happens, in detail, in the above snippet is: * an Array X is created and stored in the lexpad as the name '@A' * The contents of the list (1,2,3) is iterated, copying the values to the Array X; * an Scalar Y is created and stored in the lexpad as the name '$x' * The name '@A' is resolved to the Array X, which is used in item context, returning itself * The Scalar Y receives the rvalue to be STOREd in its cell. Now $x is BOUND TO an item container of type Scalar, which CONTAINS an Array which itself CONTAINS 3 items of type Int. Exactly. but it would probably be more clear to state that the name '$x' in the lexpad is bound to a item container, binding is something that happens to the variable as stored in the lexpad, so it's an operation that happens in the lexpad, not in the container... (that simplifying the point where the lexpad is also a container) @A is BOUND TO a list container of type Array. my $y := @A; $y is BOUND TO the Array, same as @A is. Again, binding to a variable is an operation in the lexpad, much the same way as: %ab := 1; is an operation in the hash itself, not in that specific cell of the hash. daniel
Re: Meditations on a Loop
That's an enjoyable and educational read, thanks! There's one form under TMTOWTDI that I'd like to see, but can't figure out myself. It's the version analogous to this perl5 snippet- sub odd {$_ % 2} say grep odd,0..6; -where the line that filters the list mentions no variables at all, and $_ does its work behind the curtains. perl6 golfers, what can you formulate- using anything you like in the odd sub, not adding to the Int class, not using anything with a sigil in the filter expression? I haven't figured out how to match p5's brevity yet.
r26933 - docs/Perl6/Spec
Author: moritz Date: 2009-05-25 21:49:59 +0200 (Mon, 25 May 2009) New Revision: 26933 Modified: docs/Perl6/Spec/S03-operators.pod Log: [S03] maybe a newline after the BOM unconfuses the POD parser? Modified: docs/Perl6/Spec/S03-operators.pod === --- docs/Perl6/Spec/S03-operators.pod 2009-05-25 19:35:48 UTC (rev 26932) +++ docs/Perl6/Spec/S03-operators.pod 2009-05-25 19:49:59 UTC (rev 26933) @@ -1,4 +1,5 @@ -=encoding utf8 + +=encoding utf8 =head1 TITLE
Idea: Literate programing
Hello, I really like POD and I like the changes in the upcoming Perl 6 Pod. Have you ever heard of literate programing? (see Wikipedia). I think it would be neat if Pod could do literate programing. It is already very close. For reference, please see this article: For reference, please see this page: http://www.perl.com/pub/a/tchrist/litprog.html In brief, the only thing that Pod is missing is allowing you to write code sections in whatever order is best for people to understand, and have them be re-ordered when we run the program. I would like to suggest a =ref block type (for reference) as well as the :ref() configuration option for =head* and =code, such that: start myshell.pl - =begin pod =head1 Intro This program is an infinite loop. On each iteration we read user input and do something with it. =begin code while 1 { =ref handle_input } =end code =head1 Handling user input :ref(handle_input) To handle user input we simply give the input to Perl's built-in eval() function. =begin code :ref(handle_input) print Prompt ; eval(STDIN); =end code =end pod end myshell.pl - 1) When you run perl myshell.pl, Perl would grab the second code block, move to where =ref is, and run the program normally. 2) When you run (say) pod2html myshell.pl, the code block would remain where it is, but the =ref would be replaced by a hyperlink to the second =head1. In this way, a relatively simple change makes Perl 6 Pod able to do literate programing for anyone who is interested. What do you think?
Re: Idea: Literate programing
Daniel (): [...] In this way, a relatively simple change makes Perl 6 Pod able to do literate programing for anyone who is interested. What do you think? That it sounds like a good idea for a sublanguage-extending module. // Carl
Re: Idea: Literate programing
Carl Mäsak wrote: In this way, a relatively simple change makes Perl 6 Pod able to do literate programing for anyone who is interested. What do you think? That it sounds like a good idea for a sublanguage-extending module. I'm not familiar with those. Are they hard to make? I guess that it is perfectly reasonable to make this a separate module. How would it work? Daniel.
Re: Question for Larry
Daniel Ruoso daniel-at-ruoso.com |Perl 6| wrote: A few facts: * A Scalar in item context returns its value; * The dotty operator implies item context; * A list in item context returns itself; Thanks. Exactly. but it would probably be more clear to state that the name '$x' in the lexpad is bound to a item container, binding is something that happens to the variable as stored in the lexpad, so it's an operation that happens in the lexpad, not in the container... I think you're agreeing with me. True, by $x I meant the symbol as resolved to a particular scope. lexpad is not mentioned in the synopses. Behaviorally, the symbol table such as MY:: or some package appears to be a hash that associates the declared name with the container. (that simplifying the point where the lexpad is also a container) That I don't follow. %ab := 1; is an operation in the hash itself, not in that specific cell of the hash. What? Nothing in S02, S03 or S06 suggests such a usage. := is used to alias a name The expression on the left does not name a variable, but is an expression. --John
Re: Idea: Literate programing
I think the equivalent of tangle/weave would take docs designed for literate reading and produce the runable file. Perl doesn't have to execute it directly. But that can be automated using a source filter. Daniel Carrera daniel.carrera-at-theingots.org |Perl 6| wrote: Hello, I really like POD and I like the changes in the upcoming Perl 6 Pod. Have you ever heard of literate programing? (see Wikipedia). I think it would be neat if Pod could do literate programing. It is already very close. For reference, please see this article: For reference, please see this page: http://www.perl.com/pub/a/tchrist/litprog.html In brief, the only thing that Pod is missing is allowing you to write code sections in whatever order is best for people to understand, and have them be re-ordered when we run the program. I would like to suggest a =ref block type (for reference) as well as the :ref() configuration option for =head* and =code, such that: start myshell.pl - =begin pod =head1 Intro This program is an infinite loop. On each iteration we read user input and do something with it. =begin code while 1 { =ref handle_input } =end code =head1 Handling user input :ref(handle_input) To handle user input we simply give the input to Perl's built-in eval() function. =begin code :ref(handle_input) print Prompt ; eval(STDIN); =end code =end pod end myshell.pl - 1) When you run perl myshell.pl, Perl would grab the second code block, move to where =ref is, and run the program normally. 2) When you run (say) pod2html myshell.pl, the code block would remain where it is, but the =ref would be replaced by a hyperlink to the second =head1. In this way, a relatively simple change makes Perl 6 Pod able to do literate programing for anyone who is interested. What do you think?
Re: Temporal
On Sat, 2 May 2009, Timothy S. Nelson wrote: Hi. Can someone (Dave Rolsky?) please tell me why rewriting S32/Temporal in terms of Enum roles would be bad? See the example of Enum day roles here: http://www.rakudo.org/node/39 Because day and month names are hardly universal, and forcing people to use English seems rather bizarre. What's gained from this? -dave /* http://VegGuide.org http://blog.urth.org Your guide to all that's veg House Absolute(ly Pointless) */
r26937 - docs/Perl6/Spec
Author: jdlugosz Date: 2009-05-26 01:55:20 +0200 (Tue, 26 May 2009) New Revision: 26937 Modified: docs/Perl6/Spec/S04-control.pod Log: [s04] put in C... tags, fix some ... that have the C missing, typos, true=True, etc. Improve one turn-of-the-phrase as discussed with Larry in July. Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-05-25 20:29:14 UTC (rev 26936) +++ docs/Perl6/Spec/S04-control.pod 2009-05-25 23:55:20 UTC (rev 26937) @@ -12,8 +12,8 @@ Maintainer: Larry Wall la...@wall.org Date: 19 Aug 2004 - Last Modified: 3 May 2009 - Version: 77 + Last Modified: 25 May 2009 + Version: 78 This document summarizes Apocalypse 4, which covers the block and statement syntax of Perl. @@ -100,7 +100,7 @@ constant Num $pi = 3; constant Num π = atan2(2,2) * 4; -The initializing expression is evaluated at BEGIN time. +The initializing expression is evaluated at CBEGIN time. There is a new Cstate declarator that introduces a lexically scoped variable like Cmy does, but with a lifetime that persists for the @@ -213,7 +213,7 @@ else - $b { say $b } Note that the value being evaluated for truth and subsequently bound is -not necessarily a value of type Bool. (All normal types in Perl may +not necessarily a value of type CBool. (All normal types in Perl may be evaluated for truth. In fact, this construct would be relatively useless if you could bind only boolean values as parameters, since within the closure you already know whether it evaluated to true @@ -316,7 +316,7 @@ while something() { ... $^thing ... } Nothing is ever bound implicitly, however, and many conditionals would -simply bind True or False in an uninteresting fashion. This mechanism +simply bind CTrue or CFalse in an uninteresting fashion. This mechanism is really only good for objects that know how to return a boolean value and still remain themselves. In general, for most iterated solutions you should consider using a Cfor loop instead (see below). @@ -347,7 +347,7 @@ Unlike Perl 5's Cdo-while loop, this is a real loop block now, so Cnext, Clast, and Credo work as expected. The loop conditional -on a repeat block is required, so it will be recognized even if you +on a Crepeat block is required, so it will be recognized even if you put it on a line by its own: repeat @@ -360,7 +360,7 @@ Cwhile loop at the best of times, so it's also allowed to put the loop conditional at the front, with the same meaning. (The Crepeat keyword forces the conditional to be evaluated at the end of the loop, -so it's still C's do-while semantics.) Therefore, even under GNU style +so it's still C's Cdo-while semantics.) Therefore, even under GNU style rules, the previous example may be rewritten into a very clear: repeat while $x 10 @@ -498,7 +498,7 @@ When used as statement modifiers, Cfor and Cgiven use a private instance of C$_ for the left side of the statement. The outer C$_ can be referred to as C$OUTER::_. (And yes, this implies that the -compiler may have to retroactively change the binding of $_ on the +compiler may have to retroactively change the binding of C$_ on the left side. But it's what people expect of a pronoun like it.) =head2 The do-once loop @@ -609,7 +609,7 @@ } The Ctake function essentially has two contexts simultaneously, the -context in which the gather is operating, and the context in which the +context in which the Cgather is operating, and the context in which the Ctake is operating. These need not be identical contexts, since they may bind or coerce the resulting captures differently: @@ -683,7 +683,7 @@ =head2 Other Cdo-like forms Xdo -Other similar CCode-only forms may also take bare statements, +Other similar forms, where a keyword is followed by code to be controlled by it, may also take bare statements, including Ctry, Ccontend, Casync, and Clazy. These constructs establish a dynamic scope without necessarily establishing a lexical scope. (You can always establish a lexical scope explicitly by using @@ -883,7 +883,7 @@ can use Cleave, which comes in both function and method forms. The function (or listop) form always exits from the innermost block, returning its arguments as the final value of the block exactly as -return does. The method form will leave any block in the dynamic +Creturn does. The method form will leave any block in the dynamic scope that can be named as an object and that responds to the C.leave method. @@ -945,7 +945,7 @@ Warnings are produced in Perl 6 by throwing a resumable control exception to the outermost scope, which by default prints the warning and resumes the exception by extracting a resume continuation -from the exception, which must be supplied by the warn() function +from the exception, which must be supplied by the Cwarn() function (or equivalent).
Re: Idea: Literate programing
On Tue, 26 May 2009, Daniel Carrera wrote: Carl Mäsak wrote: In this way, a relatively simple change makes Perl 6 Pod able to do literate programing for anyone who is interested. What do you think? That it sounds like a good idea for a sublanguage-extending module. I'm not familiar with those. Are they hard to make? I guess that it is perfectly reasonable to make this a separate module. How would it work? They may not be possible as the code currently stands, but according to the spec, they'll be relatively easy once you have a grip on grammars. A grammar groups regexes in the same way a class groups methods. Perl 6 itself is a grammar. So you have 3 steps: 1. Make your own grammar that inherits from the Perl 6 one 2. Override the rules that need changing 3. Replace the Perl 6 grammar with your own. Steps 1 and 3 are dead easy. Step 2 varies in difficulty depending on the changes you're making. Step 1 is something like this: grammar MyPerl6 is STD { ... } Step 3 will be something like this, I think: $~MAIN = MyPerl6; See the section on Grammars in S05. http://perlcabal.org/syn/S05.html HTH, - | Name: Tim Nelson | Because the Creator is,| | E-mail: wayl...@wayland.id.au| I am | - BEGIN GEEK CODE BLOCK Version 3.12 GCS d+++ s+: a- C++$ U+++$ P+++$ L+++ E- W+ N+ w--- V- PE(+) Y+++ PGP-+++ R(+) !tv b++ DI D G+ e++ h! y- -END GEEK CODE BLOCK-
r26938 - docs/Perl6/Spec
Author: jdlugosz Date: 2009-05-26 02:14:51 +0200 (Tue, 26 May 2009) New Revision: 26938 Modified: docs/Perl6/Spec/S04-control.pod Log: [S04] update code under do-once loop in line with current specs. Move a paragraph that was interfering with the antecedent of the following paragraph. Modified: docs/Perl6/Spec/S04-control.pod === --- docs/Perl6/Spec/S04-control.pod 2009-05-25 23:55:20 UTC (rev 26937) +++ docs/Perl6/Spec/S04-control.pod 2009-05-26 00:14:51 UTC (rev 26938) @@ -518,27 +518,23 @@ statement, or if you want to attach multiple statements. you must either use the curly form or surround the entire expression in brackets of some sort: -@primes = (do (do $_ if .prime) for 1..100); +@primes = do $_ if prime($_) for 1..100; Since a bare expression may be used as a statement, you may use Cdo on an expression, but its only effect is to function as an unmatched left parenthesis, much like the C$ operator in Haskell. That is, precedence decisions do not cross a Cdo boundary, and the missing right paren is assumed at the next statement terminator or unmatched -bracket. A Cdo is assumed immediately after any opening bracket, +bracket. A Cdo is unnecessary immediately after any opening bracket as +the syntax inside brackets is a semicolon-separated list of statements, so the above can in fact be written: -@primes = (($_ if .prime) for 1..100); +@primes = ($_ if prime($_) for 1..100); This basically gives us list comprehensions as rvalue expressions: -(for 1..100 { $_ if .prime}).say +(for 1..100 { $_ if prime($_)}).say -Since Cdo is defined as going in front of a statement, it follows -that it can always be followed by a statement label. This is particularly -useful for the do-once block, since it is offically a loop and can take -therefore loop control statements. - Another consequence of this is that any block just inside a left parenthesis is immediately called like a bare block, so a multidimensional list comprehension may be written using a block with @@ -550,6 +546,11 @@ @names = ({ $^name.$^num } for 'a'..'zzz' X 1..100); +Since Cdo is defined as going in front of a statement, it follows +that it can always be followed by a statement label. This is particularly +useful for the do-once block, since it is offically a loop and can take +therefore loop control statements. + =head2 Statement-level bare blocks Although a bare block occuring as a single statement is no longer