if version\0 < 1:
raise = PRIMOP{'Fraise'}
print = PRIMOP{'Fprint'}
pprint = PRIMOP{'Fpprint'}
pformat = PRIMOP{'Fformat'}
quote = PRIMOP{'Fquote'}
iter = PRIMOP{'Fiter'}
kiter = PRIMOP{'Fkiter'}
spawn = PRIMOP{'Fspawn'}
import_fast = PRIMOP{'Fimport'}
import = PrimaImport
ask_root = PrimaConsoleQuestion
sleep = PrimaSleep
resume = PrimaResume
str = PRIMOP{'Fstr'}
format_time = PRIMOP{'Fformat_time'}
append = PRIMOP{'Fappend'}
truncate = PRIMOP{'Ftrunc'}
length = <l: l.__length__>
span = <a, b: Range(start=a, stop=b)>
sjoin = PRIMOP{'Fsjoin2'}
slen = PRIMOP{'Fslen'}
sindent = PRIMOP{'Fsindent'}
joinlines = sjoin{sep='\n'}
reversed = PRIMOP{'Freversed'}
read_file = PRIMOP{'Fread_file'}
file_lines = PRIMOP{'Ffile_lines'}
json = PRIMOP{'Fjson'}
oid = PRIMOP{'Foid'}
vdb_add = PRIMOP{'Fvdb_add'}
vdb_find = PRIMOP{'Fvdb_find'}
{|
| Wait until func() returns a known value.
|
| The DSL compiler uses this for "x!"
|
| I.e., "foo.x!" desugars to
| wait_until_known(<foo.x>)
|}
def wait_until_known(func):
for val in func:
if val?:
return val
{|
| Return the first len items of list l.
| Returns l if length(l) <= len
|}
def trunc(l, len):
if length(l) <= len:
return l
ll = []
for i:v in l:
if i >= len:
return ll
append(ll, v)
return ll
def list(itr):
l = []
for v in itr:
append(l, v)
return l
def set(itr):
s = {}
for v in itr:
append(s, v)
return s
def tuple(itr):
return PRIMOP('Ftuple', list(itr))
{|
| This adds a new property to an existing type.
|
| This behaves the same as if the equivalent field
| line was added to the original definition of type.
|
| Returns the resulting Property Object.
|
| (This isn't really needed any more since you can
| amend types with a normal type declaration, but
| useful I guess for eventual meta programming.)
|}
def add_property(type, mode, name, default):
return PRIMOP('Ftype_field2', type, name, mode, default)
TODO
type vdb:
var nextid = 0
val items
val key2ob, ob2key
def new_vdb():
return vdb(items=[:], key2ob=[:], ob2key=[:])
def vadd(v, key, val):
v.items[key] = val
if not (skey = v.ob2key[key])?:
skey = "i{v.nextid}"
v.nextid = v.nextid+1
v.key2ob[skey] = key
v.ob2key[key] = skey
vdb_add(oid(v), skey, val)
def vfind(v, val, num):
num = num\10
return [v.key2ob[skey] for skey in vdb_find(oid(v), val, num)]
import telegram
version = 1