Skip to content

eval-syntax #74

@DrSensor

Description

@DrSensor

Expose an eval syntax. Similar to new Function() (used by AlpineJS) or eval() but doesn't expose global variable and Web API. Also no new variable creation a.k.a let or const. No declaration, no statement, no loop. It just an expression. However, it may have ternary operation and range/slice bound.

Some ideas:


Operator that exclusive for string, list/array, and vector/matrix are denoted in [ops]. There's some ops-syntax borrowed from other lang.

concat (inspired by Lua)

<span ~ #text="
  ret:sepByComma<~`(scale3d[..][0,0,0])
"></span>

same as

span.textContent = sepByComma(
  scale3d.concat([0, 0, 0])
)

scalar add on vector

<span ~ #text="
  ret:sepByComma<~`(scale3d[+]5)
"></span>

same as

span.textContent = sepByComma(
  scale3d.map(it => it + 5)
)

addition between vector

<span ~ #text="
  ret:sepByComma<~`(scale3d[+]pos2d)
"></span>

roughly same as

span.textContent = sepByComma(
  Array.from(
    { length: Math.max(scale3d.length, pos2d.length) },
    (_, i) => (scale3d[i] ?? null) + (pos2d[i] ?? null),
  )
)

Note that to enter eval-syntax, the expression should be wrapped in `()

Metadata

Metadata

Assignees

No one assigned

    Labels

    data bindingEverything related to data bindingenhancementNew feature or requestexperimentalBreaking changes can happen at any timepriority: lowLow hanging issue. Might not worth to tackle it now.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions