Closed onbjerg closed 5 years ago
There might be a case for using something other than brackets, e.g. angle brackets, to denote what value to return.
I would agree with this; perhaps we could use <return>
instead? At first read, without context, I thought [return]
meant this was optional, due to how JSDoc and etc. handle optional parameters.
Sure, I can update the PR to use angled brackets if you decide on that :)
@sohkai Added the requested test cases and switched [ and ] for < and >
@onbjerg Just wanted to check your thoughts on https://github.com/aragon/radspec/pull/79#discussion_r334993442.
I'll merge this and release soon :).
@onbjerg I've just added a few commits:
()
to have the same interface as call expressions
This PR closes #1 by adding support for multiple return values for calls.
It adds two new tokens (
LEFT_BRACKET
andRIGHT_BRACKET
) and no new AST nodes. It is fully backwards compatible with the single return type syntax.Example
Imagine that this string describes a function that removes an entry from a registry. The string calls a function,
getEntry(uint256): (string title, address author)
, that returns information about a specific entry in a registry:Output:
Design Rationale
The syntax for describing a call with multiple return values is a type list (e.g.
(address, string)
) where one of the types is marked as the type to use for further evaluation by surrounding it with brackets.I initially wanted to implement a syntax that is more "JavaScript"-y by mimicing the array access syntax (
arr[n]
for then
th value in an array), but it would lead to extra parenthesis being needed:I realised I could make the syntax more concise while making the implementation easier by implementing it as the final result in this PR.
Final note
There might be a case for using something other than brackets, e.g. angle brackets, to denote what value to return. For example, using brackets as this PR does might lead to confusion with array syntax in some languages.