Hacker News new | past | comments | ask | show | jobs | submit login
Eager Comprehensions (2003) (schemers.org)
21 points by pmoriarty 3 months ago | hide | past | web | favorite | 3 comments

It is well worth a mention that srfi-42 inspired racket's loops. It is actually a pretty neat looping protocol, and I ended up looking at it quite a lot for inspiration when implementing my own loop facilities.

The reference implementation is pretty cool since it is implemented only using syntax-rules (the standardised high level, strictly hygienic macro facility of scheme). That is a special level of masochism right there, but it is probably also why the reference implementation has to use set! instead of generating pure tail-recursive (and thus continuation safe) code.

I ended up implementing something not unlike racket's for guile scheme [0] using syntax-case. I find that syntax easier to work with and understand, and the code generated is better than srfi-42. In fact it is almost always zero overhead, just like racket's loops.

[0]:https://bitbucket.org/bjoli/guile-for-loops the readme is not really correct. I now support both pre-checks and lazy loops, but I am cleaning some things up for a first release. The docs are here: https://koketteriet.se/software/guile-for-loops/docs.html

Note that it is possible to implement SRFI-42 using `syntax-rules` - the only available macro system in R5RS.

That's what I said :)

Come to think of it, a large subset of racket's for loops is possible to implement using syntax rules, but I wouldn't recommend it.

Applications are open for YC Summer 2019

Guidelines | FAQ | Support | API | Security | Lists | Bookmarklet | Legal | Apply to YC | Contact