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

basic loops things needed #453

Open
3 of 7 tasks
jessfraz opened this issue Sep 13, 2023 · 4 comments
Open
3 of 7 tasks

basic loops things needed #453

jessfraz opened this issue Sep 13, 2023 · 4 comments
Assignees
Labels
ast Issues / features relevant to ast and parser. kcl Language and compiler features

Comments

@jessfraz
Copy link
Contributor

jessfraz commented Sep 13, 2023

this is my mental notes so i can mess around later

struct ForLoopExpression {
     // the source range start and end
     start: usize,
    end: usize,
     // The var we assign in each loop.
      variable: Identifier,
      // The array we are looping over.
     array: ArrayExpression,
     // This is the inner shit in the loop.
      body: Program,
}
  • then we need the executor to loop over the array expression and re-execute the body changing the identifier value every time

something like that

added some failing tests here: f3589e0

@jessfraz jessfraz self-assigned this Sep 13, 2023
@jessfraz jessfraz added the ast Issues / features relevant to ast and parser. label Sep 13, 2023
@jessfraz
Copy link
Contributor Author

jessfraz commented Sep 13, 2023

Okay before diving in more I wanted to spec this out with a gear and I have something a little like this but I really dont like it

let res = 64
let gear_step = 2 * pi() / res
let half_gear_step = gear_step / 2.0
let gear_radius = 5.0
let gear_sprocket_radius = 6.0

fn getCoord = (r) => {
    let first = {x: gear_radius * sin(gear_step * r), y: gear_radius * cos(gear_step * r)}
    let second = {x: gear_sprocket_radius * sin(gear_step * r), y: gear_sprocket_radius * cos(gear_step * r)}

    return [first, second]
}

let startingCoords = getCoord(0)

let myGear = startSketchAt(startingCoords[0])

for r in [1..64] {
    let lastCoords = getCoord(r - 1)
    let coords = getCoord(r)
    if (n - 1) % 4 < 2 {
        myGear
            |> line([coords[1].x-lastCoords[0].x, coords[1].y-lastCoords[0].y], %)
    } else {
        myGear
            |> line([coords[0].x-lastCoords[1].x, coords[0].y-lastCoords[1].y], %)
    }
}

also requires if statements which we can do, and sin and cos in std lib also doable, and a CONST you can access called PI, also doable.

anyways the pipes get super weird and I bet @adamchalmers had better ideas here

but this is a good example to make work, as in the gear not my syntax

@franknoirot
Copy link
Collaborator

@jessfraz check out this issue in the KCL experimentation repo that @adamchalmers set up: KittyCAD/kcl-experiments#6

@jessfraz
Copy link
Contributor Author

jessfraz commented Sep 13, 2023

okay yeah I like @Irev-Dev example it seems like patterns, unless I'm hallucinating what patterns are but also like @adamchalmers as well

@jessfraz
Copy link
Contributor Author

i like the loop in the pipe like @Irev-Dev has and patterns like that I guess my question is do we need a regular loop then? just like a for x in [] do we even need that?

@jessfraz jessfraz added the kcl Language and compiler features label May 22, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
ast Issues / features relevant to ast and parser. kcl Language and compiler features
Projects
None yet
Development

No branches or pull requests

2 participants