2016-11-14 22:34 GMT+01:00 CodeDmitry <dimamakh...@gmail.com>: > Is there a way to stop Pharo from preventing me from shadowing blocks? >
There is no setting for ignoring this warning, but you can compile the code in a non-interactive way: Object compile: 'foo [ :superenv | | env | env := Dictionary new. [ :superenv | | env | env := Dictionary new. [ :superenv | | env | env := Dictionary new "..." ] value: env ] value: env ] value: nil' > > [:superenv | > |env| > env := Dictionary new. > > [:superenv | > |env| > env := Dictionary new. > [:superenv | > |env| > env := Dictionary new. > > "..." > ] value: env. > ] value: env. > ] value: nil. > > It says superenv name already defined, even though that is the whole point, > I want to demonstrate dynamic links, eg: > > var env_get = function(env, varname) { > var tenv = env; > > while (true) { > if (tenv.hasOwnProperty(varname)) { > return tenv[varname]; > } else { > if (tenv.superenv == null) { > throw "no such variable" + tenv; > } else { > tenv = tenv.superenv; > } > } > } > }; > > (function(superenv) { > var env = { > 'superenv': superenv, > 'one': 1 > }; > > console.log(env_get(env, "one")); > > (function(superenv) { > var env = { > 'superenv': superenv, > 'two': 2 > }; > console.log(env_get(env, "one")); > console.log(env_get(env, "two")); > > (function(superenv) { > var env = { > 'superenv': superenv, > 'three': 3 > } > console.log(env_get(env, "one")); > console.log(env_get(env, "two")); > console.log(env_get(env, "three")); > })(env); > })(env); > })(null); > > in JavaScript > > and > > (defun env_get (env varname) (let > ((tenv)) > (setq tenv env) > > (loop (let > ((val)) > > (setq val (gethash varname tenv)) > (if val > (return val) > (let > ((superenv)) > (setq superenv (gethash 'superenv tenv)) > > (if superenv > (setq tenv superenv) > (return 'undefined) > ) > ) > ) > )) > )) > > ((lambda (superenv) (let > ((env)) > > (setq env (make-hash-table)) > (setf (gethash 'superenv env) nil) > (setf (gethash 'one env) 1) > > (print (env_get env 'one)) > (print (env_get env 'two)) > (print (env_get env 'three)) > > ((lambda (superenv) (let > ((env)) > > (setq env (make-hash-table)) > (setf (gethash 'superenv env) superenv) > (setf (gethash 'two env) 2) > > (print (env_get env 'one)) > (print (env_get env 'two)) > (print (env_get env 'three)) > > ((lambda (superenv) (let > ((env)) > > (setq env (make-hash-table)) > (setf (gethash 'superenv env) superenv) > (setf (gethash 'two env) 2) > (setf (gethash 'three env) 3) > > (print (env_get env 'one)) > (print (env_get env 'two)) > (print (env_get env 'three)) > )) env) > )) env) > )) nil) > > in Lisp. > > > > > > -- > View this message in context: http://forum.world.st/scope- > shadowing-problem-tp4923049.html > Sent from the Pharo Smalltalk Users mailing list archive at Nabble.com. > >