Merge pull request #636 from tianon/read-docs
Fix RST code-block rendering for (read) examples and add more complex example of (read) usage
This commit is contained in:
commit
6147acfc61
@ -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}))
|
||||
@ -928,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:
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user