Ray Tracing in J

https://news.ycombinator.com/rss Hits: 15
Summary

Ray Tracing in J 2020-04-18 I've been reading up on J and decided another small project was in order, this time I've written a minimal ray tracer. Brevity J is, perhaps infamously, a terse language. I think it may sometimes get unfairly discounted for this brevity because of the flavor of the syntax (namely, ASCII). It can be a little hard to describe, but the syntax isn't the hard part of learning J, the jarring parts are a result of the paradigm differences in array programming. By the time I've started to wrap my head around the very functional, array oriented style of programming the syntax has started to fall away. At least in the case of my own code I don't find the syntax being an obstacle, I'm curious how this would hold up in the face of someone else's code. Tacit Verbs One piece of syntax that bears explaining is J's means of tacit programming (that is, functions which make no reference to their arguments). While there is a bit more depth to it than I bother using, I've limited myself to using mostly trains of three verbs, so-called forks. A fork is a function comprised of three verbs, F G and H and might look like this: myNewVerb=. F G H NB. results in application (F(y)) G (H(y)) The parsing rules for J identify this pattern and apply the function in a specific way; the canonical example is to define "average": sum=. +/ divide=. % count=. # average=. sum divide count If you applied it to an array 1 2 3 4 5: average 1 2 3 4 5 NB. (sum 1 2 3 4 5) divide (count 1 2 3 4 5) One last thing that may confuse the untrained eye is the order of evaluation. Sentences respect the traditional means of evaluating parenthesized phrases first, but otherwise proceed from right to left. An example: - +/ 1 2 3 _6 The result will be the sum of 1 2 3 (6), which is then negated, so the result is -6 (which is written as _6 to avoid confusion with the minus/negate symbol). Utility Verbs I've written several verbs in the tacit style that are generally useful or improve the reading...

First seen: 2025-05-30 21:25

Last seen: 2025-05-31 13:27