really thanks Bert ;)
clear explanation... I had dome vague ideas but thats far clearer now

A module is written in C (though often the C code is generated from
Squeak code) and needs to be compiled with a C compiler. Some modules
are linked into the VM, some are external. You can list all currently
used modules using "Smalltalk listLoadedModules".

SmalltalkImage current listLoadedModules
for me on 3.9

To access a function from a C library without the need to write a
module, we have FFI primitives:

        puts: aString
                <cdecl: void 'puts' (char*) module: 'libSystem.dylib'>
                ^ExternalFunction externalCallFailed

When called, FFI looks up the function "puts" in "libSystem.dylib",
converts the Smalltalk string to a C char*, and calls the function with
it. This is for Mac OS X, on Linux, you would use " libc.so.1" and on
Windows, I don't know, maybe "system32.dll" - FFI calls are very
platform-specific. Also, they can crash Squeak easily. That's the reason
the basic Squeak system does not use FFI at all, it is used for specific
applications only, which have to deal with the platform issues.

ok :)

So primitives generally are the gateway to the world outside Smalltalk's
objects.

Additionally, some primitives are optional, they are only used to speed
up lengthy computations. Like searching in a string or adding large
numbers (ever tried "1000 factorial" ?).

yes :)
thought it was 100% object power . A bit dissapointed ;)

euhh actually, I don't see any primitive call in Integer>>factorial , only a recursive function... did I miss somrthing ?


Integer>>factorial
    "Answer the factorial of the receiver."

    self = 0 ifTrue: [^ 1].
    self > 0 ifTrue: [^ self * (self - 1) factorial].
    self error: 'Not valid for negative integers'

Thanks again Bert

Cédrick


ps: Considering pragma, is there any classical uses that can be interesting to do to work at the meta level... like Id' like to tag instance variables according to their meaning in my application. I have no idea on how to use pragma for that...
_______________________________________________
Beginners mailing list
[email protected]
http://lists.squeakfoundation.org/mailman/listinfo/beginners

Reply via email to