[plt-scheme] Why does (begin ((lambda () (values))) (display "k")) fail?
Values is a very advanced feature.
Using it, you can return multiple values from one procedure.
But you can't use that procedure like any other one. You have to use
call-with-values or define-values or let-values, etc.
When you apply procedures, each argument must have exactly one value.
When you use begin, or a procedure body, etc., each expression must have
exactly one value.
The only place except special value functions where values work properly is
the REPL.
Therefore,
(begin
; ...
(values)
; ...
"k")
fails.
I also suggest you use the learning languages, and HtDP, to learn Scheme.
Yours,
ifconfig.
> -----Original Message-----
> From: plt-scheme-admin at list.cs.brown.edu [mailto:plt-scheme-
> admin at list.cs.brown.edu] On Behalf Of Anders Conradi
> Sent: Wednesday, May 19, 2004 10:19 AM
> To: plt-scheme at list.cs.brown.edu
> Subject: [plt-scheme] Why does (begin ((lambda () (values))) (display
> "k")) fail?
>
> For list-related administrative tasks:
> http://list.cs.brown.edu/mailman/listinfo/plt-scheme
>
> Hi,
>
> I am trying to teach myself scheme, but I stumble on the most basic
> expressions.
> Why does the following behave as it does? I don't understand the
> message about "context expected 1 value, received 0 values". I was
> expecting (begin (l) (display "k")) to display k.
> If I try the same expression in mzscheme it behaves as I expected.
>
> Welcome to DrScheme, version 206p1.
> Language: Standard (R5RS).
> > (define l (lambda () (values)))
> > (begin (l) (display "k"))
> context expected 1 value, received 0 values
> > ((lambda () (begin (l) (display "k"))))
> k
>
> Grateful for any clues,
> // Anders