Showing posts with label global.variables. Show all posts
Showing posts with label global.variables. Show all posts

Saturday, December 11, 2010

dumping globals in node.js REPL

This seems handy in the node REPL.  It exploits a JS3 flaw in the failure to send new to a function 'creating' an instance.  The this in the dump function gets the context above and not ourself.
> function Fexp() { for (var v in this) { console.log(v) }; return this}
> var ex = Fexp();
global
process
GLOBAL
root
setTimeout
setInterval
clearTimeout
clearInterval
console
Buffer
module
require
_
from my running console. Was there an easier way?
See http://nodejs.org/docs/v0.3.1/api/repl.html

Friday, December 10, 2010

Inspecting Global Variables in Pharo Smalltalk 1.1.1

I cannot resist posting this: it creates an interable collection of associations of all current global identifiers and their current types:

"A recipe from Squeak wiki at http://wiki.squeak.org/squeak/1824

Smalltalk keys select:
   [:k | ((Smalltalk at: k) isKindOf: Class) not]
     thenCollect:
        [:k | k -> (Smalltalk at: k) class]


"The code is in SystemDictionary's class comment."

Smalltalk implementations and VM's are evolving - but just compare what has to be done today in other dynamic languages to achieve the same ...

One notable exception is the Io Lobby object.  With a little care, the same result can be very succinct in Rebol 2.7.6. and even simpler in Rebol3.

Here is a node.js shell result on startup:
for (var s in process) { s}
'listeners'
In a Pharo One-Click I get an Array of 127 assocs.

Python does have dir(obj) which is hardly a Smalltalk inspection widget ...

in JavaScript there had been access to the Arguments object for a top-level function callee/caller to get into the activation/call object - But what will that kludge's fate be now that ECMAScript5 is here and Mozilla JavaScript 2.0 is coming?

In all fairness, in Smalltalk and Rebol the unwary traditionally can clobber anything.  But in Smalltalk you can inspect almost anything non-primitive - even during startup. And a bootstrapping JavaScript interpreter written in JavaScript achieves almost the same transparency.  See also: The avocado variant of Lively-Kernel.

see: JavaScript Function.call and Function.apply and ECMAScrip5 Function.prototype.bind