Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[don't merge] Junie examples generation #4706

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from

Conversation

zamulla
Copy link
Contributor

@zamulla zamulla commented Feb 17, 2025

No description provided.

@AlexanderPrendota
Copy link
Collaborator

Bad samples
Snippets:
File: docs/topics/functions.md

fun main() {
//sampleStart
// Non-tail-recursive factorial (less efficient, risk of stack overflow)
fun factorial(n: Long): Long =
    if (n <= 1) 1
    else n * factorial(n - 1)  // Not tail recursive: multiplication after recursive call

// Traditional loop-based implementation
fun factorialLoop(n: Long): Long {
    var result = 1L
    for (i in 1..n) {
        result *= i
    }
    return result
}

// Compares results of different implementations
val n = 5L
println("Tail recursive factorial: ${factorial(n, 1)}")
println("Non-tail recursive factorial: ${factorial(n)}")
println("Loop-based factorial: ${factorialLoop(n)}")
// All print: 120
//sampleEnd
}

(18:50, 18:51) ERROR Too many arguments for 'local final fun /factorial(n: kotlin/Long): kotlin/Long'.


* correct indentations in functions.md
* add (not always fitting, but correct) print comments to generics.md, idioms.md, and interfaces.md
@AlexanderPrendota
Copy link
Collaborator

Bad samples
Snippets:
File: docs/topics/functions.md

fun main() {
    //sampleStart
    // Non-tail-recursive factorial (less efficient, risk of stack overflow)
    fun factorial(n: Long): Long =
        if (n <= 1) 1
        else n * factorial(n - 1)  // Not tail recursive: multiplication after recursive call

    // Traditional loop-based implementation
    fun factorialLoop(n: Long): Long {
        var result = 1L
        for (i in 1..n) {
            result *= i
        }
        return result
    }

    // Compares results of different implementations
    val n = 5L
    println("Tail recursive factorial: ${factorial(n, 1)}")
    println("Non-tail recursive factorial: ${factorial(n)}")
    println("Loop-based factorial: ${factorialLoop(n)}")
    // All print: 120
    //sampleEnd
}

(18:54, 18:55) ERROR Too many arguments for 'local final fun /factorial(n: kotlin/Long): kotlin/Long'.


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.

2 participants