Jamis Buck <jgb3 / email.byu.edu> writes:

> Please don't misunderstand me.  I am not saying that every C module ever 
> written for Ruby should have been written *in* Ruby.  That would be 
> ludicrous.  I'm simply saying that for some things (compression 
> algorithms, for instance), there is some value in having them available 
> *both* as a C modules, *and* as pure Ruby modules.

A good point. That's what some Smalltalks do, but in an even more useful
way. Primitives are sometimes implemented in C (or at least in the VM
itself, rather than in pure Smalltalk). If the primitive fails or does not
exist, then alternate Smalltalk code can be run.

For example, this is from Squeak's Object class:

instVarAt: index 
    "Primitive. Answer a fixed variable in an object. The numbering of the 
    variables corresponds to the named instance variables. Fail if the
    index is not an Integer or is not the index of a fixed variable. Essential.
    See Object documentation whatIsAPrimitive."

    <primitive: 73>
    "Access beyond fixed variables."
    ^self basicAt: index - self class instSize

The Squeak Object class has a method called "whatIsAPrimitive" whose entire
purpose is to act as documentation. Here is a snippet from the comment:

    When the Smalltalk interpreter begins to execute a method which
    specifies a primitive response, it tries to perform the primitive
    action and to return a result. If the routine in the interpreter for
    this primitive is successful, it will return a value and the
    expressions in the method will not be evaluated. If the primitive
    routine is not successful, the primitive 'fails', and the Smalltalk
    expressions in the method are executed instead. These expressions are
    evaluated as though the primitive routine had not been called.

Jim
-- 
Jim Menard, jimm / io.com, http://www.io.com/~jimm/
"T-shirts are the computer industry's only persistent objects."
    -- Seen in R. L. Peskin's .sig