Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

I think twice about writing for loops. Functional style APIs make these kinds of mistakes way less common


Personally I'm a fan of list comprehension, particularly as implemented by rackets for/list forms. I certainly don't use them for everything, sometimes a plain old map fits the circumstance better, but I find myself using for/list fairly often. And I don't think it's error prone in the same way that a traditional C-style for loop would be.

https://docs.racket-lang.org/reference/for.html?q=for%2Flist...

    > (for/list ([i '(1 2 3)]
                 [j "abc"]
                 #:when (odd? i)
                 [k #(#t #f)])
        (list i j k))
    
    '((1 #\a #t) (1 #\a #f) (3 #\c #t) (3 #\c #f))




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

Search: