News for hackers. Stuff that matters.
Re:Brett Slatkin: Why am I building a new functional program... by bslatkin on Sunday March 05, 2023 @11:37PM (#35037559)
For a very simple, single-expression lambda function I agree you don't need an explicit return. Even Python skips the "return" for lambdas. But for anything more complex, I find explicit returns, especially early returns, makes the code much more readable for people who are used to imperative languages.

For example, which of these is more clear to people who don't know Lisp? I'd argue the second one because of the early return if guard.

    ---- THIS ----

    (defun sum-helper (items total)
        (cond
            (items
                (sum-helper
                    (cdr items)
                    (+ total (car items))))
            (t total)))

    (defun sum (&rest items)
        (sum-helper items 0))

    (print (sum 1 2 3 4))

    ----- OR -----

    (defun sum-helper2 (items total)
        (if (not items)
            (return-from nil total))

        (sum-helper
            (cdr items)
            (+ total (car items))))

    (defun sum2 (&rest items)
        (sum-helper2 items 0))

    (print (sum2 5 6 7 8))
        (sum-helper items 0))
Re:Brett Slatkin: Why am I building a new functional program... by noelwelsh on Monday March 06, 2023 @06:03AM (#35039612)
I think I'll write a blog post in response, as I believe this illustrates a much deeper and more important issue.
Re:Brett Slatkin: Why am I building a new functional program... by bslatkin on Monday March 06, 2023 @09:12AM (#35041205)
Great! Please send it my way so I don't miss it. Thank you
Re:Brett Slatkin: Why am I building a new functional program... by noelwelsh on Monday March 06, 2023 @01:02PM (#35044840)
I have a draft up here: https://noelwelsh.com/posts/fp-is-based/

(It should be readable but hasn't had a final editing pass.)