Bypassing Type Checking: Quoted Type Specs

I've started being more verbose in type specs, putting in string descriptions of what each type means, it's getting detailed:

//
//  for-each: native [
//
//  "Evaluates a block for each value(s) in a series"
//
//      return: [
//          any-stable?     "last body result (if not NULL)"
//          ~[<null>]~      "if last body result was NULL"
//          <null>          "if BREAK encountered"
//          ghost!          "if body never ran"
//      ]
//      @(vars) "Word or block of words to set each time, no new var if $word"
//          [_ word! ^word! $word! 'word! '^word! '$word! block!]
//      data "The series to traverse"
//          [<opt> none? any-series? any-context? map! any-sequence?
//           action! quoted!]  ; action support experimental, e.g. generators
//      body "Code to evaluate each time, if BREAK encountered returns NULL"
//          [<const> block!]
//      {iterator}
//  ]
//

Natives don't do type checking in release builds on their return results. But they do check the parameters. And some of these checks are slow... often doing redundant work that the native has to do anyway in its switch() statements and inner logic.

Now: Mark Spec Blocks as Quoted to Not Check Them

//      @(vars) "Word or block of words to set each time, no new var if $word"
//          '[_ word! ^word! $word! 'word! '^word! '$word! block!]

HELP will still show the information, but you won't pay for the check. It puts the responsibility on the C code in the native to do any checking, which it essentially would have to do anyway to branch the code to the right functionality.

I'm a little bit reticent to allow you to mark RETURN as not checked for usermode functions. But I guess if the HELP emphasized it to you, it's no worse than saying you return ANY-VALUE?

This Only Applies To The Native Itself

If you extract the PARAMETER!, that parameter will be checked if you use it in TYPECHECK or MATCH or to build a new function.

1 Like