Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The differences between procedures with and without brackets?

Tags:

lisp

scheme

(define (procedere1) (lambda () 2))
(define procedure2 (lambda () 2))

They both can be compiled. But I am confused about the difference between above two procedures.

like image 712
Charq Lou Avatar asked Apr 26 '26 09:04

Charq Lou


2 Answers

The first one is a procedure that returns a procedure. The second one is a procedure that returns the number 2.

In particular, the first one is equivalent to the following:

(define procedure1
  (lambda ()
    (lambda () 2)))
like image 108
Chris Jester-Young Avatar answered Apr 29 '26 05:04

Chris Jester-Young


In general

(define (name arg1 arg2 arg3 ...)
  body)

is shorthand for

(define name
  (lambda (arg1 arg2 arg3 ...) 
    body))
like image 21
Barmar Avatar answered Apr 29 '26 06:04

Barmar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!