DINAC/STDLIB

From Esolang
Jump to navigation Jump to search

DINAC STDLIB is a library of functions you can use in your DINAC code. They are grouped together for ease of access, and from there the individual functions are arranged alphabetically. Overloads are listed in no specific order. Any functions required by other functions are listed.

Arithmetic

 DEF/00 add a:00 b:00
    WHILE b
        a . a+
        b . b-
    GIVE a
# Requires add, and, less, mul
DEF/00 factorial a:00
    IF less(a,2)
        GIVE 01
    ELSE
        GIVE mul(n,factorial(n-))
# Requires less, sub
DEF/00 floordiv a:00 b:00
    SET res:00
    WHILE ~less(a,b)
        a . sub(a,b)
        res . res+
    GIVE res
# Requires add
DEF/00 mul a:00 b:00
    SET res:00
    WHILE b
        res . add(res,a)
        b . b-
    GIVE res
# Requires add, mul
DEF/00 pow a:00 b:00
    SET res:01
    WHILE b
        res . mul(res,a)
        b . b-
    GIVE res
DEF/00 sub a:00 b:00
    WHILE b
        a . a-
        b . b-
    GIVE a

Boolean

DEF/00 and a:00 b:00
    IF a
        GIVE ~~b
    ELSE
        GIVE 00
DEF/00 or a:00 b:00
    IF a
        GIVE 01
    ELSE
        GIVE ~~b
# Requires and, or
DEF/00 xor a:00 b:00
    GIVE and(~and(a,b),or(a,b))

Comparison

# Requires and
DEF/00 greater a:00 b:00
    WHILE and(a,b)
        a . a-
        b . b-
    GIVE ~~a
# Requires and
DEF/00 greq a:00 b:00
    WHILE and(a,b)
        a . a-
        b . b-
    GIVE ~b
# Requires and
DEF/00 less a:00 b:00
    WHILE and(a,b)
        a . a-
        b . b-
    GIVE ~~b
# Requires and
DEF/00 lseq a:00 b:00
    WHILE and(a,b)
        a . a-
        b . b-
    GIVE ~a

Conversion

DEF/00 ascharToWubyte a:\0
    SET w:00
    WHILE a
        w . w+
        a . a-
    GIVE w
DEF/00 wubyteToAschar w:00
    SET a:\0
    WHILE w
        a . a+
        w . w-
    GIVE a

Other

DEF/00 ternary cond:00 a:00 b:00
    IF cond
        GIVE a
    ELSE
        GIVE b
DEF/\0 ternary cond:00 a:\0 b:\0
    IF cond
        GIVE a
    ELSE
        GIVE b