core functions (lib)


np has a few core functions that are not part of any library. You can invoke those functions without any prefixes.

assert( expression   message )

The assert() function executes the expression. If that expression evaluates to false, the program is interrupted, producing the message as an error.

assert(false 'that was FALSE!!1!')
1: that was FALSE!!1!
stack traceback:
	[C]: in function 'assert'

call( ƒ   [params] ) → ƒResult

call() executes the function ƒ, optionally passing any parameters that follow to it. Finally, it returns the result of the function call.

new f = { v | => v, v*2, v^2 }
print( call(f 10) )
10 20 100

first( param1   [params...] ) → result

first() takes a list of arbitrary many parameters and returns the first one that is not nil.

new t3 = 'tadaa'
print( first( t1 t2 t3 ) )

print( [params] )

Prints all the values passed to it, internally using the :toString() behavior of the objects involved.

print(: 10 20 30)
(: 10 20 30 )

raise( errorMessage )

Exits the program with an errorMessage.

raise('woah! make it stop!')
1: woah! make it stop!
stack traceback:
	[C]: in function 'raise'

select( fromIndex   ƒ⇠params )

Gets a subset of the return values produced by ƒ, starting with the value at fromIndex.

new f = { v | => v, v*2, v^2 }
print( select(3, f(10)) )

try( ƒ   [failureHandler⇠reason] ) → result

Executes the function ƒ, returning its result. If ƒ raises a fatal error during execution, the failureHandler is invoked. If no failure handler is given and ƒ raises an error, try returns false and additional error information.

print( try{ |
  } )
false fail!
  { | raise('fail!') }, 
  { | print('FAILED') })

type( value ) → typeName

Returns the name of the type of value.

print( type(:) )