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

consistently use do lambda #25

Closed
wants to merge 1 commit into from
Closed

Conversation

krux02
Copy link
Contributor

@krux02 krux02 commented Sep 3, 2019

This change makes consistent use of the do notation. The no notation is an official syntax for lambda expressions. Without the do the code relies on implicit conversions of statement list to a callback lambda expression. As mentioned in my earlier PR, this feature is flaky.

@iffy
Copy link
Owner

iffy commented Sep 4, 2019

If it's at all possible to keep, I love the current terse syntax. Could something be done within argparse to allow users to not have to use do?

For instance, could argparse do the same thing nimscript does for tasks? https://github.com/nim-lang/Nim/blob/master/lib/system/nimscript.nim#L331 Does that avoid flakiness?

@krux02
Copy link
Contributor Author

krux02 commented Sep 4, 2019

well, currently command is written as a proc that takes a procedure argument as the last argument. In this situation you need a lambda expression. Nim has many different syntaxes for this. Here are they:

import sugar

proc command*(name: string, group: string, content: proc()) =
  content()

command "a","b", proc() =
  echo 1
  echo 2
  echo 3

command("a","b", proc() =
  echo 1
  echo 2
  echo 3
)

command("a","b") do:
  echo 1
  echo 2
  echo 3

command("a","b", () => (echo 1; echo 2; echo 3))

From all these options I still think the do notation is the most compact. But for that API you need to pick one lambda syntax.

An alternative would be to make command into a template. You can pass a block of code to a template that isn't a lambda and you can instantiate it as many times as you want. No do: required.

@krux02
Copy link
Contributor Author

krux02 commented Sep 20, 2019

My PR to mainline Nim is blocked by this PR. Is there anything preventing this PR from being merged?

Here is the error message:
https://ci.appveyor.com/project/dom96/nim/builds/27155600/job/kdrac67cvypbmjkt/tests

@iffy
Copy link
Owner

iffy commented Sep 21, 2019

Sorry for the delay! Just busy with life and job.

I was hoping to see if I could switch to a template to keep the more terse syntax. Let me see if I can do it quickly, otherwise, I'll merge this one in.

@iffy
Copy link
Owner

iffy commented Sep 21, 2019

Fixed in v0.8.3. Thank you so taking the time to explain do:!

@iffy iffy closed this Sep 21, 2019
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.

2 participants