History | Log In     View a printable version of the current page.  
Issue Details (XML | Word | Printable)

Key: BOO-466
Type: New Feature New Feature
Status: Open Open
Priority: Major Major
Assignee: Unassigned
Reporter: Arron Washington
Votes: 0
Watchers: 0
Operations

If you were logged in you would be able to see more operations.
Boo

Element syntax.

Created: 31/Aug/05 03:16 PM   Updated: 20/May/08 09:09 AM
Component/s: Compiler
Affects Version/s: 0.6
Fix Version/s: 0.8.3

Time Tracking:
Not Specified

Issue Links:
dependent
 


 Description  « Hide
(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.



 All   Comments   Work Log   Change History      Sort Order: Ascending order - Click to sort in descending order

Cameron Kenneth Knight - 28/Oct/05 12:03 PM
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}


Cameron Kenneth Knight - 28/Oct/05 12:13 PM
Also,
items.{it.Member} == items->Member

Arron Washington - 28/Oct/05 12:20 PM
Basically, enumerable[CONDITION].{TRANSFORMATION ON ELEMENTS PASSING CONDITION}

Doug H - 18/Nov/05 08:16 AM
and implicit it parameter
{it*2} == {it | return it*2}