From: David Unric Date: 2010-11-10T10:50:48+09:00 Subject: Re: Analyzer for errors in code ? Ryan Davis wrote in post #960436: > > In python, 'mymsg' _has_ to be a variable. This isn't true in ruby. It > can be a variable OR a method call. In the case of the latter, we don't > know if it is valid or not without evaluating. > > in ruby, 'def x; mymsg; end' (the most boiled down version of your > example) looks like this internally: > > % echo 'def x; mymsg; end' | parse_tree_show > s(:defn, > :x, > s(:args), > s(:scope, s(:block, s(:call, nil, :mymsg, s(:arglist))))) > > Ruby parsed the code and decided that mymsg must be a method call. It is > determined at runtime (since everything is late bound) who (if anyone) > implemented the method and if not, it goes to method_missing. > > Python simply doesn't have this flexibility. 'x' is a variable and 'x()' > is a call. AFAIK, there is no "__" hook equivalent to method_missing in > python... But it has been a while for me. Great info Ryan, thank you. My appologies I did not realized sooner the deeper conceptual differencies between these languages. Despite of that, if Ruby cann't decide if mymsg is a variable or a method call in advance, how does it rule out the possibility for a static parser to notify the 'mymsg' symbol has no assignment or method definiton in the source code ? I.e. if 'x' in your example is a method call, how can arise without some form of an assignment ? -- Posted via http://www.ruby-forum.com/.