From: Dan Doel Date: 2003-11-27T01:04:25+09:00 Subject: Re: Controlled block variables David A. Black wrote: >I can see what you're getting at, but I don't agree that it's clean, >because it involves so much magic; in particular, both the program and >the programmer would have to know what the names of the variables from >the proc's creation context were, which means things get very >unencapsulated and very coupled. > > Actually, I meant that the way of specifying that you want dynamic scoping was clean. If Proc had another method similar to #call that used dynamic scoping, that'd be rather weird, but "eval proc" seems to convey the idea without talking about lexical scoping and dynamic scoping at all. That said, dynamic scoping isn't for everyone. Common Lisp is, for the most part, dynamically scoped, which I personally don't like, but it has its uses. For example: (let ((*print-circle* t)) (print some-circular-data-structure)) Where (print) uses the flag *print-circle* flag to determine whether or not to safely print circular lists. *print-circle* is seen as true in that call, but it may not be in the general global environment. The alternative would be: (let ((old-pcircle *print-circle*)) (setf *print-circle* t) (print some-circular-data-structure) (setf *print-circle* old-pcircle)) Dynamic scoping isn't for everyone (like I said, I don't like it much), but it can have its uses. On the other hand, I'm not sure how generally useful this would be in Ruby, as global-ish flags like *print-circle* would certainly be frowned upon, and it would only be available in Procs, and one doesn't normally use Proc objects in global variables as print routines. Perhaps someone smarter than I will come up with something using dynamic scoping that would be otherwise tedious in Ruby. Anyhow, I'm not overly attached to the idea. It was more of a what if/why don't we have this ramble. - Dan