Reusable expressions #68
Replies: 2 comments 1 reply
-
Hello , That's a good idea but should the example be :
or I'm missing something? |
Beta Was this translation helpful? Give feedback.
-
On use case has come up in the Gitter discussions. {
"/home/user/Desktop/test_for_chain_click/test": [
{ "name": "file1", "permission": "0664", "type": "file" },
{
"/home/user/Desktop/test_for_chain_click/test/directory1": [
{ "name": "file2", "permission": "0664", "type": "file" },
{ "name": "file3", "permission": "0664", "type": "file" }
],
"name": "directory1",
"type": "directory"
},
{
"/home/user/Desktop/test_for_chain_click/test/directory2": [
{ "name": "file4", "permission": "0664", "type": "file" }
],
"name": "directory2",
"type": "directory"
}
],
"name": "test",
"type": "directory"
} Let’s say we wanted to retrieve the list of fully qualified path names for the all hierarchy.
This returns the following list of paths at the top-level: [
"/home/user/Desktop/test_for_chain_click/test/file1",
"/home/user/Desktop/test_for_chain_click/test/directory1",
"/home/user/Desktop/test_for_chain_click/test/directory2"
] However, to retrieve files from subdirectories, we need to keep track of additionnal directory metadata.
Which returns: {
"v": [
{
"/home/user/Desktop/test_for_chain_click/test/directory1": [
{ "name": "file2", "permission": "0664", "type": "file" },
{ "name": "file3", "permission": "0664", "type": "file" }
],
"name": "directory1",
"type": "directory"
},
{
"/home/user/Desktop/test_for_chain_click/test/directory2": [
{ "name": "file4", "permission": "0664", "type": "file" }
],
"name": "directory2",
"type": "directory"
}
],
"n": [
"/home/user/Desktop/test_for_chain_click/test/file1",
"/home/user/Desktop/test_for_chain_click/test/directory1",
"/home/user/Desktop/test_for_chain_click/test/directory2"
]
} As you can see, the Each element of the So, if we had a way to design reusable expressions we could apply that hierarchically. |
Beta Was this translation helpful? Give feedback.
-
With the acceptance of let(), there is the opportunity to introduce user defined functions or reusable expressions.
We already have the
expression-type
construct, which can be exploited to provide this functionality.The only additional functionality that would be needed is for an
expression-type
value to be evaluated when encountered if it was not expected.for example:
In this example
let()
associatesfunc1
with the expressionx + y + d
, the literal number3
withy
and4
withd
.The second argument to
let()
is expected to be anexpression-type
and so is handled bylet()
rather than being implicitly evaluated in place. When the let() expression is evaluated, it projects the remaining expression over the input values. The remaining expression in this case beingfunc1
which is not an identifier in the current context, so it falls back to the identifier defined bylet()
. The value offunc1
is anexpression-type
, which is not expected at that point, so it implicitly evaluates the expression in-place.let()
additionally provides values that are not defined in the context, allowing for definition time values, and evaluation time values. A nestedlet()
could also change the value of y or d if needed.Beta Was this translation helpful? Give feedback.
All reactions