Required Named Params and go write your own grammar
As I try writing P6 programs I do find myself needing required named params, and I thought I'd like something like ++$named_req for myself as a shorthand for +$named_req is required or whatever is decided. Now, larry often says (only partly jokingly) go write your own grammar. But I do not know how I'd change/modify/append the grammar to accomodate that cosmetic change above. Needing to know the entire P6 grammar isn't mouth watering. I am sure this has been discussed before, so can somebody please point me to some place where I can start reading about this? macros does not seem to be an answer as I seem to think of them as defining syntax for new commands that you are writing. (In this case, I do not know where I would put the is parsed trait). I may be wrong and macros in some form are the answer. Either way, I'd appreciate any thoughts/answers/pointers on this. --Abhijit Abhijit A. Mahabal http://www.cs.indiana.edu/~amahabal/
Re: Required Named Params and go write your own grammar
Abhijit A. Mahabal skribis 2004-05-04 10:27 (-0500): As I try writing P6 programs I do find myself needing required named params, and I thought I'd like something like ++$named_req for myself as a shorthand for +$named_req is required or whatever is decided. What's wrong with just specifying them as positional ones? Don't document the feature and you'll effectively have required named parameters. Or am I missing something? the entire P6 grammar Are parts already available in Perl 6 rule syntax? Juerd
Re: Required Named Params and go write your own grammar
Abhijit A. Mahabal writes: As I try writing P6 programs I do find myself needing required named params, and I thought I'd like something like ++$named_req for myself as a shorthand for +$named_req is required or whatever is decided. Now, larry often says (only partly jokingly) go write your own grammar. But I do not know how I'd change/modify/append the grammar to accomodate that cosmetic change above. Needing to know the entire P6 grammar isn't mouth watering. I am sure this has been discussed before, so can somebody please point me to some place where I can start reading about this? Well, there's no official grammar for Perl 6 anywhere. The most definitive source you can find is in A6. In that document we find: rule parameter :w { [ type? zone? variable trait* defval? | \[ signature \] # treat a single array ref as an arg list ] } rule zone { [ \? # optional positional | \* # slurpy array or hash (or scalar) | \+ # optional named-only ] } It would seem that this is the place to create your ++ zone. Here we go: grammar Grammar::ReqNamed { is Grammar::Perl; rule zone { \+ before: \+ { .substr(.pos, 1) = ''; s/after: variable/is required/; fail; } | next } } That probably doesn't work. But it gets close. I'd much prefer to parse it and then change the syntax tree in the walking phase, but I don't know how to do that yet. Luke
Re: Required Named Params and go write your own grammar
On Tue, 4 May 2004, Luke Palmer wrote: Abhijit A. Mahabal writes: Needing to know the entire P6 grammar isn't mouth watering. grammar Grammar::ReqNamed { is Grammar::Perl; Ah, I see. That does answer my question. I had forgotten that grammers can be inherited from and you can change only the bits you want to change... thanks. Luke --Abhijit