Skip to content

Commit

Permalink
added foldl
Browse files Browse the repository at this point in the history
  • Loading branch information
DennisMitchell committed Apr 23, 2018
1 parent ee6751b commit bee6aa3
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 8 deletions.
21 changes: 14 additions & 7 deletions jelly/interpreter.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
code_page = '''¡¢£¤¥¦©¬®µ½¿€ÆÇÐÑ×ØŒÞßæçðıȷñ÷øœþ !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~¶'''
code_page += '''°¹²³⁴⁵⁶⁷⁸⁹⁺⁻⁼⁽⁾ƁƇƊƑƓƘⱮƝƤƬƲȤɓƈɗƒɠɦƙɱɲƥʠɼʂƭʋȥẠḄḌẸḤỊḲḶṂṆỌṚṢṬỤṾẈỴẒȦḂĊḊĖḞĠḢİĿṀṄȮṖṘṠṪẆẊẎŻạḅḍẹḥịḳḷṃṇọṛṣṭụṿẉỵẓȧḃċḋėḟġḣŀṁṅȯṗṙṡṫẇẋẏż«»‘’“”'''

# Unused symbols for single-byte atoms/quicks: ()kquƁƇƘⱮƬȤƒɦɱɲƥʠɼʂȥẈẒŻḥḳṇụṿẉỵẓḋėġṅẏ
# Unused symbols for single-byte atoms/quicks: ()kquƁƇƘⱮƬȤɦɱɲƥʠɼʂȥẈẒŻḥḳṇụṿẉỵẓḋėġṅẏ

str_digit = '0123456789'
str_lower = 'abcdefghijklmnopqrstuvwxyz'
Expand Down Expand Up @@ -228,6 +228,9 @@ def flatten(argument):
flat.append(argument)
return flat

def foldl(*args):
return reduce(*args, arity = 2)

def from_base(digits, base):
integer = 0
for digit in digits:
Expand Down Expand Up @@ -821,17 +824,17 @@ def random_int(pool):
return random.choice(pool)
return random.randint(1, pool)

def reduce(links, outmost_links, index):
ret = [attrdict(arity = 1)]
def reduce(links, outmost_links, index, arity = 1):
ret = [attrdict(arity = arity)]
if len(links) == 1:
ret[0].call = lambda z: reduce_simple(z, links[0])
ret[0].call = lambda x, *y: reduce_simple(x, links[0], *y)
else:
ret[0].call = lambda z: [reduce_simple(t, links[0]) for t in split_fixed(iterable(z), links[1].call())]
ret[0].call = lambda x, *y: [reduce_simple(t, links[0], *y) for t in split_fixed(iterable(x), links[1].call())]
return ret

def reduce_simple(array, link):
def reduce_simple(array, link, *init):
array = iterable(array)
return functools.reduce(lambda x, y: dyadic_link(link, (x, y)), array)
return functools.reduce(lambda x, y: dyadic_link(link, (x, y)), array, *init)

def reduce_cumulative(links, outmost_links, index):
ret = [attrdict(arity = 1)]
Expand Down Expand Up @@ -2583,6 +2586,10 @@ def zip_ragged(array):
call = lambda x, y = None: int(x == variadic_link(links[0], (x, y)))
)]
),
'ƒ': attrdict(
condition = lambda links: links and links[0].arity,
quicklink = foldl
),
'Ɲ': attrdict(
condition = lambda links: links and not leading_nilad(links),
quicklink = lambda links, outmost_links, index: [attrdict(
Expand Down
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@

setup(
name = 'jellylanguage',
version = '0.1.5',
version = '0.1.6',
packages = [
'jelly'
],
Expand Down

0 comments on commit bee6aa3

Please sign in to comment.