[racket] two question about DrRacket
The other option is to use values:
(define (p x)
(values (+ x 10)
(* x 10)))
That will return 2 values.
However, if you want to actually "display" the answers, you can:
(define (p x)
(displayln (+ x 10))
(displayln (* x 10)))
[]'s
Rodolfo Carvalho
On Thu, Jun 2, 2011 at 09:52, Hendrik Boom <hendrik at topoi.pooq.com> wrote:
> On Wed, Jun 01, 2011 at 02:57:41PM -0700, Yingjian Ma wrote:
> > Hi all,
> >
> > 1 I wrote
> >
> > (define (p x)
> > (+ x 10)
> > (* x 10)
> > )
> >
> > The result of (p 4) is 40. How can I display 14 and 40?
>
> You could return a list instead of the individual numbers. The way
> you've coded it, the 14 is computed, then discarded. Then the 40 is
> computed and returned.
>
> In LISP I'd code (list (+ x 10) (* x 10)). I'm not quite sure if 'list'
> is still called 'list' in Scheme, though; a lot of the built-in function
> names have changed since the 60's, when I was heavily involved with
> Lisp. Look it up.
>
> -- hendrik
> _________________________________________________
> For list-related administrative tasks:
> http://lists.racket-lang.org/listinfo/users
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.racket-lang.org/users/archive/attachments/20110603/6bf5a20c/attachment.html>