Julia Juno Jupyter part1 [無断転載禁止]©2ch.net

1デフォルトの名無しさん
垢版 |
2016/02/12(金) 19:05:13.83ID:zhNvVfnf
LLVM で動く Julia のお勉強
Python に少し似てネイティブの速さで動く素敵な関数型言語
http://julialang.org/
http://junolab.org/
http://jupyter.org/

関連
Pythonista のための Julia 100 問 100 答
http://bicycle1885.hatenablog.com/entry/2014/12/23/170745
2016/07/22(金) 11:45:49.87ID:f6dSUOKk
>>7-11 >>25 >>28 >>30-32
定義はmacro使うと楽

macro c(restype, fnc, argtypes)
local args = [symbol("a", n) for n in 1:length(argtypes.args)]
quote
$(esc(fnc))($(args...)) = ccall($(string(fnc)), $restype, $argtypes, $(args...))
end
end

@c UInt32 printf (Ptr{Cchar},)
@c UInt32 printf (Ptr{Cchar}, UInt32,)

printf(pointer(Array{UInt8,1}([65,66,0,67,68,0,0])))
printf("%s\n", pointer(Array{UInt8,1}([65,66,0,67,68,0,0])))

macro m(lib, restype, fnc, argtypes)
local args = [symbol("a", n) for n in 1:length(argtypes.args)]
quote
$(esc(fnc))($(args...)) = ccall(($(string(fnc)), $(Expr(:quote, lib))), $restype, $argtypes, $(args...))
end
end

@m libcurl Cint curl_free (Ptr{Void},)
@m libcurl Ptr{Cchar} curl_getenv (Ptr{Cchar},)
@m libcurl Ptr{Cchar} curl_version ()

v = curl_getenv("TZ")
printf(v)
curl_free(v)
printf(curl_version())
2016/07/22(金) 11:49:20.02ID:f6dSUOKk
>>9

macro w(lib, restype, fnc, argtypes)
local args = [symbol("a", n) for n in 1:length(argtypes.args)]
quote
$(esc(fnc))($(args...)) = ccall(($(string(fnc)), $(Expr(:quote, lib))), stdcall, $restype, $argtypes, $(args...))
end
end

@w user32 UInt32 MessageBoxA (UInt32, Ptr{Cchar}, Ptr{Cchar}, UInt32,)

MessageBoxA(C_NULL, "hage", "title", 1)
レスを投稿する

5ちゃんねるの広告が気に入らない場合は、こちらをクリックしてください。

ニューススポーツなんでも実況