String to S-expression for Fundamentals I, 2016, Northeastern University
string->sexpr
8.12

String to S-expression for Fundamentals I, 2016, Northeastern University🔗ℹ

matthias

 (require string-sexpr) package: string-sexpr

The teachpack provides a single function:

procedure

(string->sexpr s)  (or/c #false PD*)

  s : string?
Convert the given String into an S-expression that belongs to PD*. If the function produces #false, the given String is either not an S-expression or it is an S-expression that does not belong to PD*.

; A PD* (short for picture description) is one of:
; 'empty-image
; – String
; – (list 'circle Number String String)
; – (list 'rectangle Number Number String String)
; – (list 'beside LPD*)
; – (list 'above LPD*)
; 
; An LPD* is [Listof PD*]

Examples:
> (string->sexpr "empty-image")

'empty-image

> (string->sexpr "\"nope\"")

"nope"

> (string->sexpr "(circle 10 \"solid\" \"red\")")

'(circle 10 "solid" "red")

> (string->sexpr "(rectangle 10 20 \"solid\" \"red\")")

'(rectangle 10 20 "solid" "red")

> (string->sexpr "(above (rectangle 10 20 \"solid\" \"red\"))")

#f

> (string->sexpr
   "(beside \"hello\" (rectangle 10 20 \"solid\" \"red\") \"world\")")

#f

> (string->sexpr "(circle 10 solid red")

#f

Thanks to Eric L. for discovering the discrepancy between the data definition and the signature.

Changed in version 1.0 of package string-sexpr: Thu Nov 10 13:42:33 EST 2016
Changed in version 2.0: Sun Nov 13 21:53:56 EST 2016