boot2

Playing with the boostrap
git clone https://git.ryansepassi.com/git/boot2.git
Log | Files | Refs | README

065-string-symbol.scm (1379B)


      1 ; string->symbol interns into the global symtab; symbol->string returns
      2 ; a fresh string copy of the name.
      3 
      4 ; Round-trip a literal.
      5 (define s (string->symbol "hello"))
      6 (if (eq? s 'hello) 0 (sys-exit 1))
      7 
      8 ; Two interns of the same bytes give eq? symbols (interning, not just
      9 ; structural equality).
     10 (if (eq? (string->symbol "abc") (string->symbol "abc")) 0 (sys-exit 2))
     11 
     12 ; Interning a literal matches a quoted symbol.
     13 (if (eq? (string->symbol "foo") 'foo) 0 (sys-exit 3))
     14 
     15 ; symbol->string returns a string with the right bytes.
     16 (define name (symbol->string 'world))
     17 (if (string? name) 0 (sys-exit 4))
     18 (if (not (bytevector? name)) 0 (sys-exit 5))
     19 (if (string=? name "world") 0 (sys-exit 6))
     20 
     21 ; symbol->string returns a *fresh* string: mutating it does not bleed back
     22 ; into the symtab (next conversion still gives "world").
     23 (string-set! name 0 #\X)
     24 (if (string=? (symbol->string 'world) "world") 0 (sys-exit 7))
     25 
     26 ; Round-trip both directions.
     27 (if (eq? 'banana (string->symbol (symbol->string 'banana))) 0 (sys-exit 8))
     28 (if (string=? "banana"
     29               (symbol->string (string->symbol "banana"))) 0 (sys-exit 9))
     30 
     31 ; Empty bytevector interns to a single canonical empty-named symbol.
     32 (define empty-name (string->symbol ""))
     33 (collect-garbage)
     34 (if (eq? empty-name (string->symbol "")) 0 (sys-exit 10))
     35 (if (string=? "" (symbol->string empty-name)) 0 (sys-exit 11))
     36 
     37 (sys-exit 0)