Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Ruby > Static group references in recursive pattern (Ruby 1.9)

Reply
Thread Tools

Static group references in recursive pattern (Ruby 1.9)

 
 
Wolfgang Nádasi-Donner
Guest
Posts: n/a
 
      06-29-2006
I've recognized an additional problem, which might come from wrong
expectations.

A short program:

palindrome = [ "rr",
"rer",
"reer"]

palindrome.each do |text|
if (md = text.match(/^(?<o>|.|(??<i>.)\g<o>\k<i>))$/))
puts "'#{text}' is a palindrome"
puts md[1]
puts md[2]
else
puts "no match for '#{text}'"
end
end

Results in:

'rr' is a palindrome
rr
r
'rer' is a palindrome
rer
r
no match for 'reer'

I'm surprised that named groups, that are defined inside a named group a
like "global references". Is there a possibility to change this behaviour,
that "\k<i>" refers to the associated "(?<i>.)" in the actual recursive call
(like "local variables").

Best regards, Wolfgang Nadasi-Donner


 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Recursive functions Vs Non-recursive functions - performance aspect vamsi C Programming 21 03-09-2009 10:53 PM
First post, recursive references with pickle. mark starnes Python 1 11-10-2008 09:36 PM
Two recursive calls inside of a recursive function n00m C++ 12 03-13-2008 03:18 PM
recursive method and references Sci000 Lem. Ruby 2 07-21-2006 10:25 AM
renaming 'references' to functions can give recursive problems peter Python 9 02-17-2005 05:40 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57