JuliaLang / JuliaLang/julia

comprehension syntax should respect the local variables defined in if clause

Open
#32,905 5 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

compiler:lowering design iteration speculative
Dominant language
Julia
Stars
49.1k
Forks
6k
Avg merge
2d 2h
Merged PRs (30d)
209

Description

It will be nice if comprehension syntax respects the local variables defined in if clause.

For example, filter_map of Ruby 2.7 or Rust will be implemented as follows

filter_map(f, a) = (y for x in a if (y=f(x)) !== nothing)

Python 3.8 will introduce the assignment expressions which makes this possible.
https://docs.python.org/3.8/whatsnew/3.8.html
https://www.python.org/dev/peps/pep-0572/#simplifying-list-comprehensions

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Begin with the comprehension example in the issue and compare its intended behavior with Julia's current local-variable scoping rules. No source file or test is named, so first locate the comprehension parser and relevant scope tests. Done means the shown filter_map pattern can bind y in the if clause and use it as the comprehension result without changing unrelated scoping behavior.

Written by the indexing model from the issue text.

Assessment

Tech stack
julia
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.