On Tue, 2002-09-03 at 11:35, Ken Fox wrote: > Peter Haworth wrote: > > Also the different operators used (:= inside the rule, = inside the code) > > seems a bit confusing to me; I can't see that they're really doing anything > > different: > > > > / $x := (gr\w+) / vs / (gr\w+) { let $x = $1 } / > > > > Shouldn't they both use C< := > ? > > Depends on what you want. The "$x :=" in the rule binds the > first match to $x -- it does not copy the value. The "$x =" > in the code block copies the value of the first match. You > can use either binding or assignment in the code block.
Hmm... I had not thought of the copy aspect. Certainly, the code version is more flexible. You could define C<$x> above as anything. For example: / (gr\w+) {let $x = Gr_Thing.new($1)} / The binding version is just a simple, fast version of one special case, no?