GithubHelp home page GithubHelp logo

Comments (6)

AltSysrq avatar AltSysrq commented on July 30, 2024 1

the macro invocation looks like a closure

I guess we have different ways of looking at things; I saw it as a function-like macro that mimics a function taking a closure as an argument. (I was wondering why you used braces though; now that makes sense.)

I suppose we'll just have to see how it plays out over time now that it's been released in its current form.

from proptest.

AltSysrq avatar AltSysrq commented on July 30, 2024

To be frank, I'm quite confused about what you're looking for now. Your original PR called runner.run() within the macro.

runner.test

Is this referring to some other test framework? If so, your example could just be written

runner.test("some test", || proptest!(|..| {
  /* ... */
}));

from proptest.

udoprog avatar udoprog commented on July 30, 2024

Hey @AltSysrq

To be frank, I'm quite confused about what you're looking for now. Your original PR called runner.run() within the macro.

You are missing this part which was removed here. The PR had proptest! return a closure which you have to capture and call yourself. After your change it no longer returns a closure, it just evaluates the test in place. Given your comment, I'm not sure this was intentional.

Is this referring to some other test framework? If so, your example could just be written.

Yes, the test framework I use captured the closure in order to execute it as part of a suite. Now there is a fair bit more bracket matching to be done because I have to wrap everything in closures manually.

from proptest.

AltSysrq avatar AltSysrq commented on July 30, 2024

The PR had proptest! return a closure

Yes. I discovered that when trying to document what that usage style did and was so suprised that it was returning a closure that I assumed it was an error.

I don't think returning a closure is a good fit for a general-purpose macro here. Users trying to use it in a normal context would need extra syntax to just invoke the closure immediately after (most likely) finding out the hard way that the macro did absolutely nothing without the extra (), whereas making closures around normal immediate code is something everyone does every day.

Unless there's something else I'm missing, it seems to me that the new form is enough of a building block to just make your own convenience macro.

macro_rules! ptc {
  ($($t:tt)*) => { || proptest!($($t)*) }
}

from proptest.

udoprog avatar udoprog commented on July 30, 2024

Ok!

I don't think returning a closure is a good fit for a general-purpose macro here.

I think the pertinent part here is that the macro invocation looks like a closure. And folks seeing it will likely expect it to behave like a closure. I believe it's considered good practice to try to mimic existing language items when building macros.

If we are after something that performs in-place execution, something that doesn't look like a closure is probably more suitable, like:

proptest!((...) {
})

Unless there's something else I'm missing, it seems to me that the new form is enough of a building block to just make your own convenience macro.

I already have. It's just a bummer that I have to :/.

from proptest.

udoprog avatar udoprog commented on July 30, 2024

Ok, let's let it settle for a while. Thanks for explaining your reasoning!

from proptest.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.