Skip to content

[WIP] Let In Syntax Initial Impl#578

Draft
oldwomanjosiah wants to merge 7 commits into
elkowar:masterfrom
oldwomanjosiah:josiah/add_let_in
Draft

[WIP] Let In Syntax Initial Impl#578
oldwomanjosiah wants to merge 7 commits into
elkowar:masterfrom
oldwomanjosiah:josiah/add_let_in

Conversation

@oldwomanjosiah
Copy link
Copy Markdown
Contributor

@oldwomanjosiah oldwomanjosiah commented Sep 19, 2022

Description

This is not intended to be final, but I had some time so I thought I would work on this. First pass ended up being easier than I was expecting.

Usage

(defvar somevar {{ "key": "Some Value" }})
(label
  :text { let it = somevar.value in "Here Is ${it}" end })

Showcase

My current workspace indicator:

image

Where I have a script that outputs the following on workspace changes:

{
  "1": {
    "dis": -1,
    "ex": false,
    "urg": false
  },
  ...
}

And the let-in syntax to pull out the relevant information for each part

(defwidget workspaceIndicator [num monitor]
  (box :orientation "v"
    (button
      :class {
        let
          ws = active_workspaces["${num}"],
          foc = ws.dis == monitor ? " focused" : "",
          vis = ws.dis >= 0 ? " visible" : "",
          ex = ws.ex ? " exists" : ""
        in
          "indicator " + foc + vis + ex
        end
      }
      :onclick "scripts/workspaces set ${num}"
      (box :orientation "v"
        (box :orientation "h"
          (box :class "inner"))))))

Diffs containing fuller example of usage

Additional Notes

I borrowed the testing macro from #577

Checklist

Please make sure you can check all the boxes that apply to this PR.

  • All widgets I've added are correctly documented.
  • I added my changes to CHANGELOG.md, if appropriate.
  • The documentation in the docs/content/main directory has been adjusted to reflect my changes.
  • I used cargo fmt to automatically format all code before committing

@oldwomanjosiah oldwomanjosiah changed the title Add Let In Syntax [DRAFT] Let In Syntax Initial Impl Sep 19, 2022
),
x @ Literal(..) => x,
LetIn(_, d, b) => {
todo!("Resolve Refs is unused, TODO(josiah)");
Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It's unclear to me atm what should be done here. As far as I can tell the function is (transitively) unused, and could be removed, so it might not be a problem.

It might make the most sense to use the values from the let block to map the inner vars, but the variable defs haven't been evaluated yet here.

@oldwomanjosiah oldwomanjosiah changed the title [DRAFT] Let In Syntax Initial Impl [WIP] Let In Syntax Initial Impl Sep 19, 2022
@oldwomanjosiah
Copy link
Copy Markdown
Contributor Author

@elkowar Just following up here to see if you have any feedback on the direction of this? Specifically if try_map_var_refs can/should be removed, or if not what the behavior there should be, but also in general.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant