Account Options

  1. Sign in
The old Google Groups will be going away soon, but your browser is incompatible with the new version.
Google Groups Home
« Groups Home
type: (or something nil)
There are currently too many topics in this group that display first. To make this topic appear first, remove this option from another topic.
There was an error processing your request. Please try again.
flag
  7 messages - Collapse all  -  Translate all to Translated (View all originals)
The group you are posting to is a Usenet group. Messages posted to this group will make your email address visible to anyone on the Internet.
Your reply message has not been sent.
Your post was successful
 
From:
To:
Cc:
Followup To:
Add Cc | Add Followup-to | Edit Subject
Subject:
Validation:
For verification purposes please type the characters you see in the picture below or the numbers you hear by clicking the accessibility icon. Listen and type the numbers you hear
 
Erik Naggum  
View profile  
 More options Mar 6 1998, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <cle...@naggum.no>
Date: 1998/03/06
Subject: Re: type: (or something nil)

* Sam Steingold <s...@usa.net>
| 1. Is this desire politically correct?

  well, you wouldn't get a complaint from me.  that's why NIL is there.

| 2. If it is, there should be a way to declare the variable's type.
| How do I do that?  

(or <whatever> null)

  note that this won't buy you anything.  you need to declare the type of
  the object _after_ you have determined that it is not NIL to get any
  performance benefits from the declarations.

| Also, do I understand correctly that my ANSI CL proposal about
|       (define-format-command #\= (lambda (stream obj atp colp &rest pars)))
| is dead?

  looks like it.

#:Erik
--
  God grant me serenity to accept the code I cannot change,
  courage to change the code I can, and wisdom to know the difference.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Raymond Toy  
View profile  
 More options Mar 6 1998, 3:00 am
Newsgroups: comp.lang.lisp
From: Raymond Toy <t...@rtp.ericsson.se>
Date: 1998/03/06
Subject: Re: type: (or something nil)

Erik Naggum <cle...@naggum.no> writes:

> (or <whatever> null)

>   note that this won't buy you anything.  you need to declare the type of
>   the object _after_ you have determined that it is not NIL to get any
>   performance benefits from the declarations.

Depends on the compiler and the code.  This bit of code:

(defun tst (x)
  (declare (type (or single-float null) x) (optimize (speed 3)))
  (if x (sin x)))

can call the C version of sin because the compiler knows that by then,
x must be a single-float.

Ray


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Erik Naggum  
View profile  
 More options Mar 7 1998, 3:00 am
Newsgroups: comp.lang.lisp
From: Erik Naggum <cle...@naggum.no>
Date: 1998/03/07
Subject: Re: type: (or something nil)

* Raymond Toy
| Depends on the compiler and the code.  This bit of code:
|
| (defun tst (x)
|   (declare (type (or single-float null) x) (optimize (speed 3)))
|   (if x (sin x)))
|
| can call the C version of sin because the compiler knows that by then,
| x must be a single-float.

  but does any particular compiler do this?

  (incidentally, C's sin is defined for double-floats.)

#:Erik
--
  God grant me serenity to accept the code I cannot change,
  courage to change the code I can, and wisdom to know the difference.


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
R. Toy  
View profile  
 More options Mar 7 1998, 3:00 am
Newsgroups: comp.lang.lisp
From: "R. Toy" <r...@mindspring.com>
Date: 1998/03/07
Subject: Re: type: (or something nil)

Erik Naggum wrote:

> * Raymond Toy
> | Depends on the compiler and the code.  This bit of code:
> |
> | (defun tst (x)
> |   (declare (type (or single-float null) x) (optimize (speed 3)))
> |   (if x (sin x)))
> |
> | can call the C version of sin because the compiler knows that by then,
> | x must be a single-float.

>   but does any particular compiler do this?

Oops!!!!  I forgot to mention that CMUCL actually does this.  Perhaps
others do to, but CMUCL definitely can.

>   (incidentally, C's sin is defined for double-floats.)

Yes.  CMUCL coerces the single-float to double, calls sin, and coerces
the result back to single-float in this case.

--
---------------------------------------------------------------------------
----> Raymond Toy    r...@mindspring.com
                        http://www.mindspring.com/~rtoy


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Tim Bradshaw  
View profile  
 More options Mar 7 1998, 3:00 am
Newsgroups: comp.lang.lisp
From: Tim Bradshaw <t...@aiai.ed.ac.uk>
Date: 1998/03/07
Subject: Re: type: (or something nil)

* Erik Naggum wrote:
> (or <whatever> null)
>   note that this won't buy you anything.  you need to declare the type of
>   the object _after_ you have determined that it is not NIL to get any
>   performance benefits from the declarations.

Not necessarily -- a compiler should be able to deal with this:

        (declare (type (or my-good-type null) x))
        (and x (do-something-needing-good-type x))

(and cmucl can actually do this kind of inference).

What is perhaps more interesting is that in fact you ought to be able
to deal with things like this

    (defun test-fadd (x y)
      (declare (type (or single-float null) x y))
      (+ x y))

because you know enough about + to be able to insert suitable checks
and then compile good code.  CMUCL makes noises about being able to do
this, although in the one I have (18a, sparc), it seems to have a bug
in this particular case.  The fixnum case works though.

--tim


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
David D. Smith  
View profile  
 More options Mar 7 1998, 3:00 am
Newsgroups: comp.lang.lisp
From: d...@flavors.com (David D. Smith)
Date: 1998/03/07
Subject: Re: type: (or something nil)

In article <3098218620480...@naggum.no>, Erik Naggum <cle...@naggum.no> wrote:
> * Raymond Toy
> | Depends on the compiler and the code.  This bit of code:
> |
> | (defun tst (x)
> |   (declare (type (or single-float null) x) (optimize (speed 3)))
> |   (if x (sin x)))
> |
> | can call the C version of sin because the compiler knows that by then,
> | x must be a single-float.

The compiler would have do some fairly sophisticated type inference to
determine that the argument to SIN was a SINGLE-FLOAT.  Usually one uses:

(defun tst (x)
  (declare (optimize (speed 3)))
  (if x (sin (the single-float x))))

or

(defun tst (x)
  (declare (optimize (speed 3)))
  (if x
    (locally
      (declare (type single-float x))
      (sin x))))


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
Raymond Toy  
View profile  
 More options Mar 7 1998, 3:00 am
Newsgroups: comp.lang.lisp
From: Raymond Toy <t...@rtp.ericsson.se>
Date: 1998/03/07
Subject: Re: type: (or something nil)

Tim Bradshaw <t...@aiai.ed.ac.uk> writes:

> What is perhaps more interesting is that in fact you ought to be able
> to deal with things like this

>     (defun test-fadd (x y)
>       (declare (type (or single-float null) x y))
>       (+ x y))

> because you know enough about + to be able to insert suitable checks
> and then compile good code.  CMUCL makes noises about being able to do
> this, although in the one I have (18a, sparc), it seems to have a bug
> in this particular case.  The fixnum case works though.

Hmm, my sparc version (post 18a development) this produces this, with
(speed 3):

(compile 'test-fadd)
Compiling LAMBDA (X Y):

In: LAMBDA (X Y)
  #'(LAMBDA (X Y)
      (DECLARE (TYPE # X Y) (OPTIMIZE # # #))
      (BLOCK TEST-FADD (+ X Y)))
Note: Doing float to pointer coercion (cost 13) to "<return value>".

And a check of the disassembly shows that it uses fadds to add the two
numbers.  The note is because it has to box up the float so it can
return it.

Ray


 
You must Sign in before you can post messages.
To post a message you must first join this group.
Please update your nickname on the subscription settings page before posting.
You do not have the permission required to post.
End of messages
« Back to Discussions « Newer topic     Older topic »