ãæ°é±éåãGitHubãé²èŠ§ããŠããŠãèå³æ·±ããªããžããªã«åºããããŸããããããžã§ã¯ãã¯å®å šã«Nimã§äœæãããŸãããä»ãŸã§åœŒã«åºäŒã£ãããšããªãã£ãã®ã§ãä»åã¯ã©ããªåç©ãªã®ããèããŠã¿ãããšã«ããŸããã
æåãç§ã¯æ代é ãã ãšæããŸãããããã¯ãç§ãšã¯ç°ãªããå€ãã®äººãç©æ¥µçã«äœ¿çšããŠããäžè¬çãªããã°ã©ãã³ã°èšèªã®1ã€ã§ãããããŠããããå匷ããããšã«ããŸããã
ãããç§ã®çµè«ã§ãïŒ
- ãã®èšèªã¯ãå®éã«ã¯çãç¯å²ã®äººã ã®éã§äººæ°ããããŸãã
- ããããããããã¹ãã§ãã
ããã§ãNimã§ã®ç§ã®çµéšã«ã€ããŠå°ãã話ããããã®äžã®ããã°ã©ãã³ã°ã®æ©èœã«ã€ããŠç°¡åã«èª¬æããPythonãCãšæ¯èŒããŠã¿ãŸããå°æ¥çã«ã¯ããã®èšèªã¯ç§ã«ãšã£ãŠéåžžã«ææã§ããããã«æãããŸãã
ã¹ã¿ãžãªã§ã³ãŒãïŒ
äŸãšããŠãç§ã¯ããã«ã¡ã¯ãäžçãããè€éãªäœãããã ã§æžãããšã«ããŸããïŒ
ããã¯äœåãªãã®ã§ã¯ãªãããã§ãããïŒNimã®ããšãèããããšããªããŠãããããäœãããã®ããç°¡åã«ç解ã§ããã»ã©åçŽãªããã§ããïŒããã°ã©ã ã¯ãnumïŒ5 iïŒ5ããåºåããŸãïŒ
ããã§ã¯ãã©ããããç§ãã¡ã«éŠŽæã¿ããããšæããããã®ãåæããŸãããã
å€æ°å®£èš
ããã¯JavaScriptéçºè ã«ãšã£ãŠã¯ãªãã¿ã®ããããšã§ããäžéšã®èšèªã¯varã䜿çšããäžéšã¯letã䜿çšããŸãããJSãšNimã§ã¯ãå€æ°ã宣èšãããšãã«äž¡æ¹ã䜿çšã§ããŸãããã ããNimãšJSã§ã¯åäœãç°ãªãããšã«æ³šæããããšãéèŠã§ããããããããã«ã€ããŠã¯åŸã§è©³ãã説æããŸãã
ãããã¯
Nimã®æ°ãããããã¯ã瀺ãããã«ãã³ãã³ãšããã«ç¶ãã€ã³ãã³ããããè¡ã䜿çšããŸãããã¹ãŠãPythonã®ããã§ãã
ããŒã¯ãŒã
ã«ãŒããšifã¹ããŒãã¡ã³ãã¯ã©ã¡ããPythonã³ãŒãã®äžéšã®ããã«èŠããŸããå®éã5è¡ç®ä»¥éã¯ãã¹ãŠPythonã³ãŒãã§ãïŒechoé¢æ°ãå®çŸ©ãããŠãããšä»®å®ããŸãïŒã
ããã§ããå€ãã®PythonããŒã¯ãŒããšæŒç®åãNimã§äœ¿çšã§ããŸãïŒnotãisãandãorãªã©ã
ã€ãŸãããããŸã§ã®ãšãããNimã«ã¯ç¹å¥ãªããšã¯äœããããŸãã
ãå€æ°ã宣èšããããã«letãŸãã¯varã䜿çšããå¿ èŠããããšããäºå®ãèæ ®ãããšãPythonã®ææªã®ããŒãžã§ã³ïŒæ§æã®èŠ³ç¹ããïŒã§ãã
ããã§ãããããšãã§ããŸããã倧ããªãããããããããŸããNimã¯éçã«åä»ããããèšèªã§ãããCèšèªãšã»ãŒåãé床ã§åäœããŸãã
ããŠãå¥ã®äŒè©±ã«ç§»ããŸããããããããã§ãã¯ãããã
æ§èœãã¹ã
Nimã®æ§æïŒç¹ã«ãããŸã§èŠãŠããªãéçã«åä»ããããéšåïŒã«é£ã³èŸŒãåã«ããã®ããã©ãŒãã³ã¹ãè©äŸ¡ããŠã¿ãŸãããããããè¡ãããã«ãNimãPythonãCã§nçªç®ã®Fibonacciæ°ãèšç®ããããã®åçŽãªå®è£ ãäœæããŸããã
å ¬å¹³ãæãããã«ãLeetcodeãœãªã¥ãŒã·ã§ã³ïŒãªãã·ã§ã³1ïŒã«åºã¥ããŠå®è£ ãæšæºåãã3ã€ã®èšèªãã¹ãŠã§å¯èœãªéãå³å¯ã«æºæ ããããã«ããŸããã
ãã¡ãããLRUãã£ãã·ã¥ã«ã€ããŠæãåºãããããšãã§ããŸãããããä»ã®ãšãããç§ã®ä»äºã¯æšæºçãªã¢ãããŒãã䜿çšããããšã§ãããèšç®ãæé©åããããšã¯ããŠããŸãããã ããç§ã¯çŽ æŽãªå®è£ ãéžã³ãŸããã
40çªç®ã®ãã£ããããæ°ãèšç®ããçµæã¯æ¬¡ã®ãšããã§ãã
ã¯ããå³å¯ã«èšãã°ãå®éšã¯çŽç²ãšã¯èšããŸããããããã¯ããæ·±å»ãªãã¹ããè¡ã£ãä»ã®æ奜家ã®çµæãšçžé¢ããŠããŸã[1] [2] [3]ã
ãã®èšäºã®ããã«æžãããã¹ãŠã®ã³ãŒãã¯ããã®å®éšã®å®è¡æ¹æ³ã®èª¬æãå«ããGitHubã§å ¥æã§ããŸãã
ã§ã¯ããªãNimã¯Pythonãããã¯ããã«é«éãªã®ã§ããïŒ
ãããšãç§ã¯2ã€ã®äž»ãªçç±ããããšæããŸãïŒ
- Nimã¯ã³ã³ãã€ã«ãããèšèªã§ãããPythonã¯è§£éãããèšèªã§ãïŒè©³çŽ°ã¯ãã¡ãïŒãããã¯ãPythonããã°ã©ã ãå®è¡ããåã«ããã°ã©ã ã解éããå¿ èŠããããããPythonããã°ã©ã ãå®è¡ãããšããå€ãã®äœæ¥ãè¡ãããããšãæå³ããŸããããã¯éåžžãèšèªãé ãããŸãã
- Nimã¯éçã«å ¥åãããŸããåã«ç€ºããäŸã«ã¯å宣èšã¯ãããŸããã§ããããå®éã«éçã«åä»ããããèšèªã§ããããšãåŸã§ããããŸããåçã«åä»ããããPythonã®å Žåãåãé©åã«å®çŸ©ããŠåŠçããããã«ãã€ã³ã¿ãŒããªã¿ãŒã¯ããã«å€ãã®äœæ¥ãè¡ãå¿ èŠããããŸãããŸããããã©ãŒãã³ã¹ãäœäžããŸãã
äœæ¥é床ãåäžããŸã-ã³ãŒãã£ã³ã°é床ãäœäžããŸã
ããã§ã¯äœã®Pythonããã¥ã¡ã³ãã¯ã€ã³ã¿ããªã¿èšèªã«ã€ããŠããè¿°ã¹ãŠããŸãã
« / , , ».
ããã¯ãããšãã°PythonãšCã®éã®ãã¬ãŒããªãã®è¯ãäžè¬åã§ããPythonã§ã§ããããšã¯äœã§ããCã§ãã§ããŸãããCããã°ã©ã ã¯äœåãéãå®è¡ãããŸãã
ãã ããCã³ãŒãã®èšè¿°ãšãããã°ã«å€ãã®æéãè²»ãããããç ©éã§èªã¿ã«ãããªããŸãããã®ãããCã¯ãã¯ãéèŠããªããPythonã人æ°ããããŸããèšãæããã°ãPythonã¯ã¯ããã«åçŽã§ãïŒãã¡ãããæ¯èŒçïŒã
ãããã£ãŠãPythonãã¹ãã¯ãã«ã®äžæ¹ã®ç«¯ã«ãããCãããäžæ¹ã®ç«¯ã«ããå ŽåãNimã¯äžéã®ã©ããã«å°éããããšããŠããŸããPythonãããã¯ããã«é«éã§ãããCã»ã©ããã°ã©ãã³ã°ã¯é£ãããããŸãã
ãFibonacciæ°ã®èšç®ã®å®è£ ãèŠãŠã¿ãŸãããã
ããïŒ
#include <stdio.h>
int fibonacci(int n) {
if (n <= 1) {
return n;
}
return fibonacci(n-1) + fibonacci(n-2);
}
int main(void) {
printf("%i", fibonacci(40));
}
PythonïŒ
def fibonacci(n):
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
print(fibonacci(40))
ãã ïŒ
proc fibonacci(n: int): int =
if n <= 1:
return n
return fibonacci(n-1) + fibonacci(n-2)
echo(fibonacci(40))
Nimã¯ããã·ãŒãžã£ïŒé¢æ°ïŒæ§æã§ã=ãèšå·ã䜿çšããŸãããäžè¬ã«Cãããã³ãŒããæžãæ¹ãã¯ããã«ç°¡åã§ãã
ããããããã¯æ¬åœã«äŸ¡å€ã®ãããã¬ãŒããªãã§ããïŒPythonãããæžãã®ã¯å°ãé£ããã§ããã10åéãåäœããŸããç§ã¯ãããšäžç·ã«æ®ããããšãã§ããŸããã
Nimæ§æ
import strformat
# https://nim-lang.org/
type
Person = object
name: string
age: Natural #
let people = [
Person(name: "John", age: 45),
Person(name: "Kate", age: 30)
]
for person in people:
echo(fmt"{person.name} is {person.age} years old")
äž»ãªæ©èœã玹ä»ããŸãã
å€æ°
varãletããŸãã¯constã䜿çšããŠå€æ°ã宣èšããŸãã
varãšconstã¯JavaScriptãšåãããã«æ©èœããŸããã話ã¯ç°ãªããŸãã
JavaScript letã¯ã¹ã³ãŒãã®ç¹ã§varãšã¯ç°ãªããNimletã¯åæååŸã«å€ãå€æŽã§ããªãå€æ°ã瀺ããŸããç§ã«ã¯Swiftã®ããã«èŠããŸãã
ããããããã¯å®æ°ãšåãã§ã¯ãããŸãããïŒ- ããªããå°ããã
çªå·ãNimã§ã¯ãconstãšletã®éãã¯æ¬¡ã®ãšããã§ãã
constã®å Žåãã³ã³ãã€ã©ã¯ã³ã³ãã€ã«æã«å€ã決å®ã§ããå¿ èŠããããŸãããletã®å Žåãå®è¡æã«æ±ºå®ã§ããŸãã
ããã¥ã¡ã³ãããã®äŸïŒ
const input = readLine(stdin) # Error: constant expression expected
let input = readLine(stdin) #
ãŸãã¯ãå€æ°ã次ã®ããã«å®£èšããŠåæåããããšãã§ããŸãã
var
a = 1
b = 2
c = 3
x, y = 10 # x y 10
æ©èœ
Nimã®é¢æ°ã¯ããã·ãŒãžã£ãšåŒã°ããŸãã
proc procedureName(parameterName: parameterType):returnType =
return returnVar
èšèªãå€ãã®ç¹ã§Pythonã«äŒŒãŠããããšãèãããšãæåã«èŠããšãã®æé ã¯å°ãå¥åŠã«æããŸãã
ã{ããŸãã¯ãïŒãã®ä»£ããã«ã=ãã䜿çšãããšãæããã«æ··ä¹±ããŸããããã·ãŒãžã£ã1è¡ã§èšè¿°ãããšããã¹ãŠãå°ãè¯ããªããŸãã
proc hello(s: string) = echo s
é¢æ°ã®çµæãååŸããããšãã§ããŸãã
proc toString(x: int): string =
result =
if x < 0: ânegativeâ
elif x > 0: âpositiveâ
else: âzeroâ
ã©ããããããçµæãè¿ãå¿ èŠãããããã«æããŸããããã®å Žåãçµæã¯å€æ°ã§ã¯ãªããããŒã¯ãŒãã§ãããããã£ãŠãäžèšã®ã³ãŒãã¹ããããã¯ãNimã®èŠ³ç¹ããã¯æ£ãããã®ã«ãªããŸãã
æé ããªãŒããŒããŒãããããšãã§ããŸãã
proc toString(x: int): string =
result =
if x < 0: "negative"
elif x > 0: "positive"
else: "zero"
proc toString(x: bool): string =
result =
if x: "yep"
else: "nope"
echo toString(true) # "yep"
echo toString(5) # "positive"
æ¡ä»¶ãšãµã€ã¯ã«
ããã¯Pythonãšå€ãã®é¢ä¿ããããŸãã
# if true:
# while true:
# for num in nums:
ããšãã°ãç¯å²ïŒïŒã®ä»£ããã«ãªã¹ããå埩åŠçããã«ã¯ãã«ãŠã³ãã¢ããïŒéå§ãçµäºïŒãŸãã¯ã«ãŠã³ãããŠã³ïŒéå§ãçµäºïŒã䜿çšã§ããŸããããªãã¯ãããããã«ç°¡åã«è¡ãããšãã§ããstart..finishã§iã«äœ¿çšã§ããŸã
ãŠãŒã¶ãŒã®å ¥åãšåºå
let input = readLine(stdin)
echo input
Pythonãšæ¯èŒãããšãreadLineïŒstdinïŒã¯inputïŒïŒãšåçã§ãããechoã¯printãšåçã§ãã
ãšã³ãŒã¯ãæ¬åŒ§ã®æç¡ã«ããããã䜿çšã§ããŸãã
ç§ã®ç®æšã¯ãNimã®åºæ¬çãªç解ãæäŸããããšã§ããããã¹ãŠã®ããã¥ã¡ã³ããå説æããããšã§ã¯ãããŸãããã ããç§ã¯æ§æã«è¡ãçããèšèªã®ä»ã®æ©èœã«ç§»ããŸãã
è¿œå æ©èœ
ãªããžã§ã¯ãæåããã°ã©ãã³ã°
Nimã¯ãªããžã§ã¯ãæåã®èšèªã§ã¯ãããŸãããããªããžã§ã¯ãã®æäœã«å¯ŸãããµããŒãã¯æå°éã§ãããã¡ããã圌ã¯Pythonã¯ã©ã¹ããã¯ã»ã©é ãã§ãã
ãã¯ã
Nimã¯ãã¯ããšã¡ã¿ããã°ã©ãã³ã°ããµããŒãããŠãããéçºè ã¯ããã«å€ãã®éç¹ã眮ããŠããããã§ããããã¯ã3ã¬ãã¹ã³ã·ãªãŒãºã®ç¬èªã®ã»ã¯ã·ã§ã³ã®äž»é¡ã§ãã
å°ããªäŸïŒ
import macros macro myMacro(arg: static[int]): untyped =
echo arg
myMacro(1 + 2 * 3)
åºæ¬çãªããŒã¿ã¿ã€ã
string, char, bool, int, uint float.
次ã®ã¿ã€ãã䜿çšã§ããŸãã
int8, int16, int32, int64, uint8, uint16, uint32, uint64, float32, float64
ããã«ãNimã®æååã¯ãPythonãšã¯ç°ãªããå¯å€åã§ãã
ã³ã¡ã³ã
Pythonãšã¯ç°ãªããNimã¯è€æ°è¡ã®ã³ã¡ã³ãã«ã[ãããã³ã]ããšçµã¿åãããŠãïŒãæåã䜿çšããŸãã
# a comment#[
a
multi
line
comment
]#
JavaScriptã®ã³ã³ãã€ã«
Nimã¯ãã®ã³ãŒããJavaScriptã«å€æã§ããŸããå€ãã®äººãããã䜿çšããããã«æ¥ããã©ããã¯ããããŸãããããããNimã§æžãããSnakeãã©ãŠã¶ã²ãŒã ã®ãã®ãããªäŸããããŸãã
ã€ãã¬ãŒã¿ãŒ
Nimã€ãã¬ãŒã¿ãŒã¯Pythonãžã§ãã¬ãŒã¿ãŒã«äŒŒãŠããŸãã
iterator countup(a, b: int): int =
var res = a
while res <= b:
yield res
inc(res)
倧æå
ãšå°æåã®åºå¥ãšã¢ã³ããŒã¹ã³ã¢Nimã¯ãæåã®æåã«å¯ŸããŠã®ã¿å€§æåãšå°æåãåºå¥ããŸãã
ã€ãŸããHelloWorldãšhelloWorldã¯åºå¥ãããŸãããhelloWorldãhelloworldãããã³hello_worldã¯åºå¥ãããŸããããããã£ãŠã次ã®æé ã¯åé¡ãªãæ©èœããŸããããšãã°ã次ã®ããã«ãªããŸãã
proc my_func(s: string) =
echo myFunc("hello")
ãã ã¯ã©ãããã人æ°ããããŸããïŒ
Nimã¯GitHubã«10,000è¿ãã®æãæã£ãŠããŸããããã¯æãããªãã©ã¹ã§ããããã«ãããããããç§ã¯ä»ã®æ å ±æºããèšèªã®äººæ°ãæšå®ããããšããŸããããããŠãã¡ãããããã¯ããã»ã©é«ãã¯ãããŸããã
ããšãã°ãNimã¯2020幎ã®ã¹ã¿ãã¯ãªãŒããŒãããŒèª¿æ»ã§ãèšåãããŠããŸããã§ãããLinkedInã§Niméçºè ã®ä»äºãèŠã€ããããšãã§ããŸããã§ããïŒWorldwide geographyã§ãïŒãStackOverflowã§[nim-lang]ã¿ã°ãæ€çŽ¢ãããšã349ã®è³ªåããè¿ãããŸããã§ããïŒPythonã®å Žåã¯çŽ1,500,000ãSwiftã®å Žåã¯270,000ãšæ¯èŒããŠãã ããïŒ
ããããã£ãŠãã»ãšãã©ã®éçºè ã¯ããã䜿çšããããšããªããå€ãã®éçºè ã¯Nimèšèªã«ã€ããŠèããããšããªããšæ³å®ããã®ã劥åœã§ãã
Pythonã眮ãæããïŒ
æ£çŽãªãšããããã ã¯ããªãã¯ãŒã«ãªèšèªã ãšæããŸãããã®èšäºãæžãããã«ãç§ã¯å¿ èŠæå°éãç 究ããŸããããããããã¯ååã§ãããããŸãæ·±ãæãäžããŠããŸããããå°æ¥çã«ã¯Nimã䜿ãäºå®ã§ããå人çã«ã¯Pythonã®å€§ãã¡ã³ã§ãããéçã«åä»ããããèšèªã奜ãã§ãããããã£ãŠãç§ã«ãšã£ãŠã¯ãããã©ãŒãã³ã¹ã®åäžã«ãããæ§æã®ããããªåé·æ§ãè£ãããå ŽåããããŸãã
åºæ¬çãªæ§æã¯Pythonãšéåžžã«äŒŒãŠããŸãããããè€éã§ãããããã£ãŠãã»ãšãã©ã®Pythonãã¡ã³ã¯ããããããã«èå³ããªãã§ãããã
ãŸããGoèšèªãå¿ããªãã§ãã ãããããªããèªãã§ãããšãã«ãããªãæ¹ã®å€ããããã«ã€ããŠèããããšããããšç§ã¯ç¢ºä¿¡ããŠããŸãããããŠåœç¶ããã§ãã Nimã®æ§æã¯Pythonã®æ§æã«è¿ããšããäºå®ã«ãããããããããã©ãŒãã³ã¹ã®ç¹ã§ã¯ããç°¡ç¥åãããC ++ãã®èšèªãšæ£ç¢ºã«ç«¶åããŸãã
ç§ã¯ãã€ãŠGoã®ããã©ãŒãã³ã¹ããã¹ãããŸãããç¹ã«ãFibonacciïŒ40ïŒã®å ŽåãCãšåãéãã§åäœããŸããã
ããããããã§ãïŒNimã¯Pythonãšç«¶åã§ããŸããïŒç§ã¯ãããéåžžã«çã£ãŠããŸããã³ã³ãã¥ãŒã¿ãŒã®ããã©ãŒãã³ã¹ãåäžãããããã°ã©ãã³ã°ãç°¡çŽ åããåŸåãèŠãããŸãããããŠãç§ãè¿°ã¹ãããã«ãNimãåªããæ§æãšããã©ãŒãã³ã¹ã®ãã¬ãŒããªããæäŸãããšããŠããçŽç²ã§çšéã®åºãPythonãæã¡è² ããã«ã¯ååã§ã¯ãªããšæããŸãã
NimCoreéçºè ã®1人ãšè©±ãããŸããã圌ã¯ãNimã¯pythonistsãããC ++ãã移è¡ãã人ã«é©ããŠãããšèããŠããŸãã
Nimã¯Goãšç«¶äºã§ããŸããïŒããããïŒGoogleããèš±å¯ãããŠããå ŽåïŒãNimèšèªã¯Goãšåãããã匷åã§ããããã«ãNimã¯ããã¯ãããªãŒããŒããŒããªã©ãC / C ++æ©èœãããé©åã«ãµããŒãããŠããŸãã
ããããããã«ã€ããŠã¯æ¬¡åã®ãã€ãã«ã€ããŠãã£ãšã
åºå
EpicãµãŒããŒã¯ãAMDã®ããã»ããµãŒãæ倧3.4GHzã®CPUã³ã¢åšæ³¢æ°ãåããæé ãªäŸ¡æ Œã®ä»®æ³ãµãŒããŒã§ããæ倧æ§æã§ã¯ã128åã®CPUã³ã¢ã512 GBã®RAMã4000GBã®NVMeããã«ã«äœ¿çšã§ããŸãã泚æãæ¥ãã§ãã ããïŒ