samuelgoto / proposal-block-params

A syntactical simplification in JS to enable DSLs
205 stars 8 forks source link

Alternative arguments syntax #33

Open vadzim opened 6 years ago

vadzim commented 6 years ago

Could it make sense to make arguments syntax for-like? Instead of writing

// ... this is what you write ...
a(1) do (foo) {
  // ...
}

// ... this is what you get ...
a(1, (foo) => {
  ...
})

we could write

a(let foo of 1) {
  // ...
}
// means
a(1, (foo) => {
  ...
})

a(let [foo, bar] of 1, 2) {
  // ...
}
// means
a(1, 2, ([foo, bar]) => {
  ...
})

a(let foo, bar of 1, 2) {
  // ...
}
// means
a(1, 2, (foo, bar) => {
  ...
})

a(const foo, bar of 1, 2) {
  // ...
}
// means
a(1, 2, (__foo__, __bar__) => {
  const foo = __foo__, bar = __bar__
  ...
})

Or we can use other separator between arguments lists. E.g. ;:

a(let foo; 1) {
  // ...
}
// means
a(1, (foo) => {
  ...
})

a(let [foo, bar]; 1, 2) {
  // ...
}
// means
a(1, 2, ([foo, bar]) => {
  ...
})

a(let foo, bar; 1, 2) {
  // ...
}
// means
a(1, 2, (foo, bar) => {
  ...
})

a(const foo, bar; 1, 2) {
  // ...
}
// means
a(1, 2, (__foo__, __bar__) => {
  const foo = __foo__, bar = __bar__
  ...
})
vadzim commented 6 years ago

Hmmm.. may be the for keyword could be better for that:

a(let foo for 1) {
  // ...
}
// means
a(1, (foo) => {
  ...
})

a(let [foo, bar] for 1, 2) {
  // ...
}
// means
a(1, 2, ([foo, bar]) => {
  ...
})

a(let foo, bar for 1, 2) {
  // ...
}
// means
a(1, 2, (foo, bar) => {
  ...
})

a(const foo, bar for 1, 2) {
  // ...
}
// means
a(1, 2, (__foo__, __bar__) => {
  const foo = __foo__, bar = __bar__
  ...
})