chansey97
2021-7-21 15:33:54

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:


soegaard2
2021-7-21 15:44:56

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


chansey97
2021-7-21 15:46:21

@soegaard2 Thanks. I will look into it.


soegaard2
2021-7-21 15:57:16

@chansey97 Oh btw - in CS papers: it’s probably to keep the grammar as simple as possible.


greg
2021-7-21 17:43:34

In Racket even (define f (lambda (x) x)) is “just sugar” for (define-values (f) (lambda (x) x)). :smile:


greg
2021-7-21 17:44:24

As with writing prose I think this is something where you pick something based on (hopefully) knowing your audience.


greg
2021-7-21 17:45:01

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?


greg
2021-7-21 17:45:51

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.


greg
2021-7-21 17:50:40

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.


ben.knoble
2021-7-21 18:09:07

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.


soegaard2
2021-7-21 19:01:02

@greg Very nice explanation.


seanbunderwood
2021-7-21 22:13:29

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?


ben.knoble
2021-7-21 22:19:27

Hm, true. It would certainly be of limited use in certain situations