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

EEP 70: Implement non-skipping generators (as an experimental feature) #8625

Open
wants to merge 4 commits into
base: master
Choose a base branch
from

Commits on Jun 28, 2024

  1. Configuration menu
    Copy the full SHA
    30e0be0 View commit details
    Browse the repository at this point in the history
  2. Configuration menu
    Copy the full SHA
    cf3d187 View commit details
    Browse the repository at this point in the history

Commits on Aug 24, 2024

  1. [WIP] Implement non-skipping generators as an experimental feature.

    Currently existing generators are "skipping": they ignore terms in
    the right-hand side expression that do not match the left-hand side
    pattern. Non-skipping generators on the other hand fail with
    exception badmatch.
    
    The motivation for non-skipping generators is that skipping generators
    can hide the presence of unexpected elements in the input data of a
    comprehension. For example consider the below snippet:
    
    [{User, Email} || #{user := User, email := Email} <- all_users()]
    
    This list comprehension would skip users that don't have an email
    address. This may be an issue if we suspect potentionally incorrect
    input data, like in case all_users/0 would read the users from a
    JSON file. Therefore caucious code that would prefer crashing
    instead of silently skipping incorrect input would have to use
    a more verbose map function:
    
    lists:map(fun(#{user := User, email := Email}) -> {User, Email} end,
              all_users())
    
    Unlike the generator, the anonymous function would crash on a user
    without an email address. Non-skipping generators would allow
    similar semantics in comprehensions too:
    
    [{User, Email} || #{user := User, email := Email} <:- all_users()]
    
    This generator would crash (with a badmatch error) if the pattern
    wouldn't match an element of the list.
    
    Syntactically non-skipping generators use <:- (for lists and maps)
    and <:= (for binaries) instead of <- and <=. This syntax was chosen
    because `<:-` and `<:=` somewhat resemble the `=:=` operator that
    tests whether two terms match, and at the same time keep the operators
    short and easy to type. Having the two types of operators differ by
    a single character, `:`, also makes the operators easy to remember as
    "`:` means non-skipping."
    
    Nevertheless, non-skipping generators are added as an experimental
    feature, that has to be explicitly enabled:
    
    -feature(non_skipping_generators,enable).
    
    change operators
    dszoboszlay committed Aug 24, 2024
    Configuration menu
    Copy the full SHA
    ad90a17 View commit details
    Browse the repository at this point in the history
  2. Update primary bootstrap

    dszoboszlay committed Aug 24, 2024
    Configuration menu
    Copy the full SHA
    5544be6 View commit details
    Browse the repository at this point in the history