Page 1 of 1

How to fix an unbound variable error in scheme?

PostPosted: Tue Nov 07, 2017 1:00 am
by vitomzev
I have written the following program in scheme which should receive a list of numbers and it should then form the largest number possible from that:

Code: Select all
(define (my-procedure lsts)
  (map (lambda (xs)
         (string->number
          (apply cat(sort xs my-compare))))
       lsts))



and I would like it to behave in the following way: (my-procedure 7 4 43 123) //is entered by me
and the output should be 7443123 for example.

However when I try to compile it, I get the following error: unbound variable "cat"
is there something I missed.
Any help is greatly appreciated
Thanks in advance

Re: How to fix an unbound variable error in scheme?

PostPosted: Fri Nov 10, 2017 6:11 am
by gekkonier
Where is your cat defined?
It's obvious it has no definition, or?

Re: How to fix an unbound variable error in scheme?

PostPosted: Sat Nov 11, 2017 3:11 am
by vitomzev
(define (cat . nums) (apply string-append (map number->string nums)))

(define (my-compare a b) (string>? (cat a b) (cat b a)))

(map (lambda (xs) (string->number (apply cat (sort xs my-compare))))
'((1 34 3 98 9 76 45 4) (54 546 548 60)))

I have changed the code but I would like it to worksuch that I can input the numbers I would like to concatinate

Re: How to fix an unbound variable error in scheme?

PostPosted: Thu Nov 16, 2017 2:32 pm
by sylwester
I guess you no longer get the unbound variabel error if you evaluated the definition of cat?