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 6080045
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T11:01:02+00:00 2026-05-23T11:01:02+00:00

Here’s a library which exports a hashtable. The library also contains expressions which populate

  • 0

Here’s a library which exports a hashtable. The library also contains expressions which populate the hashtable:

(library (abc-1)

  (export tbl)

  (import (rnrs))

  (define tbl (make-eq-hashtable))

  (hashtable-set! tbl 'a 10)
  (hashtable-set! tbl 'b 20)
  (hashtable-set! tbl 'c 30))

Here’s another version of the library which exports a procedure which can be used to populate the hashtable:

(library (abc-2)

  (export tbl init-tbl)

  (import (rnrs))

  (define tbl (make-eq-hashtable))

  (define (init-tbl)
    (hashtable-set! tbl 'a 10)
    (hashtable-set! tbl 'b 20)
    (hashtable-set! tbl 'c 30)))

Is it considered bad form to take the first approach? I.e. to have a library which also executes arbitrary expressions? Are there drawbacks to this approach?

A related issue… In a library, non-definition expressions must occur after definitions. To work around this constraint, I’m using this macro:

  (define-syntax no-op-def
    (syntax-rules ()
      ((_ expr ...)
       (define no-op
         (begin
           expr
           ...)))))

for example:

(define t0 (make-eq-hashtable))

(no-op-def
  (hashtable-set! t0 'a 10))

(define t1 (make-eq-hashtable))

(no-op-def
  (hashtable-set! t1 'b 20))

Again, are there drawbacks to interspersing expressions and definitions via this workaround?

  • 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-23T11:01:03+00:00Added an answer on May 23, 2026 at 11:01 am

    There are no big problems with either of these. Maybe change no-op to dummy to clarify that it’s a binding that is never used.

    The only possible issue with toplevel side-effect expressions is that in some implementations they might not be executed when you think they should. R6RS allows “implicit phasing”, which means that you just import some library and the language gets it into the correct phase depending on where its identifiers are used. So, in such an implementation (eg, Ikarus), if you just import a library but not use its identifiers, the library wouldn’t be instantiated — so a library that is simply used to print some stuff when it’s imported will not do so unless it’s also exporting some binding, and the importing side is mentioning that binding somewhere.

    But that won’t be an issue in your case.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Here is my code, which takes two version identifiers in the form 1, 5,
Here's the link: www.mchenry.edu/maps/google.asp Why won't the location balloon display correctly? Also, the pop-up
Here a simple question : What do you think of code which use try
Here is an example: I have a file 1.js, which has some functions. I
Here's a basic regex technique that I've never managed to remember. Let's say I'm
Here's a problem I ran into recently. I have attributes strings of the form
Here is the issue I am having: I have a large query that needs
Here's my scenario - I have an SSIS job that depends on another prior
Here is a simplification of my database: Table: Property Fields: ID, Address Table: Quote
Here's a coding problem for those that like this kind of thing. Let's see

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.