Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

Really Dumb Newbie Question

3 views
Skip to first unread message

Samantha Skyler

unread,
May 23, 2002, 4:09:17 PM5/23/02
to
OK.....

I want to round a numnber

when I enter (round 5.5)

lisp spits out:
6 ;
-.1000000000000000000000f0

How do I just get lisp to return the rounded number without all that junk?

Thanks
-Samantha

Nils Goesche

unread,
May 23, 2002, 4:16:33 PM5/23/02
to
samanth...@hotmail.com (Samantha Skyler) writes:

> I want to round a numnber
>
> when I enter (round 5.5)
>
> lisp spits out:
> 6 ;
> -.1000000000000000000000f0

Sure that was the actual output? Which Lisp are you using? Anyway,
what is your problem? ROUND returns two values, apparently you are
only interested in the first one, so use it and ignore the second
one, as in:

CL-USER 3 > (pprint (round 5.5))

6

Regards,
--
Nils Goesche
"Don't ask for whom the <CTRL-G> tolls."

PGP key ID 0x42B32FC9

pizza

unread,
May 23, 2002, 4:28:29 PM5/23/02
to
>
> when I enter (round 5.5)
>
> lisp spits out:
> 6 ;
> -.1000000000000000000000f0
>
> How do I just get lisp to return the rounded number without all that
> junk?
>
> Thanks
> -Samantha

I get something similiar interactively:

[42]> (round 5.5)
6 ;
-0.5
[43]> (setf r (round 5.5))
6
[44]> r
6

...assigning to a variable seems to get rid of the extraneous data. i'm
using GNU CLISP 2.28 if it matters. keep in mind i'm a newb too... this may
be a case of the blind leading the blind :)

love,

pizza

Posted Via Usenet.com Premium Usenet Newsgroup Services
----------------------------------------------------------
** SPEED ** RETENTION ** COMPLETION ** ANONYMITY **
----------------------------------------------------------
http://www.usenet.com

Kaz Kylheku

unread,
May 23, 2002, 4:31:20 PM5/23/02
to
On 23 May 2002 13:09:17 -0700, Samantha Skyler

<samanth...@hotmail.com> wrote:
>OK.....
>
>I want to round a numnber
>
>when I enter (round 5.5)
>
>lisp spits out:
>6 ;
>-.1000000000000000000000f0

That seems strange; I would expect

6 ;
-0.5

This indicates that the expression returned two values rather than just one.
Lisp expressions can do that. Multiple values are a special datapath only for
returning values; they are not a data type like vector or list.

You can ignore the extra values, in which case the first value will be taken.
For example:

(print (round 5.5))

will pass the value 6 to the print function, and ignore the -0.5.

When your interactive read-eval-print loop intercepts a multiple value from
an evaluated form, it will print all of the values, which is what you
are seeing.

Lisp has a few special forms for creating multiple values and for intercepting
and separating them. The values function creates a multiple value:

(defun return-two-values () (values 10 20))

A values expression with no arguments, in other words (values), is the Lisp
idiom for making an expression return nothing at all, which is a useful
thing to do in expressions that are evaluated for side effects only,
and which otherwise have nothing to report to the calling environment.

The multiple-value-bind special form can be used to bind variables to the
elements of a multiple value:

(multiple-value-bind (one two) (return-two-values)
(format t "one = ~a~%" one)
(format t "two = ~a~%" two))

There are other functions and forms related to multiple values; look them
up in the HyperSpec.

Erann Gat

unread,
May 23, 2002, 4:37:12 PM5/23/02
to
In article <pan.2002.05.23.20...@parseerror.com>, pizza
<pi...@parseerror.com> wrote:

> >
> > when I enter (round 5.5)
> >
> > lisp spits out:
> > 6 ;
> > -.1000000000000000000000f0
> >
> > How do I just get lisp to return the rounded number without all that
> > junk?
> >
> > Thanks
> > -Samantha
>
> I get something similiar interactively:
>
> [42]> (round 5.5)
> 6 ;
> -0.5
> [43]> (setf r (round 5.5))
> 6
> [44]> r
> 6
>
> ...assigning to a variable seems to get rid of the extraneous data. i'm
> using GNU CLISP 2.28 if it matters. keep in mind i'm a newb too... this may
> be a case of the blind leading the blind :)

More like a blind person beginning to see. :-)

This isn't "extraneous" data. Lisp functions can return more than one
value. In many cases (like variable assignment) only the first value is
used and the additional values are discarded.

It's also a good idea to RTFM and STFW. In the case of CL the FM is on
the FW. :-) You can find it here:

http://www.xanalys.com/software_tools/reference/HyperSpec/Front/index.htm

And the answer to your question can be found here:

http://www.xanalys.com/software_tools/reference/HyperSpec/Body/f_floorc.htm

E.

Erik Naggum

unread,
May 23, 2002, 5:31:56 PM5/23/02
to
* Samantha Skyler

| How do I just get lisp to return the rounded number without all that junk?

Common Lisp supports multiple return values. However, only the primary
value is used in expressions that do not explicitly cater to multiple
values. The function `values' may return multiple values, but it may
also be used to return only one:

(values 1 2 3)
=> 1
=> 2
=> 3

How the additional values are printed varies from implementation to
implementation. I prefer the above, and have programmed my Common Lisp
system to print multiple return values that way, but your semicolon-
separated list is just another way to do it. E.g.,

(round 5.9)
=> 6
=> -0.09999999999999964

Consequently,

(values (round 5.9))
=> 6

I think it is time for you to read up on this language and not just play
with an implementation -- this is fairly basic stuff that should have
been covered in any reasonable tutorial material. Which textbooks or
other tutorials are you currently using that are confusing you? In any
case, I recommend the actual specification as it is quite readable and
lets you in on the lexicon of this community, too. Start at www.lisp.org
and look for the HyperSpec. Depending on your preferred learning mode, a
standard like this may or may not be ideal for you, but familiarity with
the authoritative reference on Common Lisp is a must sooner or later. I
predict you will find much joy in seeing how this language is specified.
It is a whole different world from the mostly underspecified languagees
that you learn by trial and error. That, too, is a cultural difference
that is worth appreciating.
--
In a fight against something, the fight has value, victory has none.
In a fight for something, the fight is a loss, victory merely relief.

70 percent of American adults do not understand the scientific process.

Kenny Tilton

unread,
May 23, 2002, 9:45:48 PM5/23/02
to

Erik Naggum wrote:
> I think it is time for you to read up on this language and not just play
> with an implementation --

Nonsense. Mind-numbing, counter-Lisp-spirit, homework-giving nonsense.

> ...this is fairly basic stuff that should have


> been covered in any reasonable tutorial material. Which textbooks or
> other tutorials are you currently using that are confusing you? In any
> case, I recommend the actual specification as it is quite readable and
> lets you in on the lexicon of this community, too. Start at www.lisp.org
> and look for the HyperSpec.

I have had it with this c.l.l. drumbeat from several
schoolmarm-lets-make-learning-miserable types of "turn off your listener
prompt and start reading page after page without knowing what you are
looking for or why you are doing it".

It is too bad some people do not like playing, but playing is fun and
one of the really big things Lisp has going for it is that one can just
dig up a command-line and explore. Thems who say "go find a book when
you have a question" are enemies of the Lisp spirit, pure and simple.

Take that sadistic, study-till-dawn crap somewhere else. The ability to
inetractively ask a function what it does by kicking it off in the
listener is one of our huge advantages over C/C++/Java -- great, you
just threw it away.

> Depending on your preferred learning mode, ...

Oh my god, we now tolerate preferred learning modes? Apparently only as
long as the preferred learning mode is to read a thousand pages before
posting an innocent question on c.l.l.

The next person to tell a newbie to go read the HyperSpec will be
summarily shot.

--

kenny tilton
clinisys, inc
---------------------------------------------------------------
"Harvey has overcome not only time and space but any objections."
Elwood P. Dowd

Kenny Tilton

unread,
May 23, 2002, 9:55:15 PM5/23/02
to

Good news. It does. It's just that ROUND happens to return two values,
and when you kick these things off at a command line by default all the
returned values are displayed (since the command line has no idea in
which value you are interested).

In a program, you need not bother with this unless you care about the
extra value. Even at the command line you can do:

(+ 1 (round 5.5)) and get 7, as if the only value returned were 6

If you want to get fancier, (multiple-value-bind (rounded
rounding-delta) (round 5.5) <whatever with rounding-delta>) lets you
capture the other value returned by round and have fun with it.

Note that you can do what ROUND does using the VALUES form. Look it up.
:)

Marc Spitzer

unread,
May 23, 2002, 10:50:34 PM5/23/02
to
In article <3CED9D0C...@nyc.rr.com>, Kenny Tilton wrote:
>
>
> Erik Naggum wrote:
>> I think it is time for you to read up on this language and not just play
>> with an implementation --
>
> Nonsense. Mind-numbing, counter-Lisp-spirit, homework-giving nonsense.
>

What is counter-Lisp-spirit about putting in the effort to learn how
to play with your toys, there is just a *lot* more to learn if you
want to play with common lisp. And homework is useful and productive
exercise, here is a problem that you can solve with what you know now
so go do it. Think how hard it would be to get a degree BA or PHD if
it was just deliver a final project.

>> ...this is fairly basic stuff that should have
>> been covered in any reasonable tutorial material. Which textbooks or
>> other tutorials are you currently using that are confusing you? In any
>> case, I recommend the actual specification as it is quite readable and
>> lets you in on the lexicon of this community, too. Start at www.lisp.org
>> and look for the HyperSpec.
>
> I have had it with this c.l.l. drumbeat from several
> schoolmarm-lets-make-learning-miserable types of "turn off your listener
> prompt and start reading page after page without knowing what you are
> looking for or why you are doing it".
>

Learning is hard work. I enjoy it a lot, but it still is hard work.
And if someone posts a question that is answered in the docs they
should be directed to the part of the documentation that applies.
Learning to use the hyperspec is a large part of learning *how* to
learn CL productively. And if you just want to play fine, but why
should do your work for you.

> It is too bad some people do not like playing, but playing is fun and
> one of the really big things Lisp has going for it is that one can just
> dig up a command-line and explore. Thems who say "go find a book when
> you have a question" are enemies of the Lisp spirit, pure and simple.
>

Well most other popular languages have no standard so you go to your
compiler or interpreter type in some code and see what it does. I
personally prefer the CL way, read the standard because this is how CL
shall act. This is much less work, especialy after 3 or 4 times to
get used to the system. You do not have to discover how things work
you just do some reading, much faster and easier to do.

> Take that sadistic, study-till-dawn crap somewhere else. The ability to
> inetractively ask a function what it does by kicking it off in the
> listener is one of our huge advantages over C/C++/Java -- great, you
> just threw it away.
>

yes it is, but it is more of a reference thing not a learning thing.
I mean that after you have some idea of why the convienence of looking
up how is great. But good books and tutorials for beginners should
focuse on why with enough how thrown in to enable you to play with the
problem. The why is what is cool, fun and profitable. just doing how
makes you borring and trains you to be a hack.

>> Depending on your preferred learning mode, ...
>
> Oh my god, we now tolerate preferred learning modes? Apparently only as
> long as the preferred learning mode is to read a thousand pages before
> posting an innocent question on c.l.l.

Did you ever hear the "teach a man to fish story", you know eat for a
day vs eat forever? And you do not have to read the whole thing at 1
sitting to benifit. If you have a question about a function go read
the spec to find out how it work thewn go back to what you were doing
before.

>
> The next person to tell a newbie to go read the HyperSpec will be
> summarily shot.
>

Well that is quite a stupid thing to say. You are telling people not
to give people good advice just because they would have to work a
little to get the benifit of that advice.

marc

Bulent Murtezaoglu

unread,
May 23, 2002, 11:06:59 PM5/23/02
to
>>>>> "KT" == Kenny Tilton <kti...@nyc.rr.com> writes:

KT> Erik Naggum wrote:
>> I think it is time for you to read up on this language and not
>> just play with an implementation --

KT> Nonsense. Mind-numbing, counter-Lisp-spirit, homework-giving
KT> nonsense.

Erik certainly doesn't need my help but you are taking issue with
good advice tactfully delivered.

>> ...this is fairly basic stuff that should have been covered in
>> any reasonable tutorial material. Which textbooks or other
>> tutorials are you currently using that are confusing you? In
>> any case, I recommend the actual specification as it is quite
>> readable and lets you in on the lexicon of this community, too.
>> Start at www.lisp.org and look for the HyperSpec.

KT> I have had it with this c.l.l. drumbeat from several
KT> schoolmarm-lets-make-learning-miserable types of "turn off
KT> your listener prompt and start reading page after page without
KT> knowing what you are looking for or why you are doing it".

This is not what's been said. It doesn't hurt to have the hyperspec handy
_while_ playing. I do it, you probably do it, nothing whatsoever wrong
with it at all. Good habit to get into. As for finding out about
functions returning multiple values, _of course_ tutorial material will
be recommended to beginners who make it clear they do not know this.
There is no misery involved, nobody is going to be miserable because they
find out functions return multiple values when they read this in a book.
You are attacking a straw man that you are creating it seems. The attitude
you are going off against is not present in the paragraph you have quoted.

KT> It is too bad some people do not like playing, but playing is
KT> fun and one of the really big things Lisp has going for it is
KT> that one can just dig up a command-line and explore. Thems who
KT> say "go find a book when you have a question" are enemies of
KT> the Lisp spirit, pure and simple.

Is this April 1st? What happened was: a couple of people who are calling
themselves newbies asked a reasonable question, they got the answer to
their question and they were given good advice on how to grow out of their
newbieness. I do not believe that you yourself would have just given
them the response w/o giving them good advice on making their studies
easier.

KT> Take that sadistic, study-till-dawn crap somewhere else. The
KT> ability to inetractively ask a function what it does by
KT> kicking it off in the listener is one of our huge advantages
KT> over C/C++/Java -- great, you just threw it away.

No he did not, he just pointed out that after some minimal reading
experimentation would produce less puzzlement. Oh BTW, one thing the
Hyperspec is great for is what the C/C++/Java visual tools people use
every day, the ability to pull up the documentation of the built-in
functions/classes as one's coding.

[...]

KT> The next person to tell a newbie to go read the HyperSpec will
KT> be summarily shot.

Oh dear. I am tempted to say it but no I don't believe newbies should
_read_ the Hyperspec. Will I still qualify if I just suggest they should
learn to refer to it?

cheers,

BM

Kenny Tilton

unread,
May 24, 2002, 4:13:43 AM5/24/02
to

Bulent Murtezaoglu wrote:
>
> KT> The next person to tell a newbie to go read the HyperSpec will
> KT> be summarily shot.
>
> Oh dear. I am tempted to say it but no I don't believe newbies should
> _read_ the Hyperspec. Will I still qualify if I just suggest they should
> learn to refer to it?

No bullet for you. That is how references should be used.

Tellingly, however, the h/s entry on ROUND would have done the latest
newbie no good at all. Her problem was with how the REPL handled
multiple values (and the mvs themselves I wager), and the h/s simply
shows them being returned, leaving her with the same question.

Look, for all we know the newbie was working their way thru the h/s
function by function trying them at random, when they came across one
with multiple values. So they hop on c.l.l. and receive advice to read
the h/s cover-to-cover so they can catch all the details. Makes the
language look unapproachable when it is just the opposite.

This "read-before-you-type" obsession has manifested itself in other
ways. recently a veteran ended up throwing themselves on a sword because
something they asserted was not supported by the h/s (the behavior was
in fact undefined or something obscure). the sin for which they perished
was not having fact-checked every sentence against the h/s before
posting.

Rubbish! This is UseNet, not air traffic control. c.l.l. needs to relax.

:)

Nicolas Neuss

unread,
May 24, 2002, 7:36:37 AM5/24/02
to
Kenny Tilton <kti...@nyc.rr.com> writes:

> ...


>
> Rubbish! This is UseNet, not air traffic control. c.l.l. needs to relax.

Nevertheless, we (at least myself, I don't know about you) don't have
the resources to teach every newbie Lisp at the level of explaining
the repl with multiple values. Therefore, I'm with Erik and find it
mandatory that newbies are answered such questions, but with a
reference to textbooks, the Hyperspec or other resources like
e.g. ELMART

http://www.psychologie.uni-trier.de:8000/elmart

or

http://www.alu.org/table/learn.htm

(Actually reading the Hyperspec is not the first thing to do, this is
good only for newbies who do not ask such questions anyhow. But Erik
didn't really suggest it as first step either.)

Nicolas.

0 new messages