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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T09:38:34+00:00 2026-06-03T09:38:34+00:00

(define l ‘(* – + 4)) (define (operator? x) (or (equal? ‘+ x) (equal?

  • 0
(define l '(* - + 4))

(define (operator? x)
    (or (equal? '+ x) (equal? '- x) (equal? '* x) (equal? '/ x)))

(define (tokes list)
  (if (null? list)(write "empty")
  (if (operator? (car list))

       ((write "operator")
        (tokes (cdr list)))

      (write "other"))))

The code works just fine til (tokes (cdr list))) reaches the end of file. Can someone give me a tip in how I can prevent that. I’m new at Scheme so I’m forgive me if the question is absurd.

  • 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-03T09:38:35+00:00Added an answer on June 3, 2026 at 9:38 am

    You must make sure of advancing the recursion on each case (except the base case, when the list is null). In your code you’re not making a recursive call for the (write "other") case. Also, you should use cond when there are several conditions to test, Let me explain with an example – instead of this:

    (if condition1
        exp1
        (if condition2
            exp2
            (if condition3
                exp3
                exp4)))
    

    Better write this, is much more readable and has the added benefit that you can write more than one expression after each condition without the need to use a begin form:

    (cond (condition1 exp1) ; you can write additional expressions after exp1
          (condition2 exp2) ; you can write additional expressions after exp2
          (condition3 exp3) ; you can write additional expressions after exp3
          (else exp4))      ; you can write additional expressions after exp4
    

    … Which leads me to the next point, be aware that you can write only one expression for each branch of an if, if more than one expression is needed for a given condition in an if form then you must surround them with a begin, for example:

    (if condition
        ; if the condition is true
        (begin  ; if more than one expression is needed 
          exp1  ; surround them with a begin
          exp2) 
        ; if the condition is false
        (begin  ; if more than one expression is needed 
          exp3  ; surround them with a begin
          exp4))
    

    Going back to your question – here’s the general idea, fill-in the blanks:

    (define (tokes list)
      (cond ((null? list)
             (write "empty"))
            ((operator? (car list))
             (write "operator")
             <???>)   ; advance on the recursion
            (else
             (write "other")
             <???>))) ; advance on the recursion
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

(define (lcs lst1 lst2) (define (except-last-pair list) (if (pair? (cdr list)) (cons (car list)
(define pick (lambda (num lat) (cond ((null? lat) (quote())) ((= (sub1 num) 0) (car
(define sp (lambda (l) (if (null? l) '(0 1) (let ((v (sp (cdr l))))
(define cart-product (lambda (sos1 sos2) (if (null? sos1) '() (cons (cart-prod-sexpr (car sos1) sos2)
(define str '(3 + 3)) (define list '(3 + 4)) (define (tokes str) (case
code: #define f(a,b) a##b #define g(a) #a #define h(a) g(a) main() { printf(%s\n,h(f(1,2))); //[case
Define a function replicate which given a list of numbers returns a list with
#define __T(x) L ## x Found in code from one of the MFC source
#define cimg_use_jpeg 2 #ifndef cimg_use_jpeg //code goes here #endif I really don't understand...
Define a list dats with two dataframes, df1 and df2 dats <- list( df1

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.