roc-lang / examples

All kinds of Roc examples
https://www.roc-lang.org/examples
Creative Commons Zero v1.0 Universal
30 stars 17 forks source link

Example for List as usage (#159) #183

Closed bairymr closed 4 months ago

bairymr commented 4 months ago

Fixes https://github.com/roc-lang/examples/issues/159

In this PR we are adding an example usage of lists and using the "as condition" to extract the tail of the list and continue processing the list.

I was able to test the code but I was not able to view the html files.

Screenshot 2024-06-16 at 11 29 22 PM

In the instructions here when I update the main.roc inside my example to have "packages {pf: /static-site-gen" - I got an error stating I should have interface, app, package or platform. When I changed it to be "package" - I got another error (I am expecting a package name next, like "roc/core". Package names must be quoted). So I couldn't fully view the html files.

lukewilliamboswell commented 4 months ago

@bairymr I updated the script and instructions in #184 so you can see the site locally.

bairymr commented 4 months ago

Thanks @lukewilliamboswell sorry one more question - in the instructions (your's & existing) it says to run this step roc run main.roc -- examples build

Do I run my example code's main.roc ? but then I didn't see any build folder created. I cloned the roc repo, should I run this command in the examples there ? Sorry if this has already been mentioned, I couldn't get past this second step from the instructions to verify the html content.

lukewilliamboswell commented 4 months ago

That PR hasn't merged yet. But here is the link to the main.roc https://github.com/roc-lang/examples/blob/91cda53537d10cf5c6a126164a936829c7ca0e94/main.roc

If you copy that and run it in the root of the roc-lang/examples repository, it will use the basic-ssg platform to generate a static site for the examples. This makes it easier to see how the examples will look locally, before they are merged and ultimately Netlify servers build and host at roc-lang.org.

The roc run main.roc -- examples/ build/ should take the markdown files in examples/ and make a folder called build/ where it will put the generated HTML content.

So then you just need a file server to serve the files on your localhost. We have been using simple-http-server which is easy to get from cargo e.g. cargo install simple-http-server.

bairymr commented 4 months ago

Thanks again for your help here Luke. This all makes sense now. I missed the main.roc from your PR. I copied it over and tried to build it but I got the below error. I guess I may have to try this on a different machine. As per the instructions in basic-ssg package should build in mac x86. I will continue to check this

ld: symbol(s) not found for architecture x86_64
thread 'main' panicked at crates/compiler/build/src/program.rs:1043:17:
not yet implemented: gracefully handle `ld` (or `zig` in the case of wasm with --optimize) returning exit code Some(1)
lukewilliamboswell commented 4 months ago

Thanks again for your help here Luke. This all makes sense now. I missed the main.roc from your PR. I copied it over and tried to build it but I got the below error. I guess I may have to try this on a different machine. As per the instructions in basic-ssg package should build in mac x86. I will continue to check this

ld: symbol(s) not found for architecture x86_64
thread 'main' panicked at crates/compiler/build/src/program.rs:1043:17:
not yet implemented: gracefully handle `ld` (or `zig` in the case of wasm with --optimize) returning exit code Some(1)

What machine are you on. basic-ssg should work on any of these targets.. maybe I need to cut another release. I noticed elsewhere that a later version of rustc fixes some of the musl issues, so I could switch back to that if your having issues on linux.

bairymr commented 4 months ago

I was on x64 MacOS

Anton-4 commented 4 months ago

I apologize for the wasted effort here @bairymr, I wanted the existing pattern matching example to be expanded instead of creating a separate example. It's mentioned in the issue title but it is easy to miss, I should have linked to the existing pattern matching example.

bairymr commented 4 months ago

No worries at all @Anton-4 , Thank you for updating this PR with more details. This all makes sense