Boo

Element syntax.

Details

  • Type: New Feature New Feature
  • Status: Open Open
  • Priority: Major Major
  • Resolution: Unresolved
  • Affects Version/s: 0.6, 0.9
  • Fix Version/s: 0.9.5
  • Component/s: Compiler
  • Labels:
    None
  • Number of attachments :
    0

Description

(This is a feature request based on input from Doug and Sorin from #boo. If you're not in #boo, you're just not in!)

Element wise operator syntax to allow for more compact generators (A) and for element-wise operations on two or more iterable items (B)

EXAMPLE A:

list = [1, 2, 3, 4, 5]
filtered = array(int, list[it > 3])
print filtered # " 4, 5 "

That is in comparison to the current generator syntax:

list = [1, 2, 3, 4, 5]
filtered = array(int, e for e in list if e > 3)
print filtered # "4, 5"

EXAMPLE B:
foo = [1, 2, 3, 4, 5]
bar = [1, 2, 3, 4, 5]
result = array(int, foo[it] * bar[it])
print result #1, 4, 8, 16, 25

Not sure I want to write the equivilent of what you have to do in Boo now.

Issue Links

Activity

Hide
Cameron Kenneth Knight added a comment -

items = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9)

Brackets are used to retrieve either a single child
items[5] == 5
or a subset of children
items[2:4] == .(2, 3, 4)
This can be extended to IEnumerables by using the form items[<bool>],
items[it < 5] == (0, 1, 2, 3, 4)
Braces (closures) can be used for some elementwise operators, e.g.
items.{it + 5} == (5, 6, 7, 8, 9, 10, 11, 12, 13, 14)
-> can be used to retrieve a member from the elements, e.g.
items->ToString() == ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9')

items == items[true] == items.{it}

Show
Cameron Kenneth Knight added a comment - items = (0, 1, 2, 3, 4, 5, 6, 7, 8, 9) Brackets are used to retrieve either a single child items[5] == 5 or a subset of children items[2:4] == .(2, 3, 4) This can be extended to IEnumerables by using the form items[<bool>], items[it < 5] == (0, 1, 2, 3, 4) Braces (closures) can be used for some elementwise operators, e.g. items.{it + 5} == (5, 6, 7, 8, 9, 10, 11, 12, 13, 14) -> can be used to retrieve a member from the elements, e.g. items->ToString() == ('0', '1', '2', '3', '4', '5', '6', '7', '8', '9') items == items[true] == items.{it}
Hide
Cameron Kenneth Knight added a comment -

Also,
items.{it.Member} == items->Member

Show
Cameron Kenneth Knight added a comment - Also, items.{it.Member} == items->Member
Hide
Arron Washington added a comment -

Basically, enumerable[CONDITION].{TRANSFORMATION ON ELEMENTS PASSING CONDITION}

Show
Arron Washington added a comment - Basically, enumerable[CONDITION].{TRANSFORMATION ON ELEMENTS PASSING CONDITION}
Hide
Doug H added a comment -

and implicit it parameter
{it*2} == {it | return it*2}

Show
Doug H added a comment - and implicit it parameter {it*2} == {it | return it*2}

People

Vote (0)
Watch (0)

Dates

  • Created:
    Updated: