File: PYlist_cats.py

package info (click to toggle)
ats2-lang 0.4.0-1
  • links: PTS, VCS
  • area: main
  • in suites: bullseye
  • size: 40,064 kB
  • sloc: ansic: 389,637; makefile: 7,123; lisp: 812; sh: 657; php: 573; python: 387; perl: 365
file content (100 lines) | stat: -rw-r--r-- 2,467 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
######
#
# HX-2014-08:
# for Python code translated from ATS
#
######

######
# beg of [PYlist_cats.py]
######

######
import functools
######

############################################

def ats2pypre_PYlist_nil(): return []
def ats2pypre_PYlist_sing(x): return [x]
def ats2pypre_PYlist_pair(x1, x2): return [x1, x2]

############################################

def ats2pypre_PYlist_cons(x0, xs): return xs.insert(0, x0)

############################################

def ats2pypre_PYlist_make_elt(n, x):
  res = []
  while (n > 0): n = n - 1; res.append(x)
  return res

############################################

def ats2pypre_PYlist_is_nil(xs): return not(xs)
def ats2pypre_PYlist_is_cons(xs): return True if xs else False
def ats2pypre_PYlist_isnot_nil(xs): return True if xs else False

############################################

def ats2pypre_PYlist_length(xs): return xs.__len__()

############################################

def ats2pypre_PYlist_get_at(xs, ind): return xs[ind]
def ats2pypre_PYlist_set_at(xs, ind, x): xs[ind] = x; return

############################################

def ats2pypre_PYlist_copy(xs):
  res = []
  for x in iter(xs): res.append(x)
  return res

############################################

def ats2pypre_PYlist_append(xs, x): xs.append(x); return
def ats2pypre_PYlist_extend(xs1, xs2): xs1.extend(xs2); return

############################################

def ats2pypre_PYlist_pop_0(xs): return xs.pop()
def ats2pypre_PYlist_pop_1(xs, i): return xs.pop(i)

############################################

def ats2pypre_PYlist_insert(xs, i, x): xs.insert(i, x); return

############################################

def ats2pypre_PYlist_map(xs, f): return list(map(f, xs))
def ats2pypre_PYlist_filter(xs, f): return list(filter(f, xs))

############################################

def ats2pypre_PYlist_string_join(xs): return ''.join(xs)

############################################

def \
ats2pypre_PYlist_reduce(xs, ini, f):
  res = ini
  for x in iter(xs): res = f(res, x)
  return res

############################################

def ats2pypre_PYlist2list_rev(xs):
  res = ats2pypre_list_nil()
  for x in iter(xs): res = ats2pypre_list_cons(x, res)
  return res

############################################
#
def ats2pypre_PYlist_sort_2(xs, cmp):
  xs.sort(key=functools.cmp_to_key(ats2pypre_cloref2fun2(cmp))); return
#
############################################

###### end of [PYlist_cats.py] ######