Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7580599
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:57:29+00:00 2026-05-30T17:57:29+00:00

When I define a function in Common Lisp like this: (defun foo (n) (declare

  • 0

When I define a function in Common Lisp like this:

(defun foo (n)
  (declare (type fixnum n))
  (+ n 42))

I expected a call like (foo "a") to fail right away but it instead fail at the call to +. Is the declare form not guarantees static type checking?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T17:57:30+00:00Added an answer on May 30, 2026 at 5:57 pm

    Type declarations are traditionally meant to be used as guarantees to the compiler for optimization purposes. For type checking, use check-type (but note that it, too, does the checking at run-time, not at compile-time):

    (defun foo (n)
      (check-type n fixnum)
      (+ n 42))
    

    That said, different Common Lisp implementations interpret type declarations differently. SBCL, for example, will treat them as types to be checked if the safety policy setting is high enough.

    In addition, if you want static checking, SBCL is probably your best bet as well, since its type inference engine warns you about any inconsistencies it encounters. To that end, ftype declarations can be put to good use:

    CL-USER(1): (declaim (ftype (function (string) string) bar))
    
    CL-USER(2): (defun foo (n)
                  (declare (type fixnum n))
                  (bar n))
    ; in: DEFUN FOO
    ;     (BAR N)
    ; 
    ; caught WARNING:
    ;   Derived type of N is
    ;     (VALUES FIXNUM &OPTIONAL),
    ;   conflicting with its asserted type
    ;     STRING.
    ;   See also:
    ;     The SBCL Manual, Node "Handling of Types"
    ; 
    ; compilation unit finished
    ;   caught 1 WARNING condition
    
    FOO
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Is this how you define a function in jQuery? $(document).ready( function () { var
In C++, if you define this function in header.hpp void incAndShow() { static int
I like to know how works or what means(?) when you define a function
In C++, the common practice is to declare functions in header files and define
I've done the Graham Common Lisp Chapter 5 Exercise 5, which requires a function
I'm baffled by trying to create the equivalent of this trivial (in Common Lisp)
In SML, it's common and easy to define a function using both currying and
Can I define a function which, when called, inserts new locals into the caller's
I have a small sample function: #define VALUE 0 int test(unsigned char x) {
I am trying to figure out how to define a function that works on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.