We can declare a function like this:
def function = { atom1 atom2 ... atomN }
Example:
def square = {dup *}
noc> 5 square
noc> 25]
=> [
noc> zapdef number = {6} # We define a constant
noc>
noc> number square36] => [
It’s like the substitution, when we called the declared function, in fact it give this:
5 dup * noc>
We can also declare a function like this:
def (function) = { atom1 atom2 ... atomN }
It’s useful for have a better syntax to define operators.
Source: std/string.noc
def ($) = {
---
Convert a string to a quote of chars
(example)"abc" $ => ['a' 'b' 'c']
---
chars }
When we declare a function, the function is pushed in the env. And we can access to this env with the 'env' command:
noc> :env square: [dup *],