initial import
git-svn-id: svn://anubis/jtlc/trunk@2 f5bc74b8-7b62-4e90-9214-7121d538519f
This commit is contained in:
1 parent
8bfe25effa
commit
01bd481bce
11 files changed
+432
No files matched your search
@@ -0,0 +1,12 @@
|
||||
|
||||
import std.io.*;
|
||||
|
||||
int main(args : String[])
|
||||
{
|
||||
foreach (arg <- args)
|
||||
println("arg: ", arg);
|
||||
|
||||
println("Hello, World!\n");
|
||||
|
||||
return 0;
|
||||
}
|
||||
@@ -0,0 +1,37 @@
|
||||
|
||||
module Interpolator;
|
||||
|
||||
import std.io.*;
|
||||
|
||||
typedef function double (double) interpolator_t;
|
||||
|
||||
int main(args : String[])
|
||||
{
|
||||
interpolator_t i1 = getInterpolator(1, 5, 4);
|
||||
interpolator_t i2 = getInterpolator(10, 2, 5);
|
||||
|
||||
assert( i1(0) =~ 1 );
|
||||
assert( i1(4) =~ 5 );
|
||||
assert( i1(3) =~ 4.0 );
|
||||
|
||||
assert( i2(0) =~ 10 );
|
||||
assert( i2(5) =~ 2 );
|
||||
assert( i2(1.0) =~ 8.4 );
|
||||
assert( i2(2.0) =~ 6.8 );
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
/*
|
||||
* Create and return a linear interpolator functor which interpolates
|
||||
* between (0.0, x1) and (sep, x2), returning the output y-value
|
||||
*/
|
||||
interpolator_t getInterpolator(x1 : double, x2 : double, sep : double)
|
||||
{
|
||||
assert (sep > 0.0);
|
||||
|
||||
return function double (x : double)
|
||||
{
|
||||
return x * (x2 - x1) / sep + x1;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
|
||||
module Regex;
|
||||
|
||||
import std.io.*;
|
||||
|
||||
int main(args : String[])
|
||||
{
|
||||
foreach (arg <- args)
|
||||
{
|
||||
/* operator=~(String, String) returns an array of String results for
|
||||
* the matches. When there are no explicit parentheses in a pattern,
|
||||
* the array returned contains just one string - the entire matched
|
||||
* content. If the pattern does not match, an empty array is returned.
|
||||
* An empty array evaluations in a boolean context to false, while an
|
||||
* array with a nonzero number of arguments evaluations to true.
|
||||
* Hence, the =~ operator can be used in an if() statement to see if
|
||||
* the string matches a given pattern
|
||||
*/
|
||||
if (arg =~ "/^\d+$/")
|
||||
{
|
||||
println(arg, " is a number");
|
||||
}
|
||||
else if (arg =~ "/^0x\d+$/i")
|
||||
{
|
||||
println(arg, " is a hexadecimal number");
|
||||
}
|
||||
else
|
||||
{
|
||||
/* auto declaration of matches to be of type String[] */
|
||||
matches ::= arg =~ "/(.)(.)/";
|
||||
if (matches)
|
||||
{
|
||||
println("first character: ", matches[0],
|
||||
"second character: ", matches[1]);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return 0;
|
||||
}
|
||||
Reference in new issue
Block a user