[erlang-questions] [Erlang]about "apply" function in the erlang.erl
Masklinn
masklinn@REDACTED
Tue May 17 10:18:50 CEST 2011
On 2011-05-17, at 09:51 , Bengt Kleberg wrote:
> Greetings,
>
> apply is a built in function (BIF). It is implemented in C, not Erlang.
Does it work in a similar manner to that of Smalltalks, or differently?
In Smalltalks, `Boolean ifTrue: aBlock ifFalse: aBlock` literal forms
are usually compiled to call into native code directly, so the
implementation of this message in Smalltalk code in Smalltalk VMs looks
like this:
ifTrue:trueBlock ifFalse:falseBlock
^self ifTrue:[ trueBlock call ] ifFalse: [ falseBlock call ]
which looks like it would not work, but when the form
`var ifTrue:aBlockLiteral ifFalse:aBlockLiteral` is encountered the
Smalltalk compiler takes over and replaces this with native code. So the
Smalltalk implementation is only ever hit for non-literal sends (either
non-literal blocks, or usage of selectors), and its only role is to
redirect execution to the native version.
Is the purpose (and behavior) of the pure version of erlang:apply
similar?
More information about the erlang-questions
mailing list