Selectors in Scheme R6RS

438 Views Asked by At

I'm reading a old book

Simply Scheme: Introducing Computer Science

you can find it here .

In the fifth section it introduces the "selectors", operators like the following:

(first 'abcd) ;-> A
(butfirst 'abcd) ;-> BCD

and so on..

Does it exist something similar in R6RS? (since this operators are not defined).

1

There are 1 best solutions below

0
leppie On BEST ANSWER

As per my comment, this will probably be quite difficult.

Another aspect is that Simply Scheme sees symbols as 'strings'.

With that info you could write the following:

(define (first s)
  (string->symbol (string (car (string->list (symbol->string s))))))

(define (butfirst s)
  (string->symbol (apply string (cdr (string->list (symbol->string s))))))

Also note that symbols are case-sensitive in R6RS, so the result will be the same case case passed to the procedure.