From cf7e5ed3c012a8f435921021ab471d61020ecbf3 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Tue, 19 Aug 2014 02:55:47 -0600 Subject: [PATCH 1/2] Fix RST code-block rendering for (read) examples Also removed trailing whitespace and added a blank line to separate the discrete examples --- docs/language/core.rst | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/docs/language/core.rst b/docs/language/core.rst index f5e31cb..9236c25 100644 --- a/docs/language/core.rst +++ b/docs/language/core.rst @@ -915,12 +915,14 @@ Raises an `EOFError` if `from-file` ends before a complete expression can be parsed. .. code-block:: hy + => (read) (+ 2 2) ('+' 2 2) => (eval (read)) - (+ 2 2) + (+ 2 2) 4 + => (import io) => (def buffer (io.StringIO "(+ 2 2)\n(- 2 1)")) => (eval (apply read [] {"from_file" buffer})) From 8d893ead073ad1e046ca1c0b8f07c94aecfeebf7 Mon Sep 17 00:00:00 2001 From: Tianon Gravi Date: Tue, 19 Aug 2014 03:02:07 -0600 Subject: [PATCH 2/2] Add more complex example of (read) usage --- docs/language/core.rst | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/docs/language/core.rst b/docs/language/core.rst index 9236c25..f18eedf 100644 --- a/docs/language/core.rst +++ b/docs/language/core.rst @@ -930,6 +930,24 @@ parsed. => (eval (apply read [] {"from_file" buffer})) 1 + => ; assuming "example.hy" contains: + => ; (print "hello") + => ; (print "hyfriends!") + => (with [[f (open "example.hy")]] + ... (try + ... (while true + ... (let [[exp (read f)]] + ... (do + ... (print "OHY" exp) + ... (eval exp)))) + ... (catch [e EOFError] + ... (print "EOF!")))) + OHY ('print' 'hello') + hello + OHY ('print' 'hyfriends!') + hyfriends! + EOF! + .. _remove-fn: