Skip to content

Implement the where: and do: to have the result stated at the end (Issue #863)#900

Open
ad4mf06 wants to merge 4 commits intoevhub:developfrom
ad4mf06:feature/where-final-result-863
Open

Implement the where: and do: to have the result stated at the end (Issue #863)#900
ad4mf06 wants to merge 4 commits intoevhub:developfrom
ad4mf06:feature/where-final-result-863

Conversation

@ad4mf06
Copy link

@ad4mf06 ad4mf06 commented Feb 19, 2026

Changes

  • Added block_where_stmt grammar rule supporting lhs = where: <suite> syntax
  • Last statement in the suite becomes the result assigned to lhs
  • Supports both where: and do: keywords
  • Handles variable scoping with name management

Example

out = where:
    x = 1 + 2 + 3
    y = 4 + 5 + 6
    x + y
assert out == 21

Testing

Added comprehensive tests in coconut/tests/src/cocotest/agnostic/primary_1.coco covering:

  • Addition: Simple sum operations
  • Multiplication: Product calculations
  • Division: Division operations
  • Chained calculations: Variables depending on previous computations
  • String concatenation: Text operations
  • Large blocks: Multiple statements with complex expressions

All tests are duplicated to verify both where: and do: syntax work identically.

Fixes #863

Adam Forest added 2 commits February 19, 2026 08:39
…t compiled into a python where statement. I added some test too.
@ad4mf06 ad4mf06 changed the base branch from master to develop February 24, 2026 19:27
@evhub
Copy link
Owner

evhub commented Feb 26, 2026

This looks pretty good! We should pick only one of these two syntaxes, though, and you should make sure to test that the variables in the where clause are properly hidden from the enclosing scope. I think I probably prefer the where: syntax over the do: syntax since do has a specific meaning in many functional programming languages that is not this.

@ad4mf06
Copy link
Author

ad4mf06 commented Feb 26, 2026

I agree with you, "where" is a better name for this function. I'll remove the do: syntax and remove the test I added with that syntax. I also added a test to make sure that the variables in the where clause are properly hidden from the enclosing scope.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

where with final result at end

2 participants