本文整理汇总了Python中pycket.values.from_list函数的典型用法代码示例。如果您正苦于以下问题:Python from_list函数的具体用法?Python from_list怎么用?Python from_list使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了from_list函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: from_raw_key
def from_raw_key(w_key, total_field_cnt=0):
init_field_cnt = -1
auto_field_cnt = 0
auto_v = values.w_false
super_key = None
mutables = []
if isinstance(w_key, values.W_Symbol):
name = w_key.utf8value
init_field_cnt = total_field_cnt
else:
key = values.from_list(w_key)
w_name = key[0]
assert isinstance(w_name, values.W_Symbol)
name = w_name.utf8value
idx = 1
w_init_field_cnt = key[idx]
if isinstance(w_init_field_cnt, values.W_Fixnum):
init_field_cnt = w_init_field_cnt.value
idx += 1
if len(key) > idx:
w_auto = key[idx]
if isinstance(w_auto, values.W_Cons):
auto = values.from_list(w_auto)
w_auto_field_cnt = auto[0]
assert isinstance(w_auto_field_cnt, values.W_Fixnum)
auto_field_cnt = w_auto_field_cnt.value
auto_v = auto[1]
idx += 1
if len(key) > idx:
v = key[idx]
if isinstance(v, values_vector.W_Vector):
for i in range(v.len):
mutable = v.ref(i)
assert isinstance(mutable, values.W_Fixnum)
mutables.append(mutable.value)
idx += 1
if len(key) > idx:
w_super_key = values.to_list(key[idx:])
super_key = W_PrefabKey.from_raw_key(w_super_key)
if init_field_cnt == -1:
init_field_cnt = total_field_cnt
s_key = super_key
while s_key:
super_name, super_init_field_cnt, super_auto_field_cnt,\
super_auto_v, super_mutables, s_key = s_key.make_key_tuple()
init_field_cnt -= super_init_field_cnt
return W_PrefabKey.make(name, init_field_cnt, auto_field_cnt, auto_v,
mutables, super_key)
示例2: is_prefab_key
def is_prefab_key(v):
if isinstance(v, values.W_Symbol):
return values.w_true
elif isinstance(v, values.W_Cons):
key = values.from_list(v)
if not isinstance(key[0], values.W_Symbol):
return values.w_false
idx = 1
if isinstance(key[idx], values.W_Fixnum):
idx += 1
else:
if not isinstance(key[idx], values.W_Cons):
return values.w_false
idx += 1
if len(key) > idx:
if not isinstance(key[idx], values.W_Cons):
return values.w_false
idx += 1
if len(key) > idx:
if not isinstance(key[idx], values_vector.W_Vector):
return values.w_false
idx += 1
if len(key) > idx:
return W_PrefabKey.is_prefab_key(key[idx])
return values.w_true
else:
return values.w_false
示例3: equal_hash_args
def equal_hash_args(w_prop):
if isinstance(w_prop, values_vector.W_Vector):
return w_prop.ref(0), w_prop.ref(1), w_prop.ref(2)
if isinstance(w_prop, values.W_List):
lst = values.from_list(w_prop)
assert len(lst) >= 3
return lst[0], lst[1], lst[2]
raise SchemeException("invalid prop:equal+hash arg " + w_prop.tostring())
示例4: append
def append(lists):
if not lists:
return values.w_null
lists, acc = lists[:-1], lists[-1]
while lists:
vals = values.from_list(lists.pop())
acc = values.to_improper(vals, acc)
return acc
示例5: from_assocs
def from_assocs(assocs, fname):
lsts = values.from_list(assocs)
keys = [None] * len(lsts)
vals = [None] * len(lsts)
for i, lst in enumerate(lsts):
if not isinstance(lst, values.W_Cons):
raise SchemeException("%s: expected list of pairs" % fname)
keys[i], vals[i] = lst.car(), lst.cdr()
return keys, vals
示例6: is_struct_info
def is_struct_info(v):
if isinstance(v, values.W_Cons):
struct_info = values.from_list(v)
if len(struct_info) == 6:
if not isinstance(struct_info[0], values_struct.W_StructType) and\
struct_info[0] is not values.w_false:
return False
if not isinstance(struct_info[1], values_struct.W_StructConstructor) and\
struct_info[1] is not values.w_false:
return False
if not isinstance(struct_info[2], values_struct.W_StructPredicate) and\
struct_info[2] is not values.w_false:
return False
accessors = struct_info[3]
if isinstance(accessors, values.W_Cons):
for accessor in values.from_list(accessors):
if not isinstance(accessor, values_struct.W_StructFieldAccessor):
if accessor is not values.w_false and\
accessor is values.from_list(accessors)[-1]:
return False
else:
return False
mutators = struct_info[4]
if isinstance(mutators, values.W_Cons):
for mutator in values.from_list(mutators):
if not isinstance(mutator, values_struct.W_StructFieldAccessor):
if mutator is not values.w_false and\
mutator is values.from_list(mutators)[-1]:
return False
else:
return False
if not isinstance(struct_info[5], values_struct.W_StructType) and\
not isinstance(struct_info[5], values.W_Bool):
return False
return True
return False
elif isinstance(v, values.W_Prim):
if v.name == "make-struct-info":
return True
# TODO: it can be also:
# 1. a structure with the prop:struct-info property
# 2. a structure type derived from struct:struct-info or
# with prop:struct-info and wrapped with make-set!-transformer
return False
示例7: make_immutable_hasheq
def make_immutable_hasheq(assocs):
pairs = values.from_list(assocs)
keys = [None] * len(pairs)
vals = [None] * len(pairs)
for i, pair in enumerate(pairs):
if not isinstance(pair, values.W_Cons):
raise SchemeException("make-immutable-hasheq: expected list of pairs")
keys[i] = pair.car()
vals[i] = pair.cdr()
return make_simple_table(W_EqHashTable, keys, vals, immutable=True)
示例8: list_tail
def list_tail(lst, pos):
start_pos = pos.value
if start_pos == 0:
return lst
else:
if isinstance(lst, values.W_Cons):
assert start_pos > 0
return values.to_list(values.from_list(lst)[start_pos:])
else:
return values.w_null
示例9: make_hasheqv
def make_hasheqv(pairs):
lsts = values.from_list(pairs)
keys = []
vals = []
for lst in lsts:
if not isinstance(lst, values.W_Cons):
raise SchemeException("make-hash: expected list of pairs")
keys.append(lst.car())
vals.append(lst.cdr())
return make_simple_table(W_EqvHashTable, keys, vals)
示例10: make_immutable_hash
def make_immutable_hash(assocs):
# FIXME: Not annotated as immutable
lsts = values.from_list(assocs)
keys = []
vals = []
for lst in lsts:
if not isinstance(lst, values.W_Cons):
raise SchemeException("make-hash: expected list of pairs")
keys.append(lst.car())
vals.append(lst.cdr())
return W_EqualHashTable(keys, vals)
示例11: list_to_bytes
def list_to_bytes(w_list):
l = values.from_list(w_list)
ll = [' '] * len(l)
for (i,x) in enumerate(l):
if not isinstance(x, values.W_Fixnum):
raise SchemeException("list->bytes: expected fixnum, got %s" % x)
if x.value < 0 or x.value >= 256:
raise SchemeException(
"list->bytes: expected number between 0 and 255, got %s" % x)
ll[i] = chr(x.value)
return values.W_MutableBytes(ll)
示例12: do_is_procedure_arity
def do_is_procedure_arity(n):
if isinstance(n, values.W_Fixnum):
if n.value >= 0:
return values.w_true
elif isinstance(n, values_struct.W_RootStruct) and\
n.struct_type().name == "arity-at-least":
return values.w_true
elif isinstance(n, values.W_List):
for item in values.from_list(n):
if not (isinstance(item, values.W_Fixnum) or\
(isinstance(item, values_struct.W_RootStruct) and\
item.struct_type().name == "arity-at-least")):
return values.w_false
return values.w_true
return values.w_false
示例13: apply
def apply(args, env, cont):
if not args:
raise SchemeException("apply expected at least one argument, got 0")
fn = args[0]
if not fn.iscallable():
raise SchemeException("apply expected a procedure, got something else")
lst = args[-1]
if not listp_loop(lst):
raise SchemeException(
"apply expected a list as the last argument, got something else")
args_len = len(args)-1
assert args_len >= 0
others = args[1:args_len]
new_args = others + values.from_list(lst)
return fn.call(new_args, env, cont)
示例14: is_module_path
def is_module_path(v):
if isinstance(v, values.W_Symbol):
# FIXME: not always right
return True
if isinstance(v, values.W_Path):
return True
if isinstance(v, values_string.W_String):
return True
if isinstance(v, values.W_List):
vs = values.from_list(v)
for p in vs:
if not is_module_path(p):
return False
return True
# FIXME
return False
示例15: apply
def apply(args, env, cont, extra_call_info):
if not args:
raise SchemeException("apply expected at least one argument, got 0")
fn = args[0]
if not fn.iscallable():
raise SchemeException("apply expected a procedure, got something else")
lst = args[-1]
try:
rest = values.from_list(lst)
except SchemeException:
raise SchemeException(
"apply expected a list as the last argument, got something else")
args_len = len(args)-1
assert args_len >= 0
others = args[1:args_len]
new_args = others + rest
return fn.call_with_extra_info(new_args, env, cont, extra_call_info)