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

Is "unique names" enough? #1633

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Update Environments.Rmd
Okay, I just read the issue #734 and I understand that there is a delicate situation here:

- Saying that every object in an Environment must have an unique name is **conceptualy wrong**. 

- It is also not recommendable to leave as it is today. It takes some reading to undo the confusion that this makes.

To say that "Every name must be unique", make it seems that, in this matter, the difference between lists and environments is just that two elements of a list can have the same name, but not in an environment. Yes, this is truth, but is an incomplete truth.


As it is written today, it makes you think that the difference is that `l` can have 2 elements named "a", while `e` cannot.

``` r
l <- list("a" =1, "a" =2, "b" = 3)
  
e <- rlang::env("a" = 1, "a" = 2, "b" = 3)
  
l
#> $a
#> [1] 1
#> 
#> $a
#> [1] 2
#> 
#> $b
#> [1] 3
 
rlang::env_print(e)
#> <environment: 0000000013A104A8>
#> parent: <environment: global>
#> bindings:
#>  * a: <dbl>
#>  * b: <dbl>

```
<sup>Created on 2020-10-22 by the [reprex package](https://reprex.tidyverse.org) (v0.3.0)</sup>

This does not makes it simplier to the reader understand that an environment is the set of names that binds objects with names. It only makes it seem that an environment is list that does not allow repeated names (and with the other elements, that it does not order it). Therefore I suggest to change the present text adding a fifth difference (that it cannot have an element not binded to a name in an environment.
  • Loading branch information
MarceloRTonon authored Oct 22, 2020
commit bc41ba9e6e911784b0c92246512a8458392144ce
8 changes: 5 additions & 3 deletions Environments.Rmd
Original file line number Diff line number Diff line change
Expand Up @@ -59,9 59,11 @@ The `env_` functions in rlang are designed to work with the pipe: all take an en

## Environment basics {#env-basics}

Generally, an environment is similar to a named list, with four important exceptions:
Generally, an environment is similar to a named list, with five important exceptions:

* Every name must be unique and all of its objects be binded to a name.
* Every name must be unique.

* All elements must be binded to a name.

* The names in an environment are not ordered.

Expand Down Expand Up @@ -896,7 898,7 @@ As well as powering scoping, environments are also useful data structures in the

## Quiz answers {#env-answers}

1. There are four ways: every object in an environment must have a name;
Copy link
Author

Choose a reason for hiding this comment

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

Even if my alterations are not implemented, this must be changed to be consistent with #734

1. There are five ways: every name must be unique; every element in an environment must be binded to a name;
order doesn't matter; environments have parents; environments have
reference semantics.

Expand Down