Skip to content

Remove closure from programs/stages before it is officially introduced #61

Merged
ryan-gang merged 1 commit intomainfrom
CC-1581
Feb 5, 2025
Merged

Remove closure from programs/stages before it is officially introduced #61
ryan-gang merged 1 commit intomainfrom
CC-1581

Conversation

@ryan-gang
Copy link
Contributor

@ryan-gang ryan-gang commented Feb 5, 2025

Report: https://forum.codecrafters.io/t/wrong-tests-for-ey3/4156

Remove the closure in #EY3, with a higher order function example.

Modify example to demonstrate function application N times
@linear
Copy link

linear bot commented Feb 5, 2025

@ryan-gang ryan-gang self-assigned this Feb 5, 2025
@coderabbitai
Copy link

coderabbitai bot commented Feb 5, 2025

Walkthrough

The changes update test cases by modifying expected outputs and function behavior. In the test helper files, expected results from clock-related computations in Stage 9 tests have been revised. In Stage 4 tests, the function previously named makeAdder is replaced by a new function square, and applyTwice has been updated to applyTimesN to apply a function multiple times. A similar update is reflected in the main test program where the adder functionality is removed, and squaring operations are introduced with corresponding expected outputs.

Changes

File(s) Change Summary
internal/test_helpers/fixtures/pass_functions
internal/test_helpers/fixtures/pass_functions_final
Revised expected outputs for clock-related computations in Stage 9. In Stage 4, replaced makeAdder with square and applyTwice with applyTimesN; updated function signatures and expected numeric outputs accordingly.
test_programs/f6/3.lox Removed the adder creation function and its calls. Introduced the square function and updated the repeated function application from applyTwice to applyTimesN, with changes in expected outputs for squaring operations.

Sequence Diagram(s)

sequenceDiagram
    participant T as Test Runner
    participant C as Clock Function
    T->>C: Call clock()
    C-->>T: Return timestamp
    T->>T: Perform arithmetic (add/divide)
    T-->>T: Print result
Loading
sequenceDiagram
    participant T as Test Runner
    participant A as applyTimesN
    participant S as square
    T->>A: Invoke applyTimesN(N, square, x)
    loop N times
        A->>S: Call square(x)
        S-->>A: Return squared value
        A->>A: Update x with new value
    end
    A-->>T: Return final result
Loading

Poem

I'm a rabbit with a hop in my code,
Skipping through tests on a winding road.
Clock ticks now whisper a brand new tune,
Squaring numbers under a binary moon.
With applyTimesN hopping high and free,
I celebrate these changes with glee! 🐇


📜 Recent review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8671026 and 9e92883.

📒 Files selected for processing (3)
  • internal/test_helpers/fixtures/pass_functions (2 hunks)
  • internal/test_helpers/fixtures/pass_functions_final (2 hunks)
  • test_programs/f6/3.lox (1 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: test
🔇 Additional comments (5)
test_programs/f6/3.lox (3)

4-6: LGTM! Clean and efficient implementation.

The square function is simple, focused, and correctly implemented.


8-17: LGTM! Well-structured higher-order function.

The applyTimesN function is:

  • Well-documented with clear comments
  • Correctly implements function application N times
  • Uses proper variable scoping and loop control

19-24: LGTM! Clear test cases demonstrating the functionality.

The test cases:

  • Show progressive complexity (1, 2, and 3 applications)
  • Include descriptive comments
  • Use consistent placeholder values
internal/test_helpers/fixtures/pass_functions (1)

324-349: LGTM! Test cases match implementation.

The test cases correctly verify:

  • Basic squaring operation
  • Multiple applications of the square function
  • Expected outputs (4, 16, 256) match mathematical expectations
internal/test_helpers/fixtures/pass_functions_final (1)

324-349: LGTM! Consistent with other test fixtures.

The test cases maintain consistency with pass_functions fixture.


🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@ryan-gang ryan-gang requested a review from rohitpaulk February 5, 2025 09:44
@rohitpaulk
Copy link
Member

rohitpaulk commented Feb 5, 2025

@ryan-gang the change makes sense, but the PR description doesn't mention why we're doing this - for the tester repositories, since they're public, I think it's worth spending some time making this clear (doesn't matter so much for core/frontend). Without access to Linear I wouldn't be able to tell that the reason we're doing this is to avoid introducing closures early

@ryan-gang ryan-gang changed the title Update example to demonstrate function application N times Remove closure from programs/stages before it is officially introduced Feb 5, 2025
@ryan-gang
Copy link
Contributor Author

Thanks to @guy-732 for highlighting this!

@ryan-gang ryan-gang merged commit 2d0a2ab into main Feb 5, 2025
2 checks passed
@ryan-gang ryan-gang deleted the CC-1581 branch February 5, 2025 20:18
@andy1li
Copy link
Member

andy1li commented Feb 6, 2025

Thanks @guy-732 for highlighting the issue!

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.

3 participants