Open MirrgieRiana opened 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 : Enchanted, $b : Enchanted :>
$enchanted::(get + $action)($a, $b)),
($c, $a : Number, $b : Enchanted :>
$enchanted::(get + $action)(/new Enchanted($a, {})/, $b)),
($c, $a : Enchanted, $b : Number :>
$enchanted::(get + $action)($a, /new Enchanted($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})/;
/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]
\
/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::$_) : ()) ==> {$_}
))/),
getSqrt: ($a :>
/new Enchanted(Math::sqrt($a.value()), (
/keys ($a.unit())/ --> ($_: $a.unit()::$_ / 2) ==> {$_}
))/),
};
$hash = /li [Plus, Add] [Minus, Sub] [Asterisk, Mul] [Slash, Div]
--> ($symbol, $action :> (
_get_operator + $symbol: (
($c, $a : Enchanted, $b : Enchanted :>
$enchanted::(get + $action)($a, $b)),
($c, $a : Number, $b : Enchanted :>
$enchanted::(get + $action)(/new Enchanted($a, {})/, $b)),
($c, $a : Enchanted, $b : Number :>
$enchanted::(get + $action)($a, /new Enchanted($b, {})/)),
)
))(@$_)
==> {$_};
$"_get_leftMultibyte_√" = ($"_get_leftMultibyte_√" ?? ()),
($env, $a : Enchanted :> $enchanted::getSqrt($a));
$rightComposite_s = $a :> /new Enchanted($a, {s: 1})/;
$rightComposite_m = $a :> /new Enchanted($a, {m: 1})/;
$rightComposite_kg = $a :> /new Enchanted($a, {kg: 1})/;
$rightComposite_A = $a :> /new Enchanted($a, {A: 1})/;
$rightComposite_K = $a :> /new Enchanted($a, {K: 1})/;
$rightComposite_mol = $a :> /new Enchanted($a, {mol: 1})/;
$rightComposite_cd = $a :> /new Enchanted($a, {cd: 1})/;
/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;
$rightComposite_Hz = $a :> $a / 1s;
$rightComposite_kHz = $a :> $a * 1Hz * 1000;
$rightComposite_MHz = $a :> $a * 1Hz * 1000 * 1000;
$rightComposite_C = $a :> $a * 1A * 1s;
$rightComposite_V = $a :> $a * 1J / 1C;
$rightComposite_ohm = $a :> $a * 1V / 1A;
$rightComposite_kohm = $a :> $a * 1ohm * 1000;
$rightComposite_Mohm = $a :> $a * 1ohm * 1000 * 1000;
$rightComposite_F = $a :> $a * 1C / 1V;
$rightComposite_pF = $a :> $a * 1F / 1000 / 1000 / 1000 / 1000;
$rightComposite_Fpm = $a :> $a * 1F / 1m;
$rightComposite_Vpm = $a :> $a * 1V / 1m;
$rightComposite_Cpmm = $a :> $a * 1C / 1m / 1m;
$rightComposite_S = $a :> $a / 1ohm;
$rightComposite_Spm = $a :> $a * 1S / 1m;
$rightComposite_Wb = $a :> $a * 1V * 1s;
$rightComposite_T = $a :> $a * 1Wb / 1m / 1m;
$rightComposite_Apm = $a :> $a * 1A / 1m;
$rightComposite_ApWb = $a :> $a * 1A / 1Wb;
$rightComposite_H = $a :> $a * 1Wb / 1A;
$rightComposite_uH = $a :> $a * 1H / 1000 / 1000;
$rightComposite_Hpm = $a :> $a * 1H / 1m;
$g = 9.8mpss;$show( 60kg * 3776m * $g, 1kcal )
\ = 531.1693779904306 * [4180kg*m^2*s^-2]
\2mps * 4s\ = 8m
\
$C = 150.8pF;
$L = 93.9uH;
$show( 1 / (2 * Math::PI * √($L * $C)) , 1kHz)
\
\$show( 1 / (2 * Math::PI * √(93.9uH * 150.8pF)) , 1kHz)\
\$a=&($b+$b+"]"+%A[B;*$a\]A);
$b=%B[\$a=&($b+$b+"]"+%A[B;*$a\]A);
$b=%B[]B;*$a\
\$_get_core_operatorPlus = $env, $l, $r :> (
&( *$l.bind($env::scope) * *$r.bind($env::scope) )
);
4 + 5\ = 20
\
$π = 3.14;
$π
\
\{a: g, k: y}.keys()\
\"aiu".length()\
\(1~5).length()\
\[a,b,c].length()\
\(a: 5).key()\
\(a: 5).value()\
\$font = $text, $color, $size :>
"<font color='$color' size='$size'>$text</font>"\
\%font(red, 4){TES}\
\%font(red, 4);\
\
/class std extends Pointer {
$class::new = () :> (/var $a; $a = (); &$a);
$class::_get_operatorLess2 = $env, $this, $str :>
(*$this = *$this, $str; $this);
};
std::cout = /new std();
std::endl = "\n";
std::cout << "a" << std::endl;
std::cout << 6 << std::endl;
std::cout << "c" << std::endl;
*std::cout => join1
\
\
$rept = $a : String, $b : Number :> 1~$b --> $a => join1;
1~10 --> 2d -> "|".rept => join3
\
\
$i = $text :> "<i>$text</i>";
%i{斜体}
\
\a :> 0\
\a : Number :> 0\
\a : Number... :> 0\
\$a : Number..., b : String :> 0\
\(a) :> 0\
\($a) :> 0\
\(a : Number...) :> 0\
\(a : Number..., b : String) :> 0\
\$J = $sep : String, $strs : String... :> join($sep, $strs)\
\$J("|", 2, 3, 4)\
\$J("|", "2", "3", "4")\
\$J2 = $strs : String..., $sep : Number :> join("" + $sep, $strs)\
\$J2("|", "2", "3", 4)\
\1 ~ 5 => sum\
\1 ~ 5 -> 10.sum\
\1 ~ 5 --> $_ * 10\
\1 ~ 5 ==> [$_, $_]\
\/call operatorPlus 30 4/\
\$t = 0;/class A extends Array {
$class::new = n :> [1 ~ $n];
$class::init = $this :> $t++;
}; [/new A(4)/, $t]\
\Math::PI.(Math::sin)()\
\$SIN = Math::sin\
\Math::PI.SIN()\
\1 ~ 5 -> SIN\
\$color = $text, $args : Value... :> [$text, [$args]]\
\%color(a, b, c){Text}\
\%color{Text}\
\%color;\
\`SIN` 1\
\$SIN2 = $a :> `SIN` $a\
\$SIN3 = $a, $b :> `SIN` $a\
\`SIN2` 1\
\1 `SIN2` 2\
\`SIN3` 1\
\1 `SIN3` 2\
\2d\
\2d6\
\$K =
($a :> [$a]),
($a, $b :> [$a, $b])\
\1K\
\1K2\
\$JOIN5 = $a : Number..., $b : Boolean :> [$a => sum], $b\
\1 ~ 10 => false!JOIN5\
\0 ~ 10 --> $_ / 10 -> 1!(Math::atan2) --> $_ / Math::PI * 180 => join3\