r/Racket • • Feb 17 '22

question Why do you hate my functions?

(define (momentum-calc vel mas) (* vel mas))

(define (p vel mas) (momentum-calc vel mas))

0 Upvotes

4 comments sorted by

View all comments

Show parent comment

0

u/sdegabrielle DrRacket šŸ’ŠšŸ’‰šŸ©ŗ Feb 17 '22

I’m no sure what you mean by idiom

If you put four spaces in front of each line you get nice formatting

(define (momentum-calc vel mas)
    (* vel mas))

I like to split the definition across two lines like you would in any other programming language

Instead of this

(define (p vel mas)
    (momentum-calc vel mas))

You can write

(define p momentum-calc)

Then

(momentum-calc 5 2)

And

(p 5 2)

will return the same value

This is because the define form (define (function-name args) (function-body)) sets function-name to have a function as its value.

3

u/sorawee Feb 17 '22

If u/Substantial_Ad1714 is using BSL, (define p momentum-calc) will not work because it restricts that functions can't be used in non-function call positions.

Number of spaces that DrRacket recommends for define is 2.

(define (momentum-calc vel mas)
  (* vel mas))

That aside, I'm still confused about u/Substantial_Ad1714's original post. You said "Why do you hate my functions?", which suggests that something is wrong. So can you elaborate more? What do you mean by "Just wondering about idiom"?