Skip to content

Commit

Permalink
fix feature find_first_good_element
Browse files Browse the repository at this point in the history
  • Loading branch information
laowantong committed Sep 21, 2024
1 parent a6d4582 commit 862116f
Show file tree
Hide file tree
Showing 3 changed files with 454 additions and 441 deletions.
17 changes: 10 additions & 7 deletions paroxython/resources/spec.md
Original file line number Diff line number Diff line change
Expand Up @@ -5696,6 +5696,7 @@ Match sequential loops, along with their iteration variable(s).
[⬇️ feature `accumulate_some_elements`](#feature-accumulate_some_elements)
[⬇️ feature `find_best_element`](#feature-find_best_element)
[⬇️ feature `find_best_element_index`](#feature-find_best_element_index)
[⬇️ feature `find_first_good_element`](#feature-find_first_good_element)
[⬇️ feature `for_range`](#feature-for_range)
[⬇️ feature `nested_for`](#feature-nested_for)
[⬇️ feature `universal_quantification|existential_quantification`](#feature-universal_quantificationexistential_quantification)
Expand Down Expand Up @@ -5881,10 +5882,6 @@ GROUP BY path

Iterate over the elements of a (named) collection.

##### Derivations

[⬇️ feature `find_first_good_element`](#feature-find_first_good_element)

##### Specification

```re
Expand Down Expand Up @@ -7461,7 +7458,7 @@ Linear search. Return the first element of a sequence satisfying a predicate.

##### Derivations

[⬆️ feature `for_each`](#feature-for_each)
[⬆️ feature `for`](#feature-for)
[⬆️ feature `if`](#feature-if)
[⬆️ feature `if_test_atom`](#feature-if_test_atom)
[⬆️ feature `return`](#feature-return)
Expand All @@ -7473,7 +7470,7 @@ SELECT "find_first_good_element",
lp.name_suffix,
lp.span,
lp.path
FROM t_for_each lp -- A for each loop...
FROM t_for lp -- A for each loop...
JOIN t_if ON (t_if.path GLOB lp.path || "*-")-- enclosing an if statement...
JOIN t_if_test_atom x ON (x.span_start = t_if.span_start
AND x.name_suffix = lp.name_suffix)-- which tests the iteration variable...
Expand All @@ -7487,14 +7484,20 @@ JOIN t_return ret ON (ret.path GLOB t_if.path || "*-" -- and returns...
1 def search_element(iterable):
2 for element in iterable:
3 if is_good(element):
4 return element
4 return element
5 def largest_prime_below(n):
6 for i in range(n - 1, 1, -1):
7 if is_prime(i):
8 return i
9 return None
```

##### Matches

| Label | Lines |
|:--|:--|
| `find_first_good_element:element` | 2-4 |
| `find_first_good_element:i` | 6-8 |

--------------------------------------------------------------------------------

Expand Down
Loading

0 comments on commit 862116f

Please sign in to comment.