yulai
yulai

Reputation: 761

Scheme: Arrow -> What does it mean?

I'm taking a functional programming course, using the book SICP as reference. Several places in the book, I have come across the use of '->' arrows in procedure definitions.

Examples:

(define (segments->painter segment-list)
    (lambda ...

(define (tree->list tree)
    (if (...

(define (scheme-number->complex n)
    (make-complex-from-real ...

So, what does the '->' arrow mean? Is it a naming convention to indicate that the procedure transforms one thing into another; such as tree-into-list? If not; what does the arrow represent?

Thanks!

Upvotes: 2

Views: 3362

Answers (2)

soegaard
soegaard

Reputation: 31145

As @sepp2k mentions -> is part of the name and doesn't mean anything in it self. The convention is to use -> in names for "conversion" (used loosely) functions. The function string->list has a string as input and produces a list of characters.

In most cases you can pronounce -> as "to". That is string->list is pronounced "string to list" if you were to read code aloud.

Upvotes: 5

sepp2k
sepp2k

Reputation: 370367

Is it a naming convention to indicate that the procedure transforms one thing into another; such as tree-into-list?

Exactly.

Upvotes: 4

Related Questions