Evaluation and control

Evaluating blocks, choosing between them and repeating them. A block is data until something evaluates it, and each of these functions decides when and how often. See deciding and repeating.

do

Evaluates a block, source text or a script file; gives the last value.

do value
  • value (any-type!)

  • /next position (word!): Evaluates only the first expression of a block; position: Set to the block after it

reduce

Evaluates each expression of a block; gives a block of the values.

reduce value
  • value (any-value!)

compose

Evaluates the parens in a block and puts their values in a copy of it.

compose value
  • value (any-value!)

  • /deep

  • /only

comment

Ignores its argument.

comment value
  • value (any-type!)

at-end

Evaluates a block once the expression that called the function running now is done; outside a function, once the code is done.

at-end body
  • body (block!)

The block is kept, not evaluated: it runs once the expression that called the function running at-end is done, before the expression after it. Several run in the order they were kept, and the value of the code around them stays its own. When that code is left early, by return or an error, they run after the code around it; outside a function, at the end of the code. machine uses it to run the hooks of its initial states once the word it is set to has the machine.

f: function [] [at-end [print "after"]  print "in f"  1]
>> x: f + 1  print "next"
in f
after
next

also

Returns the first value, after evaluating the second.

also a b
  • a (any-type!)

  • b (any-type!)

if

Evaluates the block if the condition is true; gives its value, or none.

if condition body
  • condition (any-value!)

  • body (block!)

unless

Evaluates the block if the condition is not true; gives its value, or none.

unless condition body
  • condition (any-value!)

  • body (block!)

either

Evaluates the first block if the condition is true, the second if not.

either condition true-body false-body
  • condition (any-value!)

  • true-body (block!)

  • false-body (block!)

case

Evaluates the block after the first true condition.

case cases
  • cases (block!)

  • /all

switch

Evaluates the block after the value that is equal to the one given.

switch value cases
  • value (any-value!)

  • cases (block!)

  • /default case (block!)

not

True if the value is false or none, false otherwise.

not value
  • value (any-value!)

all

Evaluates expressions while they are true; gives the last value, or none at the first false one.

all block
  • block (block!)

any

Evaluates expressions until one is true; gives it, or none.

any block
  • block (block!)

loop

Evaluates a block a number of times.

loop count body
  • count (integer!)

  • body (block!)

repeat

Evaluates a block a number of times, with a word counting from 1.

repeat 'word count body
  • 'word (word!)

  • count (integer!)

  • body (block!)

foreach

Evaluates a block for each value of a series, with a word set to it; for a map, each key, or each key and value.

foreach 'word data body
  • 'word (word! block!)

  • data (series! map!)

  • body (block!)

forall

Evaluates a block for each position of the series a word refers to.

forall 'word body
  • 'word (word!)

  • body (block!)

forskip

Evaluates a block at every so many positions of the series a word refers to.

forskip 'word size body
  • 'word (word!)

  • size (integer!)

  • body (block!)

while

Evaluates the body as long as the condition block is true.

while condition body
  • condition (block!)

  • body (block!)

until

Evaluates the block until it gives true.

until body
  • body (block!)

forever

Evaluates a block again and again, until break or return.

forever body
  • body (block!)

break

Leaves the loop it is in.

break
  • /return value (any-value!)

continue

Goes on with the next turn of the loop it is in.

continue