Quoting constructs: Difference between revisions

BLC data embedding
m (Corrected a grammatical mistake in a comment.)
(BLC data embedding)
 
(5 intermediate revisions by 2 users not shown)
Line 147:
AB"C
</pre>
=={{header|Binary Lambda Calculus}}==
The ability to embed arbitrary binary data of any length with zero overhead is one of the defining features of BLC, in which a closed lambda term is parsed from the start of the programs, and then applied to the rest of the program, making the latter the quoted part. Even the simple hello world program, which in BLC is <code> Hello, world!</code> follows this pattern, with the initial space encoding the lambda term <code>\x.x</code> for the identity function.
 
The restriction is that only one string of data can be so embedded. If we need to embed more pieces, then we can concatenate self-delimiting descriptions, which incur some logarithmic overhead, e.g. by use of the Levenshtein encoding.
 
=={{header|BQN}}==
 
Line 179 ⟶ 184:
** Strings <syntaxhighlight lang="bqn">"Hello World"
"Quoted "" String"</syntaxhighlight> any sequence of characters including newlines can be put inside a string. Quotes are escaped by typing two quotes.
 
=={{header|C++}}==
<syntaxhighlight lang="c++">
#include <iostream>
#include <string>
#include <vector>
 
int main() {
// C++ uses double quotes for strings and single quotes for characters.
std::string simple_string = "This is a simple string";
char letter = 'A';
std::cout << simple_string << " " << letter << std::endl;
 
// C++ can implement multiline strings.
std::string multiline_string = R"(
An example of multi-line string.
Text formatting is preserved.
This is a raw string literal, introduced in C++ 11.)";
std::cout << multiline_string << std::endl;
 
// C++'s primitive data types: bool, char, double, float, int, long, short,
// can be used to to store data, for example,
const int block_length = 64;
std::cout << "block length = " << block_length << std::endl;
 
// Vectors of these data types are also possible, for example,
std::vector<double> state = { 1.0, 2.0, 3.0 };
}
</syntaxhighlight>
{{ out }}
<pre>
This is a simple string A
 
An example of multi-line string.
Text formatting is preserved.
This is a raw string literal, introduced in C++ 11.
block length = 64
</pre>
 
=={{header|Ecstasy}}==
Line 433 ⟶ 476:
System.out.println(multiLineString);
// Java's primitive data types: boolean, byte, char, double, float, int, long, short,
// can be used to to store data, for example,
final int blockLength = 64;
Line 453 ⟶ 496:
This is an example of multi-line string.
Text formatting is preserved.
Text blocks can be used for a multi-line string.
</pre>
 
Line 1,055 ⟶ 1,098:
 
Here are some examples of all this.
<syntaxhighlight lang="ecmascriptwren">import "./fmt" for Fmt
 
// simple string literal
56

edits