Search code examples
schemer6rs

Selectors in Scheme R6RS


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).


Solution

  • 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.