Builtins and Libraries
3.1 Global Utilities
3.2 Numbers
3.3 Strings
3.4 Booleans
3.5 Raw  Array
3.6 Tables
3.7 lists
3.8 sets
3.9 arrays
3.10 string-dict
3.11 option
3.12 pick
3.13 either
3.14 srcloc
3.15 pprint
3.16 s-exp
3.17 s-exp-structs
3.18 image-structs
3.19 image
3.20 world
3.21 gdrive-sheets
3.22 data-source
3.23 reactors
3.24 chart
3.25 plot
3.26 statistics
3.27 math
On this page:
read-s-exp

3.16 s-exp

Usage:
include s-exp
import s-exp as ...

This module re-exports the constructors from S-Exp, which defines the result of parsing an s-exp.

read-s-exp :: (
sexp-str :: String
)

Reads an s-expression as a string, and returns it as a Pyret value.

An s-expression is a string that satisfies the following grammar:

s-exp = "(" s-exp ... ")"

      | <number>

      | <string>

      | <id>

The first form parses to a s-list containing the nested sub-expression results. Numbers become s-nums, strings become s-strs, and all other names not inside quotes become s-syms.

Examples:

import s-exp as S p = S.read-s-exp s-list = S.s-list s-num = S.s-num s-str = S.s-str s-sym = S.s-sym check: p("()") is s-list(empty) p("(5)") is s-list([list: s-num(5)]) p("(5 4)") is s-list([list: s-num(5), s-num(4)]) p("(a 5)") is s-list([list: s-sym("a"), s-num(5)]) p("a") is s-sym("a") p("\"a\"") is s-str("a") p("(a (b c))") is s-list([list: s-sym("a"), s-list([list: s-sym("b"), s-sym("c")]) ]) p("(\"a\" (5 (4) ()) \"b\")") is s-list([list: s-str("a"), s-list([list: s-num(5), s-list([list: s-num(4)]), s-list(empty) ]), s-str("b") ]) p("-5") is s-num(-5) p("-4.4") is s-num(-4.4) p("-3.") is s-num(-3.0) # Make sure bignums parse correctly p(num-tostring(num-expt(100, 100))) is s-num(num-expt(100, 100)) p("-abc3.3") is s-sym("-abc3.3") p("())") raises "Invalid" p("('a' 5)") raises "'quote'" p("(a") raises "Invalid" p(")") raises "Invalid" p("('a)") raises "Invalid" p("(()") raises "Invalid" p("(a')") raises "Invalid" end