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

Custom constants of lists #1211

Closed
nrryuya opened this issue Jan 22, 2019 · 6 comments

Comments

@nrryuya
Copy link
Contributor

@nrryuya nrryuya commented Jan 22, 2019

Version Information

  • vyper Version: 0.1.0 beta 7

What's your issue about?

I'm not sure whether this is designed or a bug but Vyper doesn't support custom constants of lists.
It'd be better to support it if there is no concern?

# Invalid value for constant type, expected bytes[8] got bytes[8] instead
BYTE_LIST: constant(bytes[8]) = 'abcdefgh'

# 'ListType' object has no attribute 'is_literal'
BYTE32_LIST: constant(bytes32[2]) = [0x0000000000000000000000000000000000000000000000000000000000000000,
                                    0x0000000000000000000000000000000000000000000000000000000000000000]

# 'ListType' object has no attribute 'is_literal'
ZERO_LIST: constant(int128[8]) = [0, 0, 0, 0, 0, 0, 0, 0]

# 'ListType' object has no attribute 'is_literal'
ZERO_LIST: constant(uint256[8]) = [convert(0, uint256), convert(0, uint256), convert(0, uint256), convert(0, uint256), convert(0, uint256), convert(0, uint256), convert(0, uint256), convert(0, uint256)]

Cute Animal Picture

image

@jacqueswww

This comment has been minimized.

Copy link
Collaborator

@jacqueswww jacqueswww commented Feb 1, 2019

Hmmm I don't think we ever considered lists to be constants, not that could not be - just that it never was considered.
So now it begs the question - should we or not ?

@fubuloubu

This comment has been minimized.

Copy link
Member

@fubuloubu fubuloubu commented Feb 1, 2019

Looks like the use case here is for an "empty list" or a list full of empty entries. @nrryuya are you looking for a way to assert that a list has not been set yet?

@jacqueswww

This comment has been minimized.

Copy link
Collaborator

@jacqueswww jacqueswww commented Feb 1, 2019

Well it's not the only use case, I can easily imagine something like a making sure you have set of values like:

VALID_STATES:  constant(int128) = [1, 33, 44, 55 .. ]

Or another form of storing owners?

OWNERS: constant(address[3]) = [....]

Just thinking out loud - on what it could be used for.

@fubuloubu

This comment has been minimized.

Copy link
Member

@fubuloubu fubuloubu commented Feb 1, 2019

Case 1 would actually be better served by enums (which we don't have... yet). Basically something like:

enum(int128) State:
    A = 1
    B = 33
    C = 44
    D = 55

Case 2 is typically done dynamically through a constructor. Probably not the best idea to hardcode a collection of addresses, since they might change on every deployment and you would have to update the code, but I can see a limited rationale of how that could be useful for something like templated programs (but basically, just use constructor args)

@nrryuya

This comment has been minimized.

Copy link
Contributor Author

@nrryuya nrryuya commented Feb 2, 2019

Looks like the use case here is for an "empty list" or a list full of empty entries. @nrryuya are you looking for a way to assert that a list has not been set yet?

Yep. I found this issue when I wanted to return a list full of 0 in my BigInt.vy which represents a zero in a big number.

I'm also not confident about the use case of this feature...
As an example, we can use constants of a list of primes in programs like RSA Accumulator.

PRIMES: constant(int128[100]) = [2, 3, 5, ...]
@fubuloubu

This comment has been minimized.

Copy link
Member

@fubuloubu fubuloubu commented Feb 2, 2019

List of primes might be a good one!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
3 participants
You can’t perform that action at this time.