-
Notifications
You must be signed in to change notification settings - Fork 2
results
A results stack will be automatically formed as needed in a with path anytime there are results to be had.
The results stack will continually grow with results unless they are
popped. Popping values into their names in the local with is as
easy as: pop results some_var_name
There is also, at the moment, a last_result variable name, This was quite nice to use in the dedup-with code.
Also notice the weirdness, which is that with is given a list in the end. In that case, with will completely replace its self with the new list. It's an easy way to break SPR.
def dedupwith
"Remove duplicates from the with stack,
keeping the first entries found from the top down."
'
- with /tmp
- as/-get ~/_with_path_
- as/reverse ~_last_result_
- as/dedup ~_last_result_
# - as/rest ~_last_result_
- as/reverse ~_last_result_
- with ~_last_result_
- pop-with
To throw results away, just leave off the destination.
pop results
If the result is a map/dict then
pop results .
will merge the results into the current with path.
if the results entry is a dictionary then that dictionary can be merged directly into the current with path with a destination of '.'.
Here is an example extracted from the particle io library doc. pb/get returns a map of id, name and path. Popping to '.' causes it to be merged directly into the /device path.
SPR:> pb/get
Found 1 device connected via serial:
/dev/ttyACM0 - Boron - e00fce681ef0d2e53379dcf0
SPR:> show
/device
id: ''
last_id: ''
name: ''
path: ''
results:
- id: e00fce681ef0d2e53379dcf0
name: Boron
path: /dev/ttyACM0
serial: ''
type: ''
SPR:> pop results .
SPR:> show
/device
id: e00fce681ef0d2e53379dcf0
last_id: ''
name: Boron
path: /dev/ttyACM0
results: []
serial: ''
type: ''
This is from core.spr and is what configures and creates the readme functionality in SPR. The steps it takes are:
- Create and move to a new path called /readme
- Use Yaml to define the data needed by as/load-pkg-resource.
- Call load-pkg-resource
- move the result of that to /readme/markdown with the
pop results markdowncommand. - Call md/html to convert the markdown to html
- move the result of that to /readme/html with the
pop results htmlcommand. - Define two new commands to view and browse the readme.
If this is as common as it seems it will be, a partial for
pop results would be nice, maybe result->.
Here is a bit of help, necessary to understand the rest. Notice how the yaml and the signature maps match up.
The command as/flat-with will show a flattened map of all data contained in the with stack.
That data, should match the signatures of the things we want to use. the md/html commands wants markdown and the browsers want something called html.
So put the readme load result into markdown, run md/html, put the result into html,
Once done, this works, because browse has an html parameter, and /readme fulfills that.
with /readme web/browse
SPR:> help as/load-pkg-resource
SPR Help
=============================================
as/load-pkg-resource(package, filename)
Signature Map: {'package': None, 'filename': None}
----------------
load a python package resource file.
Find a resource file in a python module
and return it.
SPR:> help web/view
SPR Help
=============================================
web/view(html=None, url=None, title='')
Signature Map: {'html': None, 'url': None, 'title': ''}
----------------
The html wins over url if both are given.
Uses PyWebViewer
example: with /readme
web/view
Here's the code, which seems to be more comments than code.
# Set the readme folder up with stuff,
# then load the readme and convert to html.
with /readme
'
package: Simple_Process_REPL
filename: README.md
url: https://github.com/EricGebhart/Simple_Process_REPL/blob/main/README.md
title: "The SPR README!!!"
# load the resource at readme.
# works because, 'with', readme has vars which match the function signature.
as/load-pkg-resource
# pop the last result to markdown.
pop results markdown
# convert the markdown to html.
md/html
# move the last result to html.
pop results html
# view-with and browse-with are handy to have. - they can point where they want.
# view and browse use the current 'with'...
def view-doc "Display the Readme documentation in an html viewer."
with readme web/view,
def browse-doc "Display the Readme documentation in a browser window."
with readme web/browse