-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Quote Syntax. #79
Comments
This sounds great to me. It would be very useful to have a mapping primitive to quote an import, apply a map to every key with |
cowboyd
added a commit
that referenced
this issue
Feb 14, 2023
Implement the quote system for imports documented in #79
cowboyd
added a commit
that referenced
this issue
Feb 14, 2023
Implement the quote system for imports documented in #79
cowboyd
added a commit
that referenced
this issue
Feb 14, 2023
Implement the quote system for imports documented in #79
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
There are some cases where you want to have PlatformScript not evaluate a data structure. Consider the following snippet of Open API specification
How would we represent this as data in PlatformScript so that we could do things like make it the return value of a function? We cannot do it currently because evaluating the following function:
would raise a
ReferenceError: $ref is not defined
. This is because normal PlatformScript evaluation rules would dictate that the mapping$ref: '#/components/schemas/Users'
is a call to a function namedref
passing the string argument'#/components/schemas/Users'
.We need some way to say "don't evaluate stuff", just read it as a raw PlatformScript values, and return it.
Following LISP implementations, the answer is to have a
quote
form that evaluates to the raw argument. It is represented as a single quote operator'
. Thus the expression(sum 1 2 3)
evaluates to6
, but the expression'(sum 1 2 3)
evaluates to a list containing the symbolsum
and the integers1
,2
, and3
.We can replicate this with our own
'
function, so that thecreateResponses
function would be represented as:But this is not the end of the story. What if we want to transform this response and actually say that some parts of the data structure should be evaluated, but others should be left alone. To see why, let's consider our
createResponses()
function again. It's doubtful that it would be useful in this form because we are hard-coding all of the structure, but in reality, we would want to do things like parameterize the description and entity name so that we could call it like:To make this happen, we'd want to define the function with a variable substitution:
but this won't work because we told PlatformScript not to evaluate anything! Again, this is well trodden territory when it comes to LISP. It has the mechanisms of
quasiquote
andunquote
. And it uses the`
and,
symbols.So,
`(sum 1 ,(sum 1 1) 3)
would evaluate to a list with the symbolsum
followed by the integers1
,2
, and3
because the,(sum 1 1)
tells the interpreter to evaluate the result of this and plug it back into the tree.By the same token, we can introduce a quasi quote function
`
and an unquote function,
that can be used to turn on / turn off evaluation in PlatformScript. OurcreateResponses
function could then look like.the quasi-quote and unquote functionality from LISP is equivalent to JavaScript String templating's
``
and${}
except instead of producing strings, it produces syntax trees. As such, this syntax can (and will) be used for macros.Importing Quoted data
What if you have a file on disk or a open api spec that is sitting at a URL that you would like to work with like
https://example.com/open-api-spec.yaml
? we'd like to be able to just say: "import this as a module, but don't bother interpreting it because I'm going to be transforming it for some purpose" What would that look like? Here are some possibilities:separate import
This has a separate function
$import'
(import quoted) for importing modules as quoted PlatformScript.parameterized module spec:
Currently, the value of a module mapping is a string corresponding to a url, but this proposal would allow it to be parameterized in order to pass additional attributes describing how the module is to be loaded. In this case, we would add a "quote" option to tell platformscript to just load the module.
other?
What are other possibilities to tell PS to just read the value, and not interpret it?
Learning
The text was updated successfully, but these errors were encountered: