MirrgieRiana / scriptFluorite5

チャットに数式を埋め込みダイス\2d\や演算\10*(2+3)\をする為にJavaScriptで実装されるインタプリタ型言語
4 stars 1 forks source link

作ったテストケースを報告する場所 #41

Open MirrgieRiana opened 8 years ago

MirrgieRiana commented 8 years ago
\10*(2+3)\ = 50
\10-2\ = 8
\10/4\ = 2.5
\1-2-3\ = -4
\60/2/3\ = 10
\-6\ = -6
\4--5\ = 9
\4---+5\ = -1
\ 30
+ 15\ = 45

2 <= \2d\ <= 12

\3 > 5\ = false
\5 > 3\ = true
\4 > 4\ = false
\3 >= 5\ = false
\5 >= 3\ = true
\4 >= 4\ = true
\3 < 5\ = true
\5 < 3\ = false
\4 < 4\ = false
\3 <= 5\ = true
\5 <= 3\ = false
\4 <= 4\ = true
\3 == 5\ = false
\5 == 3\ = false
\4 == 4\ = true
\3 != 5\ = true
\5 != 3\ = true
\4 != 4\ = false

\1 + 2 == 3\ = true
\5 * 6 - 1 == 29\ = true
\1 < 4 < 6\ = true
\5 > 3 > 2 < 4 <= 4 < 5\ = true
\5 > 6 > 2 < 4 <= 4 < 5\ = false
MirrgieRiana commented 8 years ago
\$pi\
\2, 3.14, 6.02e23, K\
\1+2, 1-2, 4*5, 5/2\
\(1), 10*(2+3)\
\4>5, 1<3<4<5<=5<=6==6!=8>2>-1\
\1==1 && 2==1 || 2==1 && 1==1\
\1==1 && 1==1 || 2==1 && 1==1\
\2d+4\ 
\3*(10+2)\

            <br>

\a --> 2d\
    \a, b, c --> 2d\
\1, 2 --> ($_, $_ * 2) --> $_ * 10 --> $_ + 5 --> ($_, 10)\
\sin(2d)\
\a, 2, 3 --> ($_, sin($_ * 0.1))\
MirrgieRiana commented 8 years ago
\($a ->: (*$a::b[1](5))(4))
({b: [0, ($c ->: &($d ->: $c * $d))]})\ = 20
\($a ->: $a::function(0.5 * $pi))({function: sin})\ = 1
MirrgieRiana commented 8 years ago
\($a :> /length $a::b)({b: 'asd'})\ = 3
MirrgieRiana commented 8 years ago

※まだ動かないが将来動くかもしれないコード

/function mandelbrot($c : Complex) {
  /var $z : Complex = 0;
  /const $limit : Number = 500;
  /for (/var $i : Number = 1; $i <= $limit; $i += 1) {
    $z ^= 2;
    $z += $c;
    /if ($z.abs() > 4) { /break; };
  }
  /return $limit;
}
MirrgieRiana commented 8 years ago
\1~5 --> [$_, 2d] --> (@$_ => ($k, $v :> "[$k] = $v"))\
MirrgieRiana commented 8 years ago

\1~20-->($_%3?"":Buzz)+($_%5?"":Fizz)||$_\

新Ver \1~20-->($_%3?"":Buzz)+($_%5?"":Fizz)?:$_\

MirrgieRiana commented 8 years ago
\$"_multibyte_#" = $a, $b :> (/typeof $b) == "Pointer"
? (((*$a)[0] - (*$b)[0])^2 + ((*$a)[1] - (*$b)[1])^2)^0.5
: ((*$a)[0]^2 + (*$a)[1]^2)^0.5\

5=\[100,-100]#[104, -97]\
5=\#[4, 3]\
MirrgieRiana commented 8 years ago
\`sin` 3.14159265358979\
\$sqrt = a :> $a ^ 0.5;
`sqrt` 3.14159265358979\
\"-" `join` (4, 5, 6)\
MirrgieRiana commented 8 years ago
\$fluorite::type::Number::sqrt = $self :> $self ^ 0.5;\
\4.sqrt()\
\$fluorite::type::String::rept= $self, $times :> 1 ~ $times --> $self => join1;\
\"r".rept(3)\
MirrgieRiana commented 8 years ago
\
/class RateTable extends $fluorite::type::Array {
  $class::new = (() :> [$_]);
  $class::get = ($this, $dice :> $dice == 2 ? -10 : $this[$dice - 3]);
};
/class RateTable20 extends RateTable {
  $class::new = (() :> 3 ~ 12 --> $_ - 2);
};
\

\1~10 --> (
  1~5 --> 2d --> [$_: (/new RateTable20()).get($_)] => join2
) => join3\
MirrgieRiana commented 8 years ago

\

/class BuzzFizzEntry extends $fluorite::type::Hash { $class::new = $number, $text :> { number: $number, text: $text, }; $class::toString = $this, $n :> $n % $this::number ? "" : $this::text; };

/class BuzzFizz extends $fluorite::type::Array { $class::new = () :> [$]; $class::toString = $this, $n :> ((@$this --> $.toString($n) => "".join) || $n) => join2; };

$bf35 = (/new BuzzFizz( (/new BuzzFizzEntry(3, Buzz)), (/new BuzzFizzEntry(5, Fizz)), ));

\

\1~20 --> $bf35.toString($)\ \1~20 --> (/new BuzzFizz( (/new BuzzFizzEntry(7, Seven)), (/new BuzzFizzEntry(2, Two)), )).toString($)\

MirrgieRiana commented 8 years ago
\
$fluorite::type::Entry::key = $this :> /entry_key $this;
$fluorite::type::Entry::value = $this :> /entry_value $this;
$fluorite::type::String::length = $this :> /length $this;
\

\$entry = name: "NAME!";\

Object:       \$entry\
Type:         \/typeof $entry\
Key:          \$entry.key()\
Key Length:   \$entry.key().length()\
Value:        \$entry.value()\
Value Length: \$entry.value().length()\
MirrgieRiana commented 8 years ago
\
$func = () :> (
  $primes = $_;
  /try {
    1 ~ 100
      --> (
        $n = $_;
        ($primes --> $n % $_ == 0 => and)
          ? (/throw "$n")
          : ()
      );
  } catch (e) {
    $e
  }
);

$func(3, 5, 2)
\
MirrgieRiana commented 8 years ago
\
/class Enchanted {
  $class::new = $number, $unit :> {
    number: $number,
    unit: $unit,
  };
};

$_rightComposite_Exp = $a :> /new Enchanted(*$a, Exp);

55Exp
\
MirrgieRiana commented 8 years ago
\
/new $fluorite::type::Number(3.141592 / 2)/.(Math::sin)();

/new $fluorite::type::Number /new $fluorite::type::Number(50)/ /;
/array (a) {
} else /array (a, b) {k: h
} else /array [a, b, c] {
};

\
MirrgieRiana commented 8 years ago
\
$a = {a: k, k4: b, b1: a};
/keys $a/ --> $_ + " => " + $a::$_ => join3
\
MirrgieRiana commented 8 years ago
\
/class A extends $fluorite::type::Number {
  $class::toString = $this :> $this ^ 2;
}/;

/new A(50)/
\
MirrgieRiana commented 8 years ago
\
/class A extends Number {
}/;

/class B extends A {
  $class::toString = $this :> "[$($super#_method_toString($this) ^ 2)]";
}/;

$a = /new B(50)/;

"[$a]"
\
MirrgieRiana commented 8 years ago
\
/var $a;
$a = 4;
(
  /var $a;
  $a = 44;
);
$a
\
MirrgieRiana commented 8 years ago
\1+2+/**/3+4+5\
\1+2+/***/3+4+5\
\1+2+/*
*/3+4+5\
\1+2+/++/3+4+5\
\1+2+/+++/3+4+5\
\1+2+/+
+/3+4+5\
\1+2+/+ /**/ +/3+4+5\
\1+2+/+ /+ +/ +/3+4+5\
\1+2+/+ /+ +/ +/3+4+5\
MirrgieRiana commented 8 years ago

\0xff\

MirrgieRiana commented 8 years ago
#! comment
\
0xffffff,
0xff00ff,
"\u3328" /+ co /+ mm +/ ent +/ ,
'\x5a',
/new Number(3.14 / 2)/.(Math::sin)(), #! comment
\
MirrgieRiana commented 8 years ago
\
$a = 4;
1~7 --> $a--;
$a
\
MirrgieRiana commented 8 years ago
\
/class A extends Hash {
  $class::new = () :> {
    i: 200,
    value: 5,
  };
  $class::toString = $this :> $this::value.toString();
  $class::get = $this :> $this::value;
};
$a = /new A({a: 4});
[$a, $a::i, $a.get()]
\

\5.($Math::sin)()\ \2 `d` 6\ \$sin=$Math::sin; 3.14sin\

\$a = {};$b = [$a];$a::a = $b;$a\

\$a = () :> $a();$a()\
MirrgieRiana commented 8 years ago
\
$fluorite::type::Array::length = $this :> /length $this;
$fluorite::type::Array::random = $this :> $this[Math::randomBetween(0, $this.length() - 1)];

$b = [3, 4, 5].random;
$c = 1 ~ 20;

1 ~ 18
--> ($c --> $b() => join2)
=> join3
\
MirrgieRiana commented 8 years ago
\
$fluorite::type::Array::length = $this :> /length $this;
$fluorite::type::Array::random = $this :> $this[Math::randomBetween(0, $this.length() - 1)];

$b = [/li あ い う え お];

1 ~ 12 --> (1 ~ 40 --> $b.random() => join1) => join3
\
MirrgieRiana commented 8 years ago
\
$fluorite::type::Array::length = $this :> /length $this;
/class Yakigote extends Array {
  $class::new = () :> [/li あ い う え お];
  $class::random = $this :> $this[Math::randomBetween(0, $this.length() - 1)];
};

$b = /new Yakigote();
/console_scope;
1 ~ 12 --> (1 ~ 40 --> $b.random() => join1) => join3
\
MirrgieRiana commented 8 years ago
\O, I --> "L${_}VE"\
\O, I --> "L${_}VE" => join2\
\O, I --> "L${_}VE" => " ".join\
\O, I --> L + $_ + VE=> " ".join\
\O, I --> L, $_, VE=> join1\
\/li O I --> /li L $_ VE => join1\

LOVE, LIVE
LOVE, LIVE
LOVE LIVE
LOVE LIVE
LOVELIVE
LOVELIVE
MirrgieRiana commented 8 years ago
\
$fluorite::type::String::length = $this :> /length $this;
Hello, World -> length => sum
\
MirrgieRiana commented 8 years ago
\
$fluorite::type::String::length = $this :> /length $this;
Hello, World -> length => join1
\

Ja: Stream.of("Hello", "World").map(i -> "" + i.length()).collect(Collectors.joining())
JS: ["Hello", "World"].map(i => i.length).join("")
Fu: Hello, World -> length => join1
PL: map length $_, qw/Hello World/
MirrgieRiana commented 8 years ago
\
$"𩸽" = $a, $b :> &(*$a + *$b);
4 𩸽 5
\

\/length "𩸽"\
MirrgieRiana commented 8 years ago
\
/class Array2 {
  $class::new = () :> {value: []};
  $class::push = $this, $i :> $this::value = [@$this::value, $i];
  $class::pop = $this :> (
    /var $a; $a = $this::value[/length $this::value/ - 1];
    $this::value = [0 ~ (/length $this::value/ - 2) --> $this::value[$_]];
    $a
  );
};
$_get_operatorLess2 = $c, $a, $b :> &(*$a).push(*$b);
\

\$a = /new Array2()/;\
\$a << 50; $a\
\$a << 70; $a\
\$a << 4; $a\
\$a.pop(); $a\
\$a << 120; $a\
\$a.pop(); $a\
MirrgieRiana commented 8 years ago
\
$"÷" = $a, $b :> &(*$a / *$b);
Math::atan2(1, 1) ÷ Math::PI * 180
\

\1 ~ 10
--> (1 ~ 5 --> [1~2 --> 1d] --> "[$(@$_ => ",".join)]-2+7=$((@$_ => sum) - 2 + 7)"
  + ((@$_ --> $_ == 6 => and) ? " (6ゾロ)" : "")
  + ((@$_ --> $_ == 1 => and) ? " (1ゾロ)" : "")
  => "\t".join)
=> join3\
MirrgieRiana commented 8 years ago
\
$_decoration_color = $a, $text :> "<span style='color: $(*$a)'>$(*$text)</span>";
$_decoration_size = $a, $text :> "<span style='font-size: $(*$a)'>$(*$text)</span>";
$_decoration_b = $a, $text :> "<b>$(*$text)</b>";
$_decoration_br = $a, $text :> "<br>";
//$_get_concatenate = $c, () :> &($_ --> *$_ => join1);

%{
吾輩は%b(){猫}である。名前はまだ無い。%br();
どこで生れたかとんと見当がつかぬ。
何でも%color(gray){薄暗い}じめじめした所で
%size("120%"){ニャーニャー}泣いていた事だけは記憶している。
}
\
MirrgieRiana commented 8 years ago
\
$hash = {
  _get_operatorAsterisk: ($c, $a, $b :> (
    /var $a1; $a1 = *$a;
    /var $b1; $b1 = *$b;
    /instanceof $a1 $fluorite::type::Number/ ? ($a1 = [$a1, {}]) : ();
    /instanceof $b1 $fluorite::type::Number/ ? ($b1 = [$b1, {}]) : ();
    &[$a1[0] * $b1[0], (
      /var $a2; $a2 = $a1[1];
      /var $b2; $b2 = $b1[1];
      /var $e; $e = (/keys $a2/ --> [$_, $a2::$_]), (/keys $b2/ --> [$_, $b2::$_]);
      /var $hash2; $hash2 = {};
      $e --> $hash2::($_[0]) = ($hash2::($_[0]) ?? 0) + $_[1];
      {/keys $hash2/ --> ($hash2::$_ != 0 ? ($_: $hash2::$_) : ())}
    )]
  )),
  _get_operatorSlash: ($c, $a, $b :> (
    /var $a1; $a1 = *$a;
    /var $b1; $b1 = *$b;
    /instanceof $a1 $fluorite::type::Number/ ? ($a1 = [$a1, {}]) : ();
    /instanceof $b1 $fluorite::type::Number/ ? ($b1 = [$b1, {}]) : ();
    &[$a1[0] / $b1[0], (
      /var $a2; $a2 = $a1[1];
      /var $b2; $b2 = $b1[1];
      /var $e; $e = (/keys $a2/ --> [$_, $a2::$_]), (/keys $b2/ --> [$_, -$b2::$_]);
      /var $hash2; $hash2 = {};
      $e --> $hash2::($_[0]) = ($hash2::($_[0]) ?? 0) + $_[1];
      {/keys $hash2/ --> ($hash2::$_ != 0 ? ($_: $hash2::$_) : ())}
    )]
  )),
};
$_rightComposite_km = $a :> [$a * 1000, {m: 1}];
$_rightComposite_m = $a :> [$a, {m: 1}];
$_rightComposite_h = $a :> [$a * 3600, {s: 1}];
$_rightComposite_s = $a :> [$a, {s: 1}];
(
/var $_get_operatorAsterisk, $_get_operatorSlash;
$_get_operatorAsterisk = $hash::_get_operatorAsterisk;
$_get_operatorSlash = $hash::_get_operatorSlash;
$_rightComposite_kmph = $a :> _rightComposite_km($a) / 1h;
$_rightComposite_mps = $a :> _rightComposite_m($a) / 1s;

(5kmph * 10h) / (1mps * 14)

)\
MirrgieRiana commented 8 years ago
\
/class Enchanted extends Array{
  $class::new = $a, $b :> [$a, $b];
  $class::value = $this :> $this[0];
  $class::unit = $this :> $this[1];
  $class::hasUnit = $this :> /size /keys ($this.unit())/ / != 0;
  $class::reportUnits = $this, $hash, $ratio :> (
    /keys ($this.unit())/ --> $hash::$_ = ($hash::$_ ?? 0) + $this.unit()::$_ * $ratio;
  );
  $class::toString = $this :> "" + $this.value()
    + (/keys ($this.unit())/
      --> "" + $_ + ($this.unit()::$_ == 1 ? "" : "^" + $this.unit()::$_)
      => "*".join);
};
$enchanted = {
  getAdd: ($a, $b :> (
    $enchanted::getDiv($a, $b).hasUnit() ? /throw "Illegal unit"/ : ();
    /new Enchanted($a.value() + $b.value(), $a.unit())/
  )),
  getSub: ($a, $b :> (
    $enchanted::getDiv($a, $b).hasUnit() ? /throw "Illegal unit"/ : ();
    /new Enchanted($a.value() - $b.value(), $a.unit())/
  )),
  getMul: ($a, $b :>
  /new Enchanted($a.value() * $b.value(), (
    /var $hash; $hash = {};
    [$a, 1], [$b, 1] --> $_[0].reportUnits($hash, $_[1]);
    /keys $hash/ --> ($hash::$_ != 0 ? ($_: $hash::$_) : ()) ==> {$_}
  ))/),
  getDiv: ($a, $b :>
  /new Enchanted($a.value() / $b.value(), (
    /var $hash; $hash = {};
    [$a, 1], [$b, -1] --> $_[0].reportUnits($hash, $_[1]);
    /keys $hash/ --> ($hash::$_ != 0 ? ($_: $hash::$_) : ()) ==> {$_}
  ))/),
};
$hash = /li [Plus, Add] [Minus, Sub] [Asterisk, Mul] [Slash, Div] --> ($symbol, $action :> (
    _get_operator + $symbol: ($c, $a, $b :> (
      /var $a1; $a1 = *$a;
      /var $b1; $b1 = *$b;
      /instanceof $a1 $fluorite::type::Number/ ? ($a1 = /new Enchanted($a1, {})/) : ();
      /instanceof $b1 $fluorite::type::Number/ ? ($b1 = /new Enchanted($b1, {})/) : ();
      &$enchanted::(get + $action)($a1, $b1)
    )),
  ))(@$_)
  ==> {$_};
$_rightComposite_m = $a :> /new Enchanted($a, {m: 1})/;
$_rightComposite_s = $a :> /new Enchanted($a, {s: 1})/;
$_rightComposite_kg = $a :> /new Enchanted($a, {kg: 1})/;

(
/var $_get_operatorPlus, $_get_operatorMinus, $_get_operatorAsterisk, $_get_operatorSlash;
/keys $hash/ --> $$_ = $hash::$_;
$show = $a, $b :> "$($a/$b) * [$($b)]";
$_rightComposite_kmph = $a :> $a * 1km / 1h;
$_rightComposite_mps = $a :> $a * 1m / 1s;
$_rightComposite_km = $a :> $a * 1000m;
$_rightComposite_g = $a :> $a * 0.001kg;
$_rightComposite_h = $a :> $a * 3600s;
$_rightComposite_mpss = $a :> $a * 1mps / 1s;
$_rightComposite_N = $a :> $a * 1kg * 1mpss;
$_rightComposite_J = $a :> $a * 1N * 1m;
$_rightComposite_W = $a :> $a * 1J / 1s;
$_rightComposite_cal = $a :> $a * 4.18J;
$_rightComposite_kcal = $a :> $a * 1000cal;

$g = 9.8mpss;

$show(  60kg * 3776m * $g,  1kcal  )

)
\

以降動かず #289

MirrgieRiana commented 8 years ago
\
// 逆フーリエ
$"_leftMultibyte_☆" = $a :> &(
  /var $a2; $a2 = *$a --> [$_[0], -$_[1]];
  /var $N; $N = /size $a2;
  $a2 = ♨$a2;
  $a2 = $a2 --> [$_[0] / $N, $_[1] / $N];
  $a2
);

// フーリエ
$"_leftMultibyte_♨" = $a :> &(
  /var $a2; $a2 = *$a;
  /var $N; $N = /size $a2;
  0 ~ $N - 1 --> (
    /var $n; $n = $_;
    /var $re; $re = 0;
    /var $im; $im = 0;
    /var $theta2; $theta2 = 2 * Math::PI * $n / $N;
    0 ~ $N - 1 --> (
      /var $k; $k = $_;
      /var $theta; $theta = $theta2 * $k;
      /var $sin; $sin = Math::sin($theta);
      /var $cos; $cos = Math::cos($theta);
      /var $c; $c = $a2[$k];
      $re = $re + $c[0] * $cos + $c[1] * $sin;
      $im = $im + $c[1] * $cos - $c[0] * $sin;
    );
    [$re, $im]
  )
);

$f = 0 ~ 15 --> [$_, 0];
☆♨$f => join3
\
MirrgieRiana commented 8 years ago
\
$階乗 = $a :> $a == 0 ? 1 : $a * $階乗($a - 1);

sum(0~30 --> 1 / $階乗($_))
\
 \Math::E\
MirrgieRiana commented 8 years ago
\
/class G {
  $class::toBoolean = $this :> true;
};
$a = /new G({})/;
$a ? A : B
\
MirrgieRiana commented 8 years ago
\$a, b, c : Number :> [$a, $b]\
\$a : Number :> [$a, $b]\
\$a :> [$a, $b]\
\a :> [$a, $b]\
MirrgieRiana commented 8 years ago
\/try { /throw 5; } catch () { /typeof $e };\ = Error
\/try { /throw 5; } catch (e, b) { /typeof $e };\ = Error

\/try { /throw 5; } catch (e) { "Caught" };\ = Caught
\/try { /throw 5; } catch (e : Value) { "Caught" };\ = Caught
\/try { /throw 5; } catch (e : Number) { "Caught" };\ = Caught
\/try { /throw 5; } catch (e : Exception) { "Caught" };\ = Exception
\/try { /throw 5; } catch (e : String) { "Caught" };\ = Exception

\/try { 21d; } catch (e) { "Caught" };\ = Caught
\/try { 21d; } catch (e : Value) { "Caught" };\ = Caught
\/try { 21d; } catch (e : Number) { "Caught" };\ = Exception
\/try { 21d; } catch (e : Exception) { "Caught" };\ = Caught
\/try { 21d; } catch (e : String) { "Caught" };\ = Exception
MirrgieRiana commented 8 years ago
\
/class Enchanted extends Array{
  $class::new = $a, $b :> [$a, $b];
  $class::value = $this :> $this[0];
  $class::unit = $this :> $this[1];
  $class::hasUnit = $this :> /size /keys ($this.unit())/ / != 0;
  $class::reportUnits = $this, $hash, $ratio :> (
    /keys ($this.unit())/ --> $hash::$_ = ($hash::$_ ?? 0) + $this.unit()::$_ * $ratio;
  );
  $class::toString = $this :> "" + $this.value()
    + (/keys ($this.unit())/
      --> "" + $_ + ($this.unit()::$_ == 1 ? "" : "^" + $this.unit()::$_)
      => "*".join);
};
$enchanted = {
  getAdd: ($a, $b :> (
    $enchanted::getDiv($a, $b).hasUnit() ? /throw "Illegal unit"/ : ();
    /new Enchanted($a.value() + $b.value(), $a.unit())/
  )),
  getSub: ($a, $b :> (
    $enchanted::getDiv($a, $b).hasUnit() ? /throw "Illegal unit"/ : ();
    /new Enchanted($a.value() - $b.value(), $a.unit())/
  )),
  getMul: ($a, $b :>
  /new Enchanted($a.value() * $b.value(), (
    /var $hash; $hash = {};
    [$a, 1], [$b, 1] --> $_[0].reportUnits($hash, $_[1]);
    /keys $hash/ --> ($hash::$_ != 0 ? ($_: $hash::$_) : ()) ==> {$_}
  ))/),
  getDiv: ($a, $b :>
  /new Enchanted($a.value() / $b.value(), (
    /var $hash; $hash = {};
    [$a, 1], [$b, -1] --> $_[0].reportUnits($hash, $_[1]);
    /keys $hash/ --> ($hash::$_ != 0 ? ($_: $hash::$_) : ()) ==> {$_}
  ))/),
};
$hash = /li [Plus, Add] [Minus, Sub] [Asterisk, Mul] [Slash, Div] --> ($symbol, $action :> (
    _get_core_operator + $symbol: ($c, $a, $b :> (
      /var $a1; $a1 = *$a;
      /var $b1; $b1 = *$b;
      /instanceof $a1 $fluorite::type::Number/ ? ($a1 = /new Enchanted($a1, {})/) : ();
      /instanceof $b1 $fluorite::type::Number/ ? ($b1 = /new Enchanted($b1, {})/) : ();
      &$enchanted::(get + $action)($a1, $b1)
    )),
  ))(@$_)
  ==> {$_};
$rightComposite_m = $a :> /new Enchanted($a, {m: 1})/;
$rightComposite_s = $a :> /new Enchanted($a, {s: 1})/;
$rightComposite_kg = $a :> /new Enchanted($a, {kg: 1})/;

(
/var $_get_core_operatorPlus, $_get_core_operatorMinus, $_get_core_operatorAsterisk, $_get_core_operatorSlash;
/keys $hash/ --> $$_ = $hash::$_;
$show = $a, $b :> "$($a/$b) * [$($b)]";
$rightComposite_kmph = $a :> $a * 1km / 1h;
$rightComposite_mps = $a :> $a * 1m / 1s;
$rightComposite_km = $a :> $a * 1000m;
$rightComposite_g = $a :> $a * 0.001kg;
$rightComposite_h = $a :> $a * 3600s;
$rightComposite_mpss = $a :> $a * 1mps / 1s;
$rightComposite_N = $a :> $a * 1kg * 1mpss;
$rightComposite_J = $a :> $a * 1N * 1m;
$rightComposite_W = $a :> $a * 1J / 1s;
$rightComposite_cal = $a :> $a * 4.18J;
$rightComposite_kcal = $a :> $a * 1000cal;

$g = 9.8mpss;

$show(  60kg * 3776m * $g,  1kcal  )

)
\
MirrgieRiana commented 8 years ago
\
$_get_operatorLess2 = $env, $a, $b :> [$env, $a, $b];
4 << 5
\ = [get, 4, 5]
MirrgieRiana commented 8 years ago
\ 
/class Enchanted extends Array{
  $class::new = $a, $b :> [$a, $b];
  $class::value = $this :> $this[0];
  $class::unit = $this :> $this[1];
  $class::hasUnit = $this :> /size /keys ($this.unit())/ / != 0;
  $class::reportUnits = $this, $hash, $ratio :> (
    /keys ($this.unit())/ --> $hash::$_ = ($hash::$_ ?? 0) + $this.unit()::$_ * $ratio;
  );
  $class::toString = $this :> "" + $this.value()
    + (/keys ($this.unit())/
      --> "" + $_ + ($this.unit()::$_ == 1 ? "" : "^" + $this.unit()::$_)
      => "*".join);
};
$enchanted = {
  getAdd: ($a, $b :> (
    $enchanted::getDiv($a, $b).hasUnit() ? /throw "Illegal unit"/ : ();
    /new Enchanted($a.value() + $b.value(), $a.unit())/
  )),
  getSub: ($a, $b :> (
    $enchanted::getDiv($a, $b).hasUnit() ? /throw "Illegal unit"/ : ();
    /new Enchanted($a.value() - $b.value(), $a.unit())/
  )),
  getMul: ($a, $b :>
  /new Enchanted($a.value() * $b.value(), (
    /var $hash; $hash = {};
    [$a, 1], [$b, 1] --> $_[0].reportUnits($hash, $_[1]);
    /keys $hash/ --> ($hash::$_ != 0 ? ($_: $hash::$_) : ()) ==> {$_}
  ))/),
  getDiv: ($a, $b :>
  /new Enchanted($a.value() / $b.value(), (
    /var $hash; $hash = {};
    [$a, 1], [$b, -1] --> $_[0].reportUnits($hash, $_[1]);
    /keys $hash/ --> ($hash::$_ != 0 ? ($_: $hash::$_) : ()) ==> {$_}
  ))/),
};
$hash = /li [Plus, Add] [Minus, Sub] [Asterisk, Mul] [Slash, Div] --> ($symbol, $action :> (
    _get_operator + $symbol: ($c, $a, $b :> (
      /instanceof $a $fluorite::type::Number/ ? ($a = /new Enchanted($a, {})/) : ();
      /instanceof $b $fluorite::type::Number/ ? ($b = /new Enchanted($b, {})/) : ();
      $enchanted::(get + $action)($a, $b);
    )),
  ))(@$_)
  ==> {$_};
$rightComposite_m = $a :> /new Enchanted($a, {m: 1})/;
$rightComposite_s = $a :> /new Enchanted($a, {s: 1})/;
$rightComposite_kg = $a :> /new Enchanted($a, {kg: 1})/;

(
/var $_get_operatorPlus, $_get_operatorMinus, $_get_operatorAsterisk, $_get_operatorSlash;
/keys $hash/ --> $$_ = $hash::$_;
$show = $a, $b :> "$($a/$b) * [$($b)]";
$rightComposite_kmph = $a :> $a * 1km / 1h;
$rightComposite_mps = $a :> $a * 1m / 1s;
$rightComposite_km = $a :> $a * 1000m;
$rightComposite_g = $a :> $a * 0.001kg;
$rightComposite_h = $a :> $a * 3600s;
$rightComposite_mpss = $a :> $a * 1mps / 1s;
$rightComposite_N = $a :> $a * 1kg * 1mpss;
$rightComposite_J = $a :> $a * 1N * 1m;
$rightComposite_W = $a :> $a * 1J / 1s;
$rightComposite_cal = $a :> $a * 4.18J;
$rightComposite_kcal = $a :> $a * 1000cal;

$g = 9.8mpss;

$show(  60kg * 3776m * $g,  1kcal  )

)
\ = 531.1693779904306 * [4180kg*m^2*s^-2]
MirrgieRiana commented 8 years ago
\$a = $_get_operatorPlus; $_get_operatorPlus = $_get_operatorAsterisk; $_get_operatorAsterisk = $a;
$a = $_get_operatorMinus; $_get_operatorMinus = $_get_operatorSlash; $_get_operatorSlash = $a;
"" /* 算術演算子の動作を交換 */\

\10 + 20\ \10 * 20\ \10 - 20\ \10 / 20\
\ 1 * 2  +  3 / 5  -  4 * 2  +  6 / 9\ \(1 * 2) + (3 / 5) - (4 * 2) + (6 / 9)\

\$"_get_leftMultibyte_♨" =
  ($env, $a : Number :> $a ^ 0.33), // およそ3乗根を返す関数
  ($env, $a : Array :> $a[0] );     /* 最初の要素を返す関数 */\

\♨1000\ ≒ 10
\♨[A, B, C, D, E]\ = A
\♨"String"\ : 文字列型を取るものはないので例外
MirrgieRiana commented 8 years ago
\[1, 2, 3] + [4, "<" + 5 + ">", 2 + 4]\ : 未定義なので例外

\$_get_operatorPlus = ($_get_operatorPlus,
  ($env, $a : Array, $b : Array :> [@$a, @$b])); ""\

\[1, 2, 3] + [4, "<" + 5 + ">", 2 + 4]\

           ↑         ↑   ↑        ↑
           C         B   B        A

A: Number + Number
B: String + Value | Value + String
C: Array + Array
MirrgieRiana commented 8 years ago
\
/class A extends Array {
  $class::m =
    ($this : $class, $arg : Number :> A),
    ($this : $class, $arg : String :> B),
    ($this : $class, $arg : Array :> C);
};
$m =
  ($this : A, $arg : Boolean :> D),
  ($this : A, $arg : Hash :> E);
Array::m = ($this : A, $arg : Pointer :> F);
$a = /new A([])/\

\$a.m()\
\$a.m(1)\
\$a.m(a)\
\$a.m([])\
\$a.m(false)\
\$a.m({})\
\$a.m(&$a)\
\$a.m($a :> $a + 5)\

\[].m(&a)\
\[].m(1)\
MirrgieRiana commented 8 years ago
\/class Complex extends Array {
  $class::new = $r : Number, $i : Number :> [$r, $i];
  $class::toString =
    $this :> "<" + $this[0] + ($this[1] >= 0 ? " + " : " - ") + Math::abs($this[1]) + "i>";
  $class::_get_operatorPlus =
    ($env, $a : $class, $b : $class :> /new Complex($a[0] + $b[0], $a[1] + $b[1])/),
    ($env, $a : Number, $b : $class :> /new Complex($a, 0)/ + $b),
    ($env, $a : $class, $b : Number :> $a + /new Complex($b, 0)/);
  $class::_get_operatorMinus =
    ($env, $a : $class, $b : $class :> /new Complex($a[0] - $b[0], $a[1] - $b[1])/),
    ($env, $a : Number, $b : $class :> /new Complex($a, 0)/ - $b),
    ($env, $a : $class, $b : Number :> $a - /new Complex($b, 0)/);
  $class::_get_operatorAsterisk =
    ($env, $a : $class, $b : $class :> /new Complex(
      $a[0] * $b[0] - $a[1] * $b[1], $a[0] * $b[1] + $a[1] * $b[0])/),
    ($env, $a : Number, $b : $class :> /new Complex($a, 0)/ * $b),
    ($env, $a : $class, $b : Number :> $a * /new Complex($b, 0)/);
  $class::arg = $a : $class :> Math::atan2($a[1], $a[0]);
  $class::abs = $a : $class :> ($a[0] ^ 2 + $a[1] ^ 2) ^ 0.5;
  $class::exp = $a : $class :> Math::exp($a[0]) * /new Complex(Math::cos($a[1]), Math::sin($a[1]));
};
$fromPolar = $abs, $arg :> /new Complex($abs * Math::cos($arg), $abs * Math::sin($arg))/;
$rightComposite_i = $a :> /new Complex(0, $a)/; ""\

★ここからてると★

\4 + 10i\ \4 - 10i\ \4 * 10i\ \4i * 10i\       基礎
\(2 + 3i) * (4 - 5i) + 10000 + 1000i\          演算

\(10 - 10i).abs()\                             絶対値
\(10 + 10i).arg()\ = \Math::PI / 4\            偏角
\$fromPolar(10, Math::PI / 2)\                 絶対値10で偏角90度
\(2 - 2i).exp()\                               e^2 * e^-2i
MirrgieRiana commented 8 years ago
\
$random = $random ?? (),
  ($array : Array :> $array[Math::randomBetween(0, /length ($array)/ - 1)]);
\

\
$hash = {};
1~100 -->           [1, 2, 3].random()          --> $hash::("" + $_) = ($hash::("" + $_) ?? 0) + 1;
$hash
\

\/loopCount/\ / \/loopCapacity/\
MirrgieRiana commented 8 years ago
\$random = $random ?? (),
  ($array : Array :> $array[0.b(/length $array/ - 1)]);\

\
$b = Math::randomBetween;
$a = ["1", "2", "3"].random;
Object::"1" = Object::"2" = Object::"3" = 0;

1~100 -> a --> Object::$_++;

Object::"1", Object::"2", Object::"3"
\

\/loopCount/\ \/loopCapacity/\