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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:48:54+00:00 2026-06-11T22:48:54+00:00

Just to understand how the Scheme macros work i’m trying to define a new

  • 0

Just to understand how the Scheme macros work i’m trying to define a new command, sum that works exactly like the common operator + (i.e. also undefined number of parameters).

I wroter this code:

(define-syntax sum
  (syntax-rules ()
    ((_ arg1 arg2 args...)
     (sum (+ arg1 arg2) args...))
    ((_ arg1 arg2)
     (+ arg1 arg2))
    ((_ arg1)
     arg1)))

It works if i pass it 1, 2 or 3 arguments. But with 4 arguments i get this error:

sum: bad syntax in: (sum 1 2 3 4)

I tried to expand the macro step-by-step with DrRacket but it stops immediately.

Can someone explain me the cause of this error?

  • 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-11T22:48:55+00:00Added an answer on June 11, 2026 at 10:48 pm

    In Scheme, ... is just another identifier, so you need a space between args and the ellipses (...) in both places, like this:

    (define-syntax sum
      (syntax-rules ()
        ((_ arg1 arg2 args ...)
         (sum (+ arg1 arg2) args ...))
         ___etc___))
    

    BTW, you don’t need to create macros in order to accept arbitrary numbers of arguments. You can also use “rest args”:

    (define (sum . args)
      ;; args is bound to a list of all the arguments
      (foldl + 0 args))
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just trying to understand that - I have never used it before. How is
I just can't understand why is my database (mysql) behaving like this! My console
Am just trying to understand why this exception throws. Cannot implicitly convert type 'System.DateTime?'
I was just trying to understand delegates using the following code. public class delegatesEx
I am just trying to understand the extends keyword in Java Generics. List<? extends
I've been learning scheme, and I just realized that I don't really know how
I know that this has been discussed lot of times. I just can't understand
My DBA just lost some development work that he did on our development database.
I'm just started learning scheme and can't quite understand why this function does not
I'm trying to learn how to use match in scheme. I sort of understand

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.