Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ellipsis range notation #702

Closed
robertwb opened this issue Sep 20, 2007 · 13 comments
Closed

Ellipsis range notation #702

robertwb opened this issue Sep 20, 2007 · 13 comments

Comments

@robertwb
Copy link
Contributor

There have been proposal to add syntax to SAGE similar to magma/mathmatica/etc 1..n for ranges. See the mailing list for much discusssion.

Component: user interface

Issue created by migration from https://trac.sagemath.org/ticket/702

@robertwb
Copy link
Contributor Author

Attachment: ellipsis_iterator.diff.gz

Attachment: ellipsis_iterator2.diff.gz

@robertwb
Copy link
Contributor Author

comment:1

The above patches are one such proposal. NOTE: it has not been decided whether or not to include this feature. However, I like it.

sage: [1..10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
sage: n = 5
sage: [1..n]
[1, 2, 3, 4, 5]
sage: [0,2,..,10]
[0, 2, 4, 6, 8, 10]
sage: [0,2,..,10,20..30]
[0, 2, 4, 6, 8, 10, 20, 22, 24, 26, 28, 30]

sage: (0,2,..,10)       
<generator object at 0xc57cd78>
sage: A = (5,7,..)
sage: [A.next() for _ in range(20)]
[5, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25]

And a non-trivial example

sage: L = [1..5]
sage: [L[4], .., next_prime(10), 3, 2, 1]
[5, 6, 7, 8, 9, 10, 11, 3, 2, 1]

@robertwb robertwb assigned robertwb and unassigned williamstein Sep 20, 2007
@robertwb
Copy link
Contributor Author

Attachment: ellipsis_iterator3.diff.gz

@robertwb
Copy link
Contributor Author

comment:2

Fixed:

sage: A = (5,7,..)
sage: [A.next() for _ in range(10)]
[5, 7, 9, 11, 13, 15, 17, 19, 21, 23]

@robertwb
Copy link
Contributor Author

Attachment: ellipsis_iterator4.diff.gz

@robertwb
Copy link
Contributor Author

comment:3

Fixed an issue with double quotes, and now this works as well

sage: list(1..5)
[1, 2, 3, 4, 5]

@williamstein
Copy link
Contributor

comment:4

Attachment: ellipsis_iterator1-4.hg.gz

Applied. (And I fixed a few bugs.)

@robertwb
Copy link
Contributor Author

comment:5

[1,2,..,-10] should return the empty list.

@robertwb robertwb reopened this Sep 21, 2007
@robertwb robertwb modified the milestones: sage-2.8.5, sage-2.8.5.1 Sep 21, 2007
@robertwb
Copy link
Contributor Author

Attachment: ellipsis-empty-range.hg.gz

@robertwb
Copy link
Contributor Author

comment:6

Fixed.

sage: [1,2..-1]
[]
sage: [10..1]
[]
sage: [1..10]
[1, 2, 3, 4, 5, 6, 7, 8, 9, 10]
sage: [1..10,step=2] # no extra preparsing needed
[1, 3, 5, 7, 9]

@jasongrout
Copy link
Member

comment:7

Why doesn't [10..1] return [10,9,8,7,6,5,4,3,2,1]?

@williamstein
Copy link
Contributor

comment:8

I don't think this should be an error:

sage: [1..5, step=0.5]
<type 'exceptions.TypeError'>: unable to coerce element to an integer

i.e., the universe stuff should take into account the step if given.

@williamstein
Copy link
Contributor

comment:9

Fixed now by Robert...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants