Yes, lambda expression have an implicit begin in the body.

    > (begin . (1 2 3))
    3

    > (begin (1 2 3))
    application: not a procedure;
    expected a procedure that can be applied to arguments
    given: 1
     arguments...:

Here (begin . (1 2 3)) is the same as (begin 1 2 3).

The docs for lambda are here:

http://docs.racket-lang.org/reference/lambda.html?q=lambda#%28form._%28%28lib._racket%2Fprivate%2Fbase..rkt%29._lambda%29%29

Note the body ...+ which means 1 or more bodies are allowed.

/Jens Axel







2016-03-14 18:37 GMT+01:00 Pedro Caldeira <pedro.calde...@bluewin.ch>:

> Does that mean that lambda expressions have an implicit (begin …) block
> in them?
>
> (begin ((displayln 1) (displayln 2) (displayln 3))) leads to an error
>
> (begin . ((displayln 1) (displayln 2) (displayln 3))) displays to 1 2 3
>
> Thank you for the detailed explanation I think I get it now.
>
> On 13 Mar 2016, at 19:48, Jens Axel Søgaard <jensa...@soegaard.net> wrote:
>
> If we use
>
> (define-syntax define/memoized
>   (syntax-rules ()
>     ((_ (name . args) . body)
>      (define name (memoize (lambda args  body))))))
>
> and body is bound to    ((displayln x) (displayln y) (displayz))
> then
>
>     (lambda args  body)
>
> will become
>
>     (lambda <something> ((displayln x) (displayln y) (displayz)))
>
> And when this function is called you will get an error since
>
>     ((displayln x) ...)
>
> means apply the result of (displayln x) to (displayln y) (displayln x).
>
> /Jens Axel
>
>
> --
> You received this message because you are subscribed to the Google Groups
> "Racket Users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to racket-users+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>



-- 
-- 
Jens Axel Søgaard

-- 
You received this message because you are subscribed to the Google Groups 
"Racket Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to racket-users+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to