sweet-js/sweet-core

Array accessor custom operator

Opened this issue · 6 comments

Hello. I also have idea for custom operators with arrays.

operator {@} accessor 19 = (object, index) => {
  return #`[object, index]`; // for feed some functions with spreads, for example - Atomics
}

Where symbol @ are divisor between { and }.

For your proposed syntax, you'll have to wait for #687 to be resolved.

I'm not sure what accessor is supposed to designate in your operator declaration.

I mean argument that means key/index.

Can you provide example usage?

Really good for SIMD, Typed Array operations, Atomics.

let arrayPtr = typedarray{0}; // getting [typedarray, 0]
// also would be operators with pointers i.e. right pair value 
let value = *arrayPtr; // arrayPtr[0][arrayPtr[1]] as getter
*arrayPtr = anotherValue; // arrayPtr[0][arrayPtr[1]] as setter
Atomics.add(...arrayPtr, 1); // using ptr as arguments of Atomics (workers)

There's currently no way to use operator or syntax to modify the meaning of delimiters ([],{},()). You'd have to extend the reader.

I can do array $ptr 0 but this is not very nice syntax. I want like this array |> 0.