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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T02:37:46+00:00 2026-05-19T02:37:46+00:00

I am developing a custom LISP interpreter. It won’t support defining functions like in

  • 0

I am developing a custom LISP interpreter. It won’t support defining functions like in LISP, instead all functions are mapped to C functions. When it sees an expression like,

(substr 'input '1 '1)

it knows to call internal substr function and return the result.

Now I am planning to implement a message function which supports basic formatting and writes the output to stdout. Something like,

(message "Hello, %s" name)

%s will be replaced with value in variable name.

Current plan is to directly pass the format and arguments to functions like printf. In that way, I can support all formats that printf supports. But problem comes with variable number of arguments. One way to do will be something like,

if(argcount == 1)
   /* call printf with one arg */
else if(argcount == 2)
   /* call printf with two arg */
....

This works, but I am wondering is there a better way to achieve this?

  • 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-19T02:37:47+00:00Added an answer on May 19, 2026 at 2:37 am

    I doubt there is a way to do this. The reason is that the number of parameters to your lisp function is only known at runtime, but the number of arguments to a C function must be known at compile time.

    This includes va_lists unless you want to hack at them in some kind of platform specific way.

    The best you can really do is write a function in C which is capable of looping through the arguments one at a time and doing something with them. The only way I can see around this is to not only store a function pointer for each of your internal functions, but to also store a “calling convention” which will give information about whether it takes parameters in the ordinary way or whether it finishes with the equivalent of a va_list.

    Functions like printf would have a wrapper, printf_wrapper, say, and you’d store a function pointer to the wrapper. This wrapper would accept the format string as an ordinary parameter, followed by a list or array of other parameters (roughly analogous to a va_list).

    You might indicate that printf_wrapper finishes with a parameter that expects a list by specifying the calling conventions for the printf_wrapper function as “va_list_type”, meaning that it takes the usual fixed parameters, and that all remaining parameters must be bundled up and supplied to it as a list.

    Of course writing a printf_wrapper function which can split up and parse a format string into multiple format strings is a bit of work. Here’s an example of where I did precisely this so that I could add my own custom format specifiers:

    https://github.com/wbhart/bsdnt/blob/v0.26/helper.c

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

Sidebar

Related Questions

I'm developing custom Agent for LotusNotes 8.5. I'd like to use iCal4j jar to
I'm developing a custom DataGridView control for internal use and I'd like to add
Does anyone have any good links for developing custom field and content types that
I am developing a custom control derived from System.Windows.Controls.ContentControl. In the controls default template
H guys. I'm developing a custom component for SSIS. I'm having a problem when
Is it necessary or advantageous to write custom connection pooling code when developing applications
I'm developing a client/server app that will communicate via rest. Some custom request data
I am developing an application for PocketPC. When the application starts the custom function
I'm developing custom client/server application that requires client to log in with their username
My company has recently started developing custom iPhone applications for various clients. One of

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.