-
Notifications
You must be signed in to change notification settings - Fork 10
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鈥檒l occasionally send you account related emails.
Already on GitHub? Sign in to your account
Map / Set syntax 馃毑 #27
Comments
I did think of map and set being keywords, but I don't want A lot of the things that are possible in records are also possible in maps and sets, and they share a lot of syntax. So I want them to feel conceptually similar |
I agree, they should feel first-class. You wouldn't really need the let record = { a: 1, b: 2 }
let map = { 'a' => 1, 'b' => 2 } For lists, arrays, and sets: let list = [ 1, 2, 3 ]
let array = +[ 1, 2, 3 ]
let set = -[ 1, 2, 3 ] |
It might be interesting for lists to use parentheses. let list = ( 1, 2, 3 )
let array = [ 1, 2, 3 ]
let set = [[ 1, 2, 3 ]] |
This won't work because a list of a single list is a valid thing people may want to do and relying on their being a whitespace is hard to notice. let set = [[ 1, 2, 3 ]] let list = ( 1, 2, 3 ) There's already a lot of use of parenthesis in expressions. I don't want there to be many places where you have parenthesis next to each other: let a = fn((a && (fn()))) Also, you have to deal with a lot of syntax ambiguities when using the let record = { a: 1, b: 2 }
let map = { 'a' => 1, 'b' => 2 } How do you create an empty map? I don't want the answer to be I also don't want to have huge lookaheads in the parser to figure out what I can see an argument for let map = {=
'keyA' = 1,
'keyB' = 2,
=}
let record = {:
keyA: 1,
keyB: 2,
:}
let set = {
1,
2,
} |
How about getting rid of the regular record syntax and requiring that it be annotated with a type? let record = Person {
name: "John Doe",
age: 42
} This would free up Also, Python uses |
There could also be a sigil ( let record = Person {
name: _ {
first: "Jane",
last: "Doe"
},
age: 42
} |
Would empty map be I think How about the following? let map = { 'a' = 1, 'b' = 2 }
let empty = <Map>{}
let set = { 1, 2 }
let empty = <Set>{}
let record = { a: 1, b: 2 }
let empty = {} PS: Not a fan of the required type annotation for records that @j-f1 suggests. |
This is the other syntax that I'm considering with keywords: let map = map { 'a' = 1, 'b' = 2 }
let empty = map {}
let set = set { 1, 2 }
let empty = set {}
let record = { a: 1, b: 2 }
let empty = {} |
You could also have everything use constructors: let m = map(a=1, b=2)
let s = set(1, 2, 3)
let r = record(a=1, a=2)
let a = array(1, 2, 3)
# etc |
FWIW: I don't love the aesthetic of
{= =}
and{- -}
.Below is my proposal (other proposals are invited to this thread):
The idea is to remove cryptic syntax (
{=
and{-
) and make map keys look less like variable assignments.Along the way, I'm playing with the idea of function calls being able to omit the parentheses when only one argument is passed and it's an object/array literal.
The text was updated successfully, but these errors were encountered: