Skip to content

Comments

Update docs to highlight lambda comparison#2146

Merged
wilzbach merged 1 commit intodlang:masterfrom
RazvanN7:patch-5
Feb 20, 2018
Merged

Update docs to highlight lambda comparison#2146
wilzbach merged 1 commit intodlang:masterfrom
RazvanN7:patch-5

Conversation

@RazvanN7
Copy link
Contributor

@RazvanN7 RazvanN7 commented Jan 30, 2018

@dlang-bot
Copy link
Contributor

dlang-bot commented Jan 30, 2018

Thanks for your pull request and interest in making D better, @RazvanN7! We are looking forward to reviewing it, and you should be hearing from a maintainer soon.
Please verify that your PR follows this checklist:

  • My PR is fully covered with tests (you can see the annotated coverage diff directly on GitHub with CodeCov's browser extension
  • My PR is as minimal as possible (smaller, focused PRs are easier to review than big ones)
  • I have provided a detailed rationale explaining my changes
  • New or modified functions have Ddoc comments (with Params: and Returns:)

Please see CONTRIBUTING.md for more information.


If you have addressed all reviews or aren't sure how to proceed, don't hesitate to ping us with a simple comment.

Bugzilla references

Your PR doesn't reference any Bugzilla issue.

If your PR contains non-trivial changes, please reference a Bugzilla issue or create a manual changelog.

statements, the function is considered uncomparable.)
)

---
Copy link
Contributor

Choose a reason for hiding this comment

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

Try the new SPEC_RUNNALE_EXAMPLE_COMPILE macro
Verify with pmake test_dspec

Example: https://github.com/dlang/dlang.org/blob/47bfef14e4275f42b403d75b31628d563f57b1d4/spec/type.dd

manifest constants, enum values and function arguments. If the
expression contains local variables, function calls or return
statements, the function is considered uncomparable.)
)
Copy link
Contributor

Choose a reason for hiding this comment

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

How about adding:

If these constraints aren't fulfilled, the function is considered uncomparable and isSame returns false

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

Getting there. I think some comments explaining your example would be helpful to the reader.

spec/traits.dd Outdated
expression contains local variables, function calls or return
statements, the function is considered uncomparable.)
$(LI If these constraints aren't fulfilled, the function is considered
uncomparable and `isSame` returns $(D false).)
Copy link
Contributor

Choose a reason for hiding this comment

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

This is not part of the list and should be put in a new paragraph after the list.

static assert(__traits(isSame, a => ++a, b => ++b));
static assert(!__traits(isSame, (int a, int b) => a + b, (a, b) => a + b));
static assert(__traits(isSame, (a, b) => a + b + 10, (c, d) => c + d + 10));

Copy link
Contributor

Choose a reason for hiding this comment

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

// lambdas accessing local variables are considered incomparable


int b;
static assert(!__traits(isSame, a => a + b, a => a + b));

Copy link
Contributor

Choose a reason for hiding this comment

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

// lambas calling local functions are considered incomparable.

spec/traits.dd Outdated
expression contains local variables, function calls or return
statements, the function is considered uncomparable.)
$(LI If these constraints aren't fulfilled, the function is considered
uncomparable and `isSame` returns $(D false).)
Copy link
Contributor

Choose a reason for hiding this comment

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

incomparable!

}
}

static assert(__traits(isSame, (A a) => ++a.a, (A b) => ++b.a));
Copy link
Contributor

Choose a reason for hiding this comment

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

// lambdas with different data types are incomparable - even if have the same memory layout

@RazvanN7
Copy link
Contributor Author

@wilzbach Done

Copy link
Contributor

@wilzbach wilzbach left a comment

Choose a reason for hiding this comment

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

LGTM - thanks a lot!

(probably a squash before merging this wouldn't hurt)

@PetarKirov
Copy link
Member

@RazvanN7 squash please.

@RazvanN7
Copy link
Contributor Author

@wilzbach @ZombineDev sorry for the late response. I rebased. Thanks!

@wilzbach wilzbach merged commit 413afd4 into dlang:master Feb 20, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants