Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

stdLambda Syntax Improvements #55

Open
2 of 6 tasks
sancarn opened this issue Jun 2, 2022 · 0 comments
Open
2 of 6 tasks

stdLambda Syntax Improvements #55

sancarn opened this issue Jun 2, 2022 · 0 comments
Labels
enhancement New feature or request lib-stdLambda

Comments

@sancarn
Copy link
Owner

sancarn commented Jun 2, 2022

Tasks

  • Lambda syntax (a,b,c)=> ...
  • Let/Set syntax let a.b = ...
    • Have a let operator a.b := ... (Is this still required?)
    • Introduce a Let/Set keyword
  • Allow column syntax [Some column] and include row property
  • Add try/catch

Allow parameter names: stdLambda.Create("(a,b,c) => a*b+c")

Not only has this been heavily requested, it would improve ease of use and it isn't too tricky to implement.

Allow vbLet | vbSet: set a.b = something, let a.c = true

One of the downfalls of lambdas so far is the inability to trigger vbLet/vbSet There are 2 options here:

Have a let operator e.g. :=

a.b := something

This is probably the easiest to implement:

if consume() = eObjectGetter and peak(2) = eObjectSetter then
  beginLetExpression()
else
  beginGetExpression()
end if

Introduce a let an set keyword:

Not entirely sure how this would work internally but this would be the typical VBA approach.

set a.b = something
let a.c = 1

Allow column syntax [Some column] and include row property

Say you are looping through rows of a csv, it would be nice if we had a good way of accessing the columns of each row. The current easiest way to do this is with dictionaries:

stdLambda.Create("$1.item(""column 1"") + $1.col2").bind(row)

'or with change 1:
stdLambda.Create("(row)=>row.col1 + row.col2").bind(row)

This change proposes the addition of a row variable on stdLambda instances.

Dim lambda as stdLambda: set lambda = stdLambda.Create("[column 1] + [col2]")
for each row in csv
  set lambda.row = row
  if lambda() > 5 then
    '...
  end if
next

Add try-catch

Say we are using stdWindow to search for ProcessIDs e.g.

set eOut = wnds.Filter(stdLambda.Create("$2.ProcessID = $1").bind(proc.id))

stdWindow is built in such a way that if the window no longer exists ProcessID will throw an error. This can be worked around with if statements to catch the error:

set eOut = wnds.Filter(stdLambda.Create("if $2.exists then $2.ProcessID = $1 else false").bind(proc.id))

but it would be nice to have a try catch also:

set eOut = wnds.Filter(stdLambda.Create("Try $2.ProcessID = $1 Catch false").bind(proc.id))

Add short circuiting out of OR and AND

  • if a or b then should immediately skip to then if a is true, without needing to check b.
  • if a and b then ... else ... should immediately skip to else if a is false.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request lib-stdLambda
Projects
Status: Feature Request/Unknown requirement
Development

No branches or pull requests

1 participant