How to fix an unbound variable error in scheme?

Discussion of Scheme and Racket
Post Reply
vitomzev
Posts: 3
Joined: Tue Nov 07, 2017 12:56 am

How to fix an unbound variable error in scheme?

Post by vitomzev » Tue Nov 07, 2017 1:00 am

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

gekkonier
Posts: 19
Joined: Tue Jan 17, 2017 6:57 am

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

Post by gekkonier » Fri Nov 10, 2017 6:11 am

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

vitomzev
Posts: 3
Joined: Tue Nov 07, 2017 12:56 am

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

Post by vitomzev » Sat Nov 11, 2017 3:11 am

(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

sylwester
Posts: 133
Joined: Mon Jul 11, 2011 2:53 pm

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

Post by sylwester » Thu Nov 16, 2017 2:32 pm

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

Post Reply