This is a read-only archive of lispforum.com. The forum was locked to new users and posts and is preserved here as static HTML from a database snapshot taken on 2019-09-07.

How to fix an unbound variable error in scheme?

4 posts · 8463 views

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:
(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?

Where is your cat defined?
It's obvious it has no definition, or?

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

(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?

I guess you no longer get the unbound variabel error if you evaluated the definition of cat?
I'm the author of two useless languages that uses BF as target machine.
Currently I'm planning a Scheme compiler :p