Out of curious, (define (my-procedure x)
body)
vs (define my-procedure
(lambda (x)
body))
Why do some people choose the second form to define a procedure? (especially in some PL papers) Is there any advantage? :thinking_face:
As you point out it is mostly a Style issue. The second form makes it very clear that functions are first class values.
Don’t know if the discussion is helpful, but here is a thread on the subject: https://groups.google.com/g/comp.lang.scheme/c/qXo8x-azlik/m/8Rz0hfasMLsJ
@soegaard2 Thanks. I will look into it.
@chansey97 Oh btw - in CS papers: it’s probably to keep the grammar as simple as possible.
In Racket even (define f (lambda (x) x))
is “just sugar” for (define-values (f) (lambda (x) x))
. :smile:
As with writing prose I think this is something where you pick something based on (hopefully) knowing your audience.
Is it CS researchers? Intro CS students? A team on a project with thousands of definitions and a desire to reduce verbosity on routine things like definitions?
So I think ideally you learn they’re all equivalent, and then, pick the level of “sugar” or abbreviation that makes sense for the situation at hand.
p.s. When you define functions that return other functions? There are at least three different styles, each with pros and cons. Here honestly I kind of wing it, picking one based on the context and the complexity.
One of the few things I miss about ML that hasn’t been effectively ported (outside of curry
) is the ability to cleanly define curried functions and use them in higher-order ways.
@greg Very nice explanation.
I miss that, too, but part of me also wonders if automatic partial application might not have a tendency to get really confusing in a dynamic language that permits variable-length argument lists?
Hm, true. It would certainly be of limited use in certain situations