Trying to count number of variables in Scheme list

Posted on 2011-04-24
Last Modified: 2012-06-27
This is the code I have so far, I am trying to implement code from a previous question.
This is the error I am getting, procedure application: expected procedure, given: 1 (no arguments)
I don't think my counter is correct.

(define (countrepeat lst)
  (count((1) (lst)))


(define (count s lst)
    ((null? list) '())
    ((null? (cdr lst)) '())
    ((equal? (car lst)(car(cdr lst))) (count(+1 cdr lst)))
    (else (list s(list(car lst))))

Open in new window

Question by:TechLearnerCA
    LVL 37

    Expert Comment

    Shouldn't it be count(s+1 cdr lst) on line 15?
    LVL 37

    Expert Comment

    Your else looks really weird too. Don't you just want to call  count(1 cdr lst) ?
    LVL 24

    Accepted Solution

    As I understand you want to count the elements in the list
    Why are you using a list as first parameter?
    Why are you having the equal test which just checks the elements which are behind each other.

    Either you want to just count the elements of a certain kind in your list or in the context of your other question you are just counting certain elements in that list. Anyways this code does neihter of it.

    If you want to count the number of adjacent elements you have to keep track of the elements which are supposed to be adjacent.

    You other question suggests that you have a list like
    '(a a b b c c) etc and that you want  to collect the numbers of symbols as long as they are equal
    So then you have to stop differently.

    (define (counter element ctr lst)
      (let ((first-element (unless (null? lst) (car lst))))
          ((null? lst) ctr)
          ((not (equal? element first-element))
           (counter element (1+ ctr) (cdr lst))))))
    (counter 'a 0 '(a a a b c))

    Open in new window

    LVL 53

    Expert Comment

    This question has been classified as abandoned and is closed as part of the Cleanup Program. See the recommendation for more details.

    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    tripleUp challenge 7 54
    Excel object stays open 19 56
    triangle challenge 4 36
    array11 challenge 16 40
    This article is meant to give a basic understanding of how to use R Sweave as a way to merge LaTeX and R code seamlessly into one presentable document.
    This is an explanation of a simple data model to help parse a JSON feed
    An introduction to basic programming syntax in Java by creating a simple program. Viewers can follow the tutorial as they create their first class in Java. Definitions and explanations about each element are given to help prepare viewers for future …
    In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    6 Experts available now in Live!

    Get 1:1 Help Now