1

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

Aslan986
  • 9,984
  • 11
  • 44
  • 75
  • 1
    You will need to port the Simply Scheme preamble which is not compatible with R6RS. I am not even sure it is possible as it uses 'funny' constructs. – leppie Aug 18 '12 at 10:04
  • 1
    This question was asked before on SO. See [here](http://stackoverflow.com/questions/11593429/is-everything-a-list-in-scheme). If you want to learn standard Scheme, Simply Scheme is probably not the best book to read. – Asumu Takikawa Aug 18 '12 at 16:52

1 Answers1

3

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.

leppie
  • 115,091
  • 17
  • 196
  • 297