A-M baby
This commit is contained in:
parent
764da6cbbb
commit
db842d013d
19005 changed files with 197040 additions and 7 deletions
4
Task/Here-document/0DESCRIPTION
Normal file
4
Task/Here-document/0DESCRIPTION
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
{{omit from|BBC BASIC}}
|
||||
A here document (or "heredoc") is a way of specifying a text block, preserving the line breaks, indentation and other whitespace within the text. Depending on the language being used a here document is constructed using a command followed by "<<" (or some other symbol) followed by a token string. The text block will then start on the next line, and will be followed by the chosen token at the beginning of the following line, which is used to mark the end of the textblock.
|
||||
|
||||
The task is to demonstrate the use of here documents within the language.
|
||||
17
Task/Here-document/ALGOL-68/here-document.alg
Normal file
17
Task/Here-document/ALGOL-68/here-document.alg
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#!/usr/local/bin/a68g --script #
|
||||
|
||||
[]STRING help = (
|
||||
"Usage: thingy [OPTIONS]",
|
||||
" -h Display this usage message",
|
||||
" -H hostname Hostname to connect to"
|
||||
);
|
||||
|
||||
printf(($gl$,help,$l$));
|
||||
|
||||
printf(($gl$,
|
||||
"The river was deep but I swam it, Janet.",
|
||||
"The future is ours so let's plan it, Janet.",
|
||||
"So please don't tell me to can it, Janet.",
|
||||
"I've one thing to say and that's ...",
|
||||
"Dammit. Janet, I love you."
|
||||
))
|
||||
20
Task/Here-document/Ada/here-document.ada
Normal file
20
Task/Here-document/Ada/here-document.ada
Normal file
|
|
@ -0,0 +1,20 @@
|
|||
with Ada.Containers.Indefinite_Vectors, Ada.Text_IO;
|
||||
|
||||
procedure Here_Doc is
|
||||
|
||||
package String_Vec is new Ada.Containers.Indefinite_Vectors
|
||||
(Index_Type => Positive,
|
||||
Element_Type => String);
|
||||
|
||||
use type String_Vec.Vector;
|
||||
|
||||
Document: String_Vec.Vector := String_Vec.Empty_Vector
|
||||
& "This is a vector of strings with the following properties:"
|
||||
& " - indention is preserved, and"
|
||||
& " - a quotation mark '""' must be ""escaped"" by a double-quote '""""'.";
|
||||
begin
|
||||
Document := Document & "Have fun!";
|
||||
for I in Document.First_Index .. Document.Last_Index loop
|
||||
Ada.Text_IO.Put_Line(Document.Element(I));
|
||||
end loop;
|
||||
end Here_Doc;
|
||||
9
Task/Here-document/AutoHotkey/here-document.ahk
Normal file
9
Task/Here-document/AutoHotkey/here-document.ahk
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
MyVar = "This is the text inside MyVar"
|
||||
MyVariable =
|
||||
(
|
||||
Note that whitespace is preserved
|
||||
As well as newlines.
|
||||
The LTrim option can be present to remove left whitespace.
|
||||
Variable references such as %MyVar% are expanded.
|
||||
)
|
||||
MsgBox % MyVariable
|
||||
13
Task/Here-document/C-sharp/here-document.cs
Normal file
13
Task/Here-document/C-sharp/here-document.cs
Normal file
|
|
@ -0,0 +1,13 @@
|
|||
using System;
|
||||
|
||||
class Program
|
||||
{
|
||||
static void Main(string[] args)
|
||||
{
|
||||
Console.Write(@"
|
||||
multiline
|
||||
strings are easy
|
||||
to put together
|
||||
in C#");
|
||||
}
|
||||
}
|
||||
11
Task/Here-document/CoffeeScript/here-document.coffee
Normal file
11
Task/Here-document/CoffeeScript/here-document.coffee
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
myDoc = '''
|
||||
Single-quoted heredocs allows no '#{foo}' interpolation.
|
||||
This behavior is similar to single-quoted strings.
|
||||
'''
|
||||
doc2 = """
|
||||
However, double-quoted heredocs *do* allow these.
|
||||
See it in action:
|
||||
Content: "#{myDoc}"
|
||||
"""
|
||||
|
||||
console.log doc2
|
||||
1
Task/Here-document/D/here-document-1.d
Normal file
1
Task/Here-document/D/here-document-1.d
Normal file
|
|
@ -0,0 +1 @@
|
|||
auto s = q"[a string that you "don't" have to escape]";
|
||||
6
Task/Here-document/D/here-document-2.d
Normal file
6
Task/Here-document/D/here-document-2.d
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
writefln(q"EOS
|
||||
This
|
||||
is a multi-line
|
||||
heredoc string
|
||||
EOS"
|
||||
);
|
||||
4
Task/Here-document/DWScript/here-document.dwscript
Normal file
4
Task/Here-document/DWScript/here-document.dwscript
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
PrintLn("This is
|
||||
a multiline
|
||||
""string""
|
||||
sample");
|
||||
49
Task/Here-document/Forth/here-document.fth
Normal file
49
Task/Here-document/Forth/here-document.fth
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
\ GForth specific words:
|
||||
\ under+ ( a b c -- a+c b) , latest ( -- nt ) , name>string ( nt -- ca u )
|
||||
\ Should not be a problem to modify it to work with other Forth implementation:
|
||||
|
||||
: $! ( ca u -- a )
|
||||
dup >R dup , here swap move R> allot ;
|
||||
: $@ ( a -- ca u )
|
||||
dup @ 1 cells under+ ;
|
||||
: c!+ ( c ca - ca+1 )
|
||||
tuck c! 1+ ;
|
||||
: $!+ ( a u a' -- a'+u ; string-store-plus )
|
||||
2dup + >R swap move R> ;
|
||||
|
||||
\ --- UNIX end-of-line adapted words
|
||||
10 constant EOL
|
||||
: input-fix ( -- ; for interactive use ! )
|
||||
source-id 0= IF cr THEN ;
|
||||
: get_line ( -- ca u ) EOL parse input-fix ;
|
||||
: EOL!+ ( a -- a' ; eol-store-plus ) EOL swap c!+ ;
|
||||
|
||||
: EOD ( -- ca u ; end-of-doc )
|
||||
latest name>string ;
|
||||
|
||||
: >> ( "doc-name" "doc-body" -- ) input-fix
|
||||
CREATE 0 , \ post body length
|
||||
here dup >R
|
||||
BEGIN refill >R
|
||||
get_line 2dup EOD compare
|
||||
R> AND \ notEOD && input-stream ->
|
||||
WHILE rot $!+ EOL!+
|
||||
REPEAT 2drop
|
||||
R> tuck - dup allot
|
||||
swap -1 cells + ! \ fixup body length
|
||||
DOES> ( -- ca u ) $@ ;
|
||||
|
||||
\ TEST ; excerpt from Project Gutenberg 'Alice in Wonderland'
|
||||
|
||||
>> ALICE
|
||||
CHAPTER I. Down the Rabbit-Hole
|
||||
|
||||
Alice was beginning to get very tired of sitting by her sister on the
|
||||
bank, and of having nothing to do: once or twice she had peeped into the
|
||||
book her sister was reading, but it had no pictures or conversations in
|
||||
it, 'and what is the use of a book,' thought Alice 'without pictures or
|
||||
conversation?'
|
||||
ALICE
|
||||
>> RABBIT
|
||||
RABBIT
|
||||
ALICE type ." --" cr RABBIT type
|
||||
3
Task/Here-document/Frink/here-document.frink
Normal file
3
Task/Here-document/Frink/here-document.frink
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
lyrics = """Oh, Danny Boy,
|
||||
The pipes, the pipes are calling
|
||||
From glen to glen and down the mountainside"""
|
||||
3
Task/Here-document/Go/here-document.go
Normal file
3
Task/Here-document/Go/here-document.go
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
var m = ` leading spaces
|
||||
|
||||
and blank lines`
|
||||
8
Task/Here-document/Groovy/here-document-1.groovy
Normal file
8
Task/Here-document/Groovy/here-document-1.groovy
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
println '''
|
||||
Time's a strange fellow;
|
||||
more he gives than takes
|
||||
(and he takes all) nor any marvel finds
|
||||
quite disappearance but some keener makes
|
||||
losing, gaining
|
||||
--love! if a world ends
|
||||
'''
|
||||
18
Task/Here-document/Groovy/here-document-2.groovy
Normal file
18
Task/Here-document/Groovy/here-document-2.groovy
Normal file
|
|
@ -0,0 +1,18 @@
|
|||
def expired='defunct'
|
||||
def horse='stallion'
|
||||
def christ='Jesus'
|
||||
|
||||
println """
|
||||
Buffalo Bill's
|
||||
${expired}
|
||||
who used to
|
||||
ride a watersmooth-silver
|
||||
${horse}
|
||||
and break onetwothreefourfive pigeonsjustlikethat
|
||||
${christ}
|
||||
|
||||
he was a handsome man
|
||||
and what i want to know is
|
||||
how do you like your blueeyed boy
|
||||
Mister Death
|
||||
"""
|
||||
40
Task/Here-document/J/here-document.j
Normal file
40
Task/Here-document/J/here-document.j
Normal file
|
|
@ -0,0 +1,40 @@
|
|||
here=:0 :0
|
||||
0 :0 will be replaced by the text on the following lines.
|
||||
This is three tokens: two instances of the number 0 and
|
||||
one instance of the explicit definition token ':'.
|
||||
Any indentation in the here document will be retained in the result.
|
||||
There must be a space to the left of : or it will combine with the
|
||||
0 on its left to form the token 0: which is something completely
|
||||
different.
|
||||
|
||||
The here document is terminated by a line which contains only a
|
||||
single right parenthesis ')' and optional white space. In J's
|
||||
documentation the family of entities which include here documents
|
||||
(and verb definitions and so on) are called 'scripts'.
|
||||
|
||||
When several scripts are referenced on the same line, they are used
|
||||
sequentially in an order determined by their appearance on the line.
|
||||
The leftmost 'script' reference gets the last script and the rightmost
|
||||
reference gets the first script. But this is a rare usage.
|
||||
|
||||
Typically, such values are assigned a name so that they can be
|
||||
used later. However, they may also be discarded and/or ignored, in
|
||||
which case they are logically equivalent to multi-line comments.
|
||||
)
|
||||
|
||||
and_here=:noun define
|
||||
'noun define' is an alternative and perhaps more "user friendly"
|
||||
way of declaring a here document. It achieves the same thing as
|
||||
0 :0 and in fact 'noun' has the value 0 and 'define' has the value :0
|
||||
And, of course, there must be a space between the word 'noun' and
|
||||
the word 'define'.
|
||||
|
||||
Other useful alternatives include verb (which has the value 3)
|
||||
and dyad (which has the value 4), and adverb (which has the value 1).
|
||||
In other words 'verb define' (if unquoted) would be replaced by a
|
||||
verb whose definition is provided in the following 'script'.
|
||||
However, all of these names are normal variables which can
|
||||
be declared to have different values by the developer. And, of course,
|
||||
note that this mechanism is significantly more verbose than using
|
||||
the underlying 0 :0 mechanism directly.
|
||||
)
|
||||
14
Task/Here-document/Lua/here-document.lua
Normal file
14
Task/Here-document/Lua/here-document.lua
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
print([[
|
||||
This is a long paragraph of text
|
||||
it is the simplest while using it
|
||||
with lua, however it will have the
|
||||
same line breaks and spacing as
|
||||
you set in this block.
|
||||
]])
|
||||
|
||||
local msg = [[this is a message that spans
|
||||
multiple lines and will have the next lines
|
||||
preserved as they were entered, so be careful
|
||||
when using this]]
|
||||
|
||||
print(msg)
|
||||
6
Task/Here-document/PHP/here-document-1.php
Normal file
6
Task/Here-document/PHP/here-document-1.php
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
$address = <<<END
|
||||
1, High Street,
|
||||
$town_name,
|
||||
West Midlands.
|
||||
WM4 5HD.
|
||||
END;
|
||||
5
Task/Here-document/PHP/here-document-2.php
Normal file
5
Task/Here-document/PHP/here-document-2.php
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$x = <<<'FOO'
|
||||
No
|
||||
$interpolation
|
||||
here
|
||||
FOO;
|
||||
6
Task/Here-document/Perl/here-document-1.pl
Normal file
6
Task/Here-document/Perl/here-document-1.pl
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
$address = <<END;
|
||||
1, High Street,
|
||||
$town_name,
|
||||
West Midlands.
|
||||
WM4 5HD.
|
||||
END
|
||||
5
Task/Here-document/Perl/here-document-2.pl
Normal file
5
Task/Here-document/Perl/here-document-2.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$pancake = <<"NO MORE INGREDIENTS";
|
||||
egg
|
||||
milk
|
||||
flour
|
||||
NO MORE INGREDIENTS
|
||||
5
Task/Here-document/Perl/here-document-3.pl
Normal file
5
Task/Here-document/Perl/here-document-3.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
$x = <<'FOO';
|
||||
No
|
||||
$interpolation
|
||||
here
|
||||
FOO
|
||||
3
Task/Here-document/Perl/here-document-4.pl
Normal file
3
Task/Here-document/Perl/here-document-4.pl
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
$output = <<`BAR`;
|
||||
ls /home
|
||||
BAR
|
||||
4
Task/Here-document/Perl/here-document-5.pl
Normal file
4
Task/Here-document/Perl/here-document-5.pl
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
print(<<EOF . "lamb\n");
|
||||
Mary had
|
||||
a little
|
||||
EOF
|
||||
5
Task/Here-document/Perl/here-document-6.pl
Normal file
5
Task/Here-document/Perl/here-document-6.pl
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
print(<<EOF
|
||||
Mary had
|
||||
a little
|
||||
EOF
|
||||
. "lamb\n");
|
||||
9
Task/Here-document/PicoLisp/here-document.l
Normal file
9
Task/Here-document/PicoLisp/here-document.l
Normal file
|
|
@ -0,0 +1,9 @@
|
|||
(out "file.txt" # Write to "file.txt"
|
||||
(prinl "### This is before the text ###")
|
||||
(here "TEXT-END")
|
||||
(prinl "### This is after the text ###") )
|
||||
"There must be some way out of here", said the joker to the thief
|
||||
"There's too much confusion, I can't get no relief"
|
||||
TEXT-END
|
||||
|
||||
(in "file.txt" (echo)) # Show "file.txt"
|
||||
5
Task/Here-document/Python/here-document.py
Normal file
5
Task/Here-document/Python/here-document.py
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
print("""\
|
||||
Usage: thingy [OPTIONS]
|
||||
-h Display this usage message
|
||||
-H hostname Hostname to connect to
|
||||
""")
|
||||
61
Task/Here-document/REXX/here-document.rexx
Normal file
61
Task/Here-document/REXX/here-document.rexx
Normal file
|
|
@ -0,0 +1,61 @@
|
|||
/*REXX program demonstrates a method to use "here" documents in REXX. */
|
||||
parse arg doc . /*"here" name is case sensitive. */
|
||||
|
||||
do j=1 for sourceline()
|
||||
if sourceline(j)\=='◄◄'doc then iterate
|
||||
do !=j+1 to sourceline() while sourceline(!)\=='◄◄.'
|
||||
say sourceline(!)
|
||||
end /*!*/
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
end /*j*/
|
||||
|
||||
say doc '"here" document not found.'
|
||||
exit /*stick a fork in it, we're done.*/
|
||||
/*──────────────────────────────────start of "here" docs──────────────────
|
||||
◄◄rs-232
|
||||
RS─232 Signals and Pinouts ┌─────────────────────────────────────────────────┐
|
||||
│13 12 11 10 9 8 7 6 5 4 3 2 1│
|
||||
──► Interface between data └┐ 25 24 23 22 21 20 19 18 17 16 15 14┌┘
|
||||
terminal equipment (DTE/male)└───────────────────────────────────────────────┘
|
||||
and data communication equipment
|
||||
[DCE/female] employing serial ┌───────────────────────────────────────────┐
|
||||
binary data interchange. │ 12◄─secondary carrier detect [SCD] DCE │
|
||||
┌─────────────────────────────────┤ 13◄─secondary clear to send [SCS] DCE │
|
||||
│ 1◄─protective ground [PG, GND] │ 14◄─secondary transmitted data [STD] DTE │
|
||||
│ 2◄─transmitted data [TD] DTE │ 15◄─transmit clock [TC] DCE │
|
||||
│ 3◄─received data [RD] DCE │ 16◄─secondary received data [SRD] DCE │
|
||||
│ 4◄─request to send [RTS] DTE │ 17◄─receiver clock [RC] DCE │
|
||||
│ 5◄─clear to send [CTS] DCE │ 18◄─unassigned │
|
||||
│ 6◄─data set ready [DSR] DCE │ 19◄─secondary request to send [SRS] DTE │
|
||||
│ 7◄─signal ground [SG] │ 20◄─data terminal ready [DTR] DTE │
|
||||
│ (common return) │ 21◄─signal quality detector [SQD] DCE │
|
||||
│ 8◄─carrier detect [CD] DCE │ 22◄─ring indicator [RI] DCE │
|
||||
│ 9◄─positive voltage [-] │ 23◄─data rate select [DRS] DCE/DTE │
|
||||
│10◄─negative voltate [-] │ 24◄─external clock [XTC] DTE │
|
||||
│11◄─unassigned │ 25◄─unassigned │
|
||||
└─────────────────────────────────┴───────────────────────────────────────────┘
|
||||
◄◄.
|
||||
◄◄can
|
||||
┌──────┐
|
||||
│ │
|
||||
│ ├┐
|
||||
│ ├┘
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
│ │ ┌─────┐
|
||||
└──┬┬──┘ │┌───┐│
|
||||
││ ├┤ ├┤
|
||||
││ ┌───────────────┐ ││ ││
|
||||
││ ┌┴──────────────┬┘ └┤ ├┘
|
||||
│└───┤ │ └───┘
|
||||
└────┤ ┌──┘
|
||||
│ │
|
||||
└──┐ │
|
||||
│ │
|
||||
│ │
|
||||
│ │
|
||||
└─────────┘
|
||||
◄◄.
|
||||
────────────────────────────────────end of "here" docs──────────────────*/
|
||||
8
Task/Here-document/Racket/here-document-1.rkt
Normal file
8
Task/Here-document/Racket/here-document-1.rkt
Normal file
|
|
@ -0,0 +1,8 @@
|
|||
#lang racket/base
|
||||
|
||||
(displayln #<<EOF
|
||||
Blah blah blah
|
||||
with indentation intact
|
||||
and "free" \punctuations\
|
||||
EOF
|
||||
)
|
||||
17
Task/Here-document/Racket/here-document-2.rkt
Normal file
17
Task/Here-document/Racket/here-document-2.rkt
Normal file
|
|
@ -0,0 +1,17 @@
|
|||
#lang at-exp racket/base
|
||||
|
||||
(require scribble/text)
|
||||
|
||||
(define excited "!!!")
|
||||
(define (shout . text) @list{>>> @text <<<})
|
||||
|
||||
(output
|
||||
@list{Blah blah blah
|
||||
with indentation intact
|
||||
but respecting the indentation of
|
||||
the whole code
|
||||
and "free" \punctuations\
|
||||
and even string interpolation-like @excited
|
||||
but really @shout{any code}
|
||||
|
||||
})
|
||||
6
Task/Here-document/Ruby/here-document-1.rb
Normal file
6
Task/Here-document/Ruby/here-document-1.rb
Normal file
|
|
@ -0,0 +1,6 @@
|
|||
address = <<END
|
||||
1, High Street,
|
||||
#{town_name},
|
||||
West Midlands.
|
||||
WM4 5HD.
|
||||
END
|
||||
5
Task/Here-document/Ruby/here-document-2.rb
Normal file
5
Task/Here-document/Ruby/here-document-2.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
pancake = <<"NO MORE INGREDIENTS"
|
||||
egg
|
||||
milk
|
||||
flour
|
||||
NO MORE INGREDIENTS
|
||||
5
Task/Here-document/Ruby/here-document-3.rb
Normal file
5
Task/Here-document/Ruby/here-document-3.rb
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
x = <<'FOO'
|
||||
No
|
||||
#{interpolation}
|
||||
here
|
||||
FOO
|
||||
3
Task/Here-document/Ruby/here-document-4.rb
Normal file
3
Task/Here-document/Ruby/here-document-4.rb
Normal file
|
|
@ -0,0 +1,3 @@
|
|||
output = <<`BAR`
|
||||
ls /home
|
||||
BAR
|
||||
4
Task/Here-document/Ruby/here-document-5.rb
Normal file
4
Task/Here-document/Ruby/here-document-5.rb
Normal file
|
|
@ -0,0 +1,4 @@
|
|||
puts <<EOF + "lamb"
|
||||
Mary had
|
||||
a little
|
||||
EOF
|
||||
11
Task/Here-document/Tcl/here-document.tcl
Normal file
11
Task/Here-document/Tcl/here-document.tcl
Normal file
|
|
@ -0,0 +1,11 @@
|
|||
set hereDocExample {
|
||||
In Tcl, the {curly brace} notation is strictly a here-document style notation
|
||||
as it permits arbitrary content inside it *except* for an unbalanced brace.
|
||||
That is typically not a problem as seen in reality, as almost all content that
|
||||
might be placed in a here-doc is either brace-free or balanced. The content
|
||||
of the braces is not interpreted at all; no substitutions are performed on it.
|
||||
|
||||
The sole exception is that there is limited processing of backslashes; a single
|
||||
backslash at the end of a line causes the end-of-line plus all whitespace at
|
||||
the start of the next line to be compressed to a single space.
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue