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

  • SEARCH
  • Home
  • 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 9248281
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 18, 20262026-06-18T09:54:38+00:00 2026-06-18T09:54:38+00:00

I defined a function true? for use with count in racket/list. (define (true? expr)

  • 0

I defined a function true? for use with count in racket/list.

(define (true? expr)
  (and (boolean? expr) expr #t))

I noticed I could provide it numeric arguments and my function would happily return #f.

> (true? 6)
#f

So, I thought I would explore using a racket contract to make non-boolean arguments return an error in contract violation. So I put this code at the tope of my file:

(provide (contract-out
          [true?         (-> boolean? boolean?)]))

However, after adding the contract I still get the same behavior as above in the racket REPL. I don’t understand how that could be. What am I missing?

  • 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-06-18T09:54:40+00:00Added an answer on June 18, 2026 at 9:54 am

    Contracts are usually enforced between modules. So you would have to try it from the outside perspective. The REPL, however, applies from inside the module you’re working in.

    An easy way to test from the outside is to use a test submodule. For example:

    #lang racket
    
    (define (true? expr)
      (and (boolean? expr) expr #t))
    
    (provide (contract-out
              [true?         (-> boolean? boolean?)]))   
    
    (module* test racket/base
      (require (submod "..")
               rackunit)
      (check-true (true? #t))
      (check-false (true? #f))
      (check-exn exn:fail:contract? (lambda () (true? 3))))
    

    Change the contracts and re-run in DrRacket, and you should see your contracts in effect here, since the test module here is being treated as an external customer of the contract.


    Alternatively, make another file that requires the first, and then you can see the effect of contracts there too. If the first file is called true-test.rkt, then you can make another module, and then:

     #lang racket
     (require "true-test.rkt")
     (true? 42)  ;; And _this_ should also raise a contract error.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

What does return true; and return false; exactly responds in user defined functions? function
Super short version: I'm trying to use a user-defined function to populate a new
I have been trying to use the row count function which is part of
User Defined Function (UDFs) are functions that one can program and can be dynamically
I have this self-defined function in my .bashrc : function ord() { printf '%d'
I have this user defined function. public partial class UserDefinedFunctions { static int i;
Why calling a user defined function need the owner name when calling a stored
I have a User Defined Function (UDF) written in Java to parse lines in
I have the following object defined function BusinessUnit(id, name, code) { this.id = ko.observable(id);
I am trying to call a user defined function in jQuery: $(document).ready(function() { $('#btnSun').click(function()

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.