3

How do I calculate the number native functions in Rebol3?

(help native! prints native functions in lib but it does not return a block of words.)

UPDATE: I have corrected the question after the error highlighted by @HostileFork.

noein
  • 411
  • 2
  • 10
  • what is `lib` ? – Geeky I Dec 30 '16 at 18:54
  • Note that **type? :val = native!** is effectively **type? (:val = native!)**, which is the datatype LOGIC!, which is a "truthy" value. Hence this just gives you all the declarations in lib. – HostileFork says dont trust SE Dec 30 '16 at 22:20
  • 1
    @GeekyI `lib` is an alias for the same context as `system/contexts/lib`. It is where all of the bootstrap definitions are put. The user context where you typically write (`system/context/user`) is initially a copy of these definitions. But lib is still available, so even if you overwrite something like `print: func [x] [...]` you can get back at the original definition via `lib/print`. – HostileFork says dont trust SE Dec 30 '16 at 22:38
  • @HostileFork thanks, I was thrown off at first because `lib` is only rebol3 – Geeky I Jan 01 '17 at 12:51

2 Answers2

3

A catalog of natives (or at least words of their names) is built at boot time:

>> length? system/catalog/natives
== 160

There are more definitions in lib than just native routines. Definitions of typesets and other things. But almost every native is accessible through it at startup:

>> natives: []

>> foreach [word value] lib [if native? :value [append natives word]]

>> length? natives
== 168

A few of those differences are accounted for by synonyms (Q for QUIT, --- for COMMENT, etc):

>> difference natives system/catalog/natives
== [native action q ! min max --- bind? pwd context]

NATIVE and ACTION are special and for whatever reason do not make it into the catalog.

(Note that in current evolutions of the Ren-C build of Rebol3, there is only one FUNCTION! datatype. So there is no NATIVE? or ACTION? etc. Hence, system/catalog/natives is your only way to find this out.)

noein
  • 411
  • 2
  • 10
  • Thanks @HostileFork, you have been very clear. Sorry for the stupid error in the code (and I think that it is too late to correct the question).Why in Ren-C there is no distinction between FUNCTION!, ACTION! and NATIVE! ? – noein Dec 31 '16 at 09:40
  • @noein [See chat](http://chat.stackoverflow.com/transcript/message/34874083#34874083) – HostileFork says dont trust SE Dec 31 '16 at 20:48
0
num: 0
foreach [w val] lib [if type? :val = native! [++ num]]

gives me 700 in a "recent" build of rebol-3

Geeky I
  • 751
  • 6
  • 22