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

Backslash Literals #901

Merged
merged 1 commit into from Dec 27, 2018
Merged

Backslash Literals #901

merged 1 commit into from Dec 27, 2018

Conversation

hostilefork
Copy link
Member

This is an experimental (yet surprisingly full-featured) new datatype
which uses backslashes to provide escaping for any datatype. Rebol
historically only allowed escaping for WORD! and PATH!, but with this
new mechanism you can escape any datatype...and escape the escape.

Each level of evaluation will peel off one backslash...similar to how
it would remove the lit marks from words or paths.

>> \(1 + 2)
== (1 + 2)

>> \\(1 + 2)
== \(1 + 2)

This implementation is exploratory and focuses more on figuring out
what these literals should behave like than on efficiency. However,
the design is intended to permit optimizations so that bits in the
datatype can be used to compress one or two levels of escaping into
a cell directly without needing to allocate an extra node.

The literals do not have any of their own path dispatch, so picking
or pathing them should return answers that their underlying content
would give. There is a thin layer for testing over GENERIC dispatch
(e.g. actions like APPEND or COPY) which lets the literal decide if
it wants to give the plain result as-is for the action, or if it wants
to have the result add on its layers of quoting. e.g.:

 >> add quote \\\10 20
 == \\\30

These literals are incorporated into COMPOSE, which is sensitive to
them and will knock one level of escaping of off groups:

>> compose [(1 + 2) \(1 + 2) \\(1 + 2)]
== [3 (1 + 2) \(1 + 2)]

They've also been added to PARSE:

>> did parse [1 1 1] [some \1 end]
== #[true]

Optimization will be revisited once the broader system impacts have
been understood. One of the areas that is affected is parameter type
checking in functions, where TYPESET! is only 64 bits in size, and
not sufficient to store an infinite number of literal possibilities of
the basic types.

This is an experimental (yet surprisingly full-featured) new datatype
which uses backslashes to provide escaping for any datatype.  Rebol
historically only allowed escaping for WORD! and PATH!, but with this
new mechanism you can escape any datatype...and escape the escape.

Each level of evaluation will peel off one backslash...similar to how
it would remove the lit marks from words or paths.

    >> \(1 + 2)
    == (1 + 2)

    >> \\(1 + 2)
    == \(1 + 2)

This implementation is exploratory and focuses more on figuring out
what these literals should behave like than on efficiency.  However,
the design is intended to permit optimizations so that bits in the
datatype can be used to compress one or two levels of escaping into
a cell directly without needing to allocate an extra node.

The literals do not have any of their own path dispatch, so picking
or pathing them should return answers that their underlying content
would give.  There is a thin layer for testing over GENERIC dispatch
(e.g. actions like APPEND or COPY) which lets the literal decide if
it wants to give the plain result as-is for the action, or if it wants
to have the result add on its layers of quoting.  e.g.:

     >> add quote \\\10 20
     == \\\30

These literals are incorporated into COMPOSE, which is sensitive to
them and will knock one level of escaping of off groups:

    >> compose [(1 + 2) \(1 + 2) \\(1 + 2)]
    == [3 (1 + 2) \(1 + 2)]

They've also been added to PARSE:

    >> did parse [1 1 1] [some \1 end]
    == #[true]

Optimization will be revisited once the broader system impacts have
been understood.  One of the areas that is affected is parameter type
checking in functions, where TYPESET! is only 64 bits in size, and
not sufficient to store an infinite number of literal possibilities of
the basic types.
@hostilefork
Copy link
Member Author

hostilefork commented Dec 27, 2018

Some pretty exciting stuff, I think! So I'd like to see if anyone can throw some interesting tests at it to help it take shape...

Here are some tests to help give ideas!

https://github.com/metaeducation/ren-c/blob/59c699de6dd6b2bea36d21af7ef0d552ddce04fd/tests/datatypes/literal.test.reb

@hostilefork hostilefork merged commit 59c699d into metaeducation:master Dec 27, 2018
@giuliolunati
Copy link

Wooo! Very cool. Let me put the hands on it..

@hostilefork hostilefork deleted the backslash-literal branch December 27, 2018 16:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants