From: David Unric Date: 2010-11-10T16:52:50+09:00 Subject: Re: Analyzer for errors in code ? Ryan Davis wrote in post #960452: > So let's try again, with the code sample reformatted better: > >> % echo 'def x; mymsg; end' | parse_tree_show > > begets: > >> s(:defn, :x, s(:args), >> s(:scope, >> s(:block, >> s(:call, nil, :mymsg, s(:arglist))))) > > read in English: "method definition :x with no args. calls mymsg w/ no > args" > > So, ruby parsed "def x;" and realized it was a 0 arg method. The body > refers to "mymsg;" and since there was no previous variable assignment > of the same name, it must be a method call (with no args). That's it. At > that point, the method is "compiled" down to a single method invocation > for the message "mymsg". Notice I said "message"... that's an important > distinction between static and dynamic languages. In static languages > (or in dynamic/hybrid languages where the method is pre-calculated), > methods/functions are called by having a pointer to the function body > and simply jumping to that address. > > In a dynamic invocation, a receiver is sent "a message" at runtime. This > roughly translates to asking the hierarchy of classes if they implement > that message, and if so, to please execute it. If not, then the runtime > does the same thing, but this time around the message is > "method_missing" with the previous message pushed onto the front of the > args. First sorry for the confusion, I had 'mymsg'in your x method example in mind, of course. Second, thank you for the more detailed explanation. It closely describes what is done during code execution by interpreter's point of view. From the static/naive human code reader's point of view, I would search for symbol 'mymsg' in current/parent/global scope including imported modules 'if there is any assignment to this symbol': lvalue, method definition, method's argument etc. If it's not found, thus 'mymsg' symbol is suspicious and I would notice about it. Similar procedure I would expect from possibly naive but still handy code checker. Btw. I'm using (g)Vim editor and know about C-n shortcut but use it sparsely because it offers too much symbols at times and it only slows me down. Code completion C-x C-o makes much more sense but it doesn't work in all cases. One of reasons of my typing errors are caused by switching between various keyboards (MS Natural KB at PC and significantly different at corporate notebook). -- Posted via http://www.ruby-forum.com/.