Files
clyx/lib.clx
T

53 lines
2.2 KiB
Plaintext
Raw Normal View History

2026-07-02 23:26:38 +03:00
# Clyx standard library (in addition to [ :: readf src ])
# Created by Luxferre in 2026, released into the public domain
:: if [ next next swap rot cond ]
:: while [ next [] swap loop ]
:: rot [ [ swap ] dip swap ]
:: over [ [ dup ] dip swap ]
:: qpush [ swap [] cons swap + ]
:: nip [ [ drop ] dip ]
:: div [ divmod drop ]
:: mod [ divmod nip ]
:: tuck [ swap over ]
:: not [ 0= ]
:: and [ if [ not not ] [ drop 0 ] ]
:: or [ if [ drop 1 ] [ not not ] ]
:: cr [ 10 emit ]
:: space [ 32 emit ]
:: puts [ uncons while [ emit uncons ] drop ]
:: sqrt [ 0.5 ^ ]
:: tan [ dup sin swap cos / ]
:: cotan [ dup cos swap sin / ]
:: neg [ 0 swap - ]
:: 1/ [ 1 swap / ]
:: shr [ neg shl ]
2026-07-04 16:59:38 +03:00
:: readln [ 0 "r" fopen read q2s ]
2026-07-02 23:26:38 +03:00
:: writef [ "w" fopen dup rot write swap close ]
:: nlstn [ "0.0.0.0" swap nopen ]
:: = [ - 0= ]
:: != [ = not ]
:: < [ - 0< ]
:: >= [ < not ]
:: > [ swap < ]
:: <= [ > not ]
:: isnum [ type 0= ]
:: isstr [ type 1 = ]
2026-07-04 16:56:08 +03:00
:: isq [ type 2 = ]
2026-07-02 23:26:38 +03:00
:: vlen [ type 2 = if [ qlen ] [ slen ] ]
2026-07-04 16:59:38 +03:00
:: s2q [ type 2 = if [] [ dup slen 0 = if [ drop [] ] [ uncons drop swap cons ] ] ]
:: asc [ s2q 0 qget ]
2026-07-02 23:26:38 +03:00
:: lcat [ [ rev ] dip swap uncons while [ [ swap ] dip swap cons swap uncons ] drop ]
:: streq [ dup vlen [ swap dup vlen ] dip = if [ 1 while [ uncons if [ [ swap uncons drop ] dip = if [ dup qlen 0 = if [ drop drop 1 0 ] [ swap 1 ] ] [ drop drop 0 0 ] ] [ drop drop 1 0 ] ] ] [ drop drop 0 ] ]
2026-07-04 16:59:38 +03:00
:: lower [ "" swap uncons while [ dup 65 >= [ dup 90 <= ] dip and if [ 32 + ] [] [ swap ] dip chr s+ swap uncons ] drop q2s ]
:: upper [ "" swap uncons while [ dup 97 >= [ dup 122 <= ] dip and if [ 32 - ] [] [ swap ] dip chr s+ swap uncons ] drop q2s ]
2026-07-02 23:26:38 +03:00
:: bitnot [ dup nand ]
:: bitand [ nand bitnot ]
:: bitor [ bitnot swap bitnot nand ]
:: bitxor [ over over bitnot bitand [ swap bitnot bitand ] dip bitor ]
:: rev [ [] swap uncons while [ [ swap ] dip swap cons swap uncons ] drop ]
2026-07-04 16:59:38 +03:00
:: s+ [ s2q [ s2q ] dip lcat ]
2026-07-05 17:40:48 +03:00
:: range [ [] [ over over < ] dip swap while [ [ over ] dip qpush [ swap 1 + swap ] dip [ over over < ] dip swap ] nip nip ]
:: qfor [ dup qlen while [ uncons drop [ [] cons cons ] dip swap dup 0 qget dip uncons drop swap 0 qget dup qlen ] drop drop ]
:: for [ next next [ i ] dip swap qfor ]