• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 459
  • Last Modified:

Trying to count number of variables in Scheme list

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)
  (cond
    
    ((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

0
TechLearnerCA
Asked:
TechLearnerCA
  • 2
1 Solution
 
TommySzalapskiCommented:
Shouldn't it be count(s+1 cdr lst) on line 15?
0
 
TommySzalapskiCommented:
Your else looks really weird too. Don't you just want to call  count(1 cdr lst) ?
0
 
fridomCommented:
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))))
    (cond 
      ((null? lst) ctr)
      ((not (equal? element first-element))
       ctr)
      (else
       (counter element (1+ ctr) (cdr lst))))))
            


(counter 'a 0 '(a a a b c))

Open in new window

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

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now