Skip to content

(gen)

generator expressions

clojure
(gen body?)

Where:

  1. body: expression yielded by the generator (the x in (x for x in items)) *

Matching:

  1. simple generators, e.g. (x for x in items)
  2. filtered generators, e.g. (f(x) for x in items if x)

Behavior

  • Does not match list comprehensions like [x for x in items].

Examples

Find generators that yield identifiers directly.

clojure
(gen (id x))

Selects in lines { 1 } but not in { 2 }:

python
(x for x in items)
(y for y in items)

Locate sum calls that use a generator expression.

clojure
(call (id "sum") (gen))

Selects in lines { 1 } but not in { 2 }:

python
total = sum(x for x in items)
total = sum([x for x in items])

Find generators that call len on each item.

clojure
(gen (call len))

Selects in lines { 1 } but not in { 2 }:

python
sum(len(x) for x in items)
sum(x for x in items)

Arguments

body

(:kind) (:ref) (:text) (call) (fun) (gen) (id) (num) (str) (:into) (:and) (:or) (:not) (:replace) (:capture)

Copyright © 2022-present Semantic Works, Inc.