Hi, I've started the implementing http://raytracerchallenge.com/ in roc, following the book.
I'm also learning roc on the way (but I have some experience with Haskell and Elm).
Now the book gives you some tests in natural language-BDD style and you have to implement them.
For example:
Scenario: A tuple with w=1.0 is a point
Given a ← tuple(4.3, -4.2, 3.1, 1.0)
Then a.x = 4.3
And a.y = -4.2
And a.z = 3.1
And a.w = 1.0
And a is a point
And a is not a vector
I implemented them as:
isVector = \v -> v.w == 0.0
isPoint = \p -> p.w == 1.0
a = {x:4.3, y:-4.2, z:3.1, w:1.0}
expect isVector a == Bool.false
expect isPoint a == Bool.true
Does this seem ok?
some other doubts I had so far:
Ideally I would like to separate tests from the code... but not sure if it's a good idea in roc.
Would be a good idea to name my record type (x,y,z,w: I32?)? Opaque types seems the best choice to me but I'm not sure.
The doc and the tutorial and very good, and I didn't have any particular problem, but I really liked the Clojure Koans when learning Clojure and I wrote something similar for Kotlin years ago... maybe once I've finished my raytracer... :)
Btw I've started using IntelliJ as editor, because it's just convenient for me. I don't think there is a plugin for roc, but I may write one before long. :)
thanks to everybody for the effort and the great language, it's a lot of fun writing in roc!
Hi Uberto :)
a = {x:4.3, y:-4.2, z:3.1, w:1.0}
I think the idiomatic Roc way would be:
vectorOrPoint : [Vector, Point]
a = {x:4.3, y:-4.2, z:3.1, w: Point}
but I really liked the Clojure Koans when learning Clojure and I wrote something similar for Kotlin years ago... maybe once I've finished my raytracer... :)
Adding exercises to some examples is something we've talked about in the past. Exercises make things stick :). In Roc it would be especially cool because you could complete them in the browser, just like we do with the web repl.
I don't think there is a plugin for roc, but I may write one before long. :)
That would be awesome, fyi we have a language server. The vscode plugin may be useful inspiration as well.
Ideally I would like to separate tests from the code... but not sure if it's a good idea in roc
I don't think we've ever done that but you should be able to make an interface module that imports the functions you want to test. I also made an issue in the examples repo to demonstrate how to do this.
thanks Anton, I will follow your suggestions and I'll keep posting things that makes me confused. :)
Last updated: Jul 06 2025 at 12:14 UTC