sweet-core icon indicating copy to clipboard operation
sweet-core copied to clipboard

Array accessor custom operator

Open ghost opened this issue 8 years ago • 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 }.

ghost avatar Jun 02 '17 08:06 ghost

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.

gabejohnson avatar Jun 02 '17 12:06 gabejohnson

I mean argument that means key/index.

ghost avatar Jun 02 '17 12:06 ghost

Can you provide example usage?

gabejohnson avatar Jun 02 '17 12:06 gabejohnson

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)

ghost avatar Jun 02 '17 12:06 ghost

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

gabejohnson avatar Jun 02 '17 13:06 gabejohnson

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

ghost avatar Jun 02 '17 14:06 ghost