Skip to content
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

chore: Remap v1 RFC #3134

Merged
merged 8 commits into from
Aug 3, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 19 additions & 33 deletions rfcs/2020-07-21-2744-vicscript.md
Original file line number Diff line number Diff line change
Expand Up @@ -66,21 +66,21 @@ root = nested.object
Vicscript supports float, int, boolean, string, null, array and object literals:

```coffee
root = [
7, false, "string", null, {
"first": 11,
"second": {"foo":"bar"},
"third": """multiple
lines on this
string"""
}
]
first = 7
second = false
third = "string"
fourth = null
```

As well as a timestamp type:

```coffee
# NOTE: The full API for the timestamp type is out of the scope of this RFC. The
# following example is for demonstrative purposes.

created_at = now().unix()
binarylogic marked this conversation as resolved.
Show resolved Hide resolved
bruceg marked this conversation as resolved.
Show resolved Hide resolved
# Sets `created_at` to an integer representing the current unix timestamp
# (in seconds).
```

Boolean operators and arithmetic galore:
bruceg marked this conversation as resolved.
Show resolved Hide resolved
Expand All @@ -93,42 +93,28 @@ multiplied = number * 7
Perform assignments conditionally with an `if` statement:

```coffee
sorted_foo = if foo.type() == "array" { foo.sort() }
sorted_foo = if foo.type() == "array" { foo.sort() } else { foo }
bruceg marked this conversation as resolved.
Show resolved Hide resolved
```

And use a `match` statement for pattern matching:
```
In: {"foo":"not an array"}
Out: {"sorted_foo":"not an array"}'

```coffee
new_doc = match doc {
type == "article" => article
type == "comment" => comment
_ => this
}
In: {"foo":["c","a","d","b"]}
Out: {"sorted_foo":["a","b","c","d"]}
bruceg marked this conversation as resolved.
Show resolved Hide resolved
```


Use a wealth of methods on values in order to perform common mutations on them:

```coffee
sorted = foo.sort()
uppercase = bar.uppercase()
bruceg marked this conversation as resolved.
Show resolved Hide resolved

foo = bar.map_each(if this.description.contains("delete me") {
deleted()
} else {
this
})
```

And, finally, create your own re-usable maps with the `map` keyword:

```coffee
map things {
first = thing_one
second = thing_two
}

foo = value_one.apply("things")
bar = value_two.apply("things")
```
In: {"foo":["c","a","d","b"],"bar":"hello world"}
Out: {"sorted":["a","b","c","d"],"uppercase":"HELLO WORLD"}
```

## Examples
Expand Down
4 changes: 4 additions & 0 deletions rfcs/2020-07-21-2744-vicscript/example1.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# NOTE: This example is intended to demonstrate larger applications for
# Vicscript in order to get a feel for the syntax. However, this uses features
# and concepts that aren't yet decided upon and aren't part of the RFC.
#
# Problem: My nan likes to send me CSV files embedded within JSON documents:
#
# {"items":"item,count\napples,10\noranges,2\n","doc":{"title":"shopping list","description":"get me this stuff"}}
Expand Down
4 changes: 4 additions & 0 deletions rfcs/2020-07-21-2744-vicscript/example2.coffee
Original file line number Diff line number Diff line change
@@ -1,3 +1,7 @@
# NOTE: This example is intended to demonstrate larger applications for
# Vicscript in order to get a feel for the syntax. However, this uses features
# and concepts that aren't yet decided upon and aren't part of the RFC.
#
# Parses events of any structure:
#
# {
Expand Down