x-engine-c v0.2.13
The C engine for x-lang
Loading...
Searching...
No Matches
iter.c File Reference

Iterator primitives – make-iter, iter-next/step/empty?. More...

#include "x-prim.h"
#include "x-eval.h"
#include "x-heap.h"
#include "x-type.h"
#include "x-token.h"
#include "x-type/buffer.h"
#include "x-type/char.h"
#include "x-type/int.h"
#include "x-type/iter.h"
#include "x-type/prim.h"
#include "x-type/str.h"

Functions

static x_obj_tx_prim_make_iter (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_iter_next (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_iter_step (x_obj_t *p_base, x_obj_t *p_args)
 
static x_obj_tx_prim_iter_empty (x_obj_t *p_base, x_obj_t *p_args)
 
x_obj_tx_prim_iter_register (x_obj_t *p_base, x_obj_t *p_args)
 

Detailed Description

Iterator primitives – make-iter, iter-next/step/empty?.

Author
Jon Ruttan (jonru.nosp@m.ttan.nosp@m.@gmai.nosp@m.l.co.nosp@m.m)

Function Documentation

◆ x_prim_iter_empty()

static x_obj_t * x_prim_iter_empty ( x_obj_t p_base,
x_obj_t p_args 
)
static

x-lang (iter-empty? iter): #t when the iterator is exhausted, else #f. Reads x_iterempty directly and maps it to a real boolean.

◆ x_prim_iter_next()

static x_obj_t * x_prim_iter_next ( x_obj_t p_base,
x_obj_t p_args 
)
static

x-lang (iter-next iter): advance an iterator, returning its next element.

◆ x_prim_iter_register()

x_obj_t * x_prim_iter_register ( x_obj_t p_base,
x_obj_t p_args 
)

Register the iterator primitives.

◆ x_prim_iter_step()

static x_obj_t * x_prim_iter_step ( x_obj_t p_base,
x_obj_t p_args 
)
static

x-lang (iter-step it): step an iterator FUNCTIONALLY – returns (value . next-iterator) with the given iterator untouched, or () when exhausted. The generator view of an iterator: Gen pipelines drive C steps through this door.

◆ x_prim_make_iter()

static x_obj_t * x_prim_make_iter ( x_obj_t p_base,
x_obj_t p_args 
)
static

x-lang (make-iter step-fn value): build an iterator – a boxed generator. Steps are PURE: an x-lang step-fn is (step state) -> (value . next-state) or () when exhausted; iter-next owns the box write-back – value going nil marks exhaustion (iter-empty?).