我有三个函数可以找到列表的第n个元素:
nthElement :: [a] -> Int -> Maybe a
nthElement [] a = Nothing
nthElement (x:xs) a | a <= 0 = Nothing
| a == 1 = Just x
| a > 1 = nthElement xs (a-1)
nthElementIf :: [a] -> Int -> Maybe a
nthElementIf [] a = Nothing
nthElementIf (x:xs) a = if a <= 1
then if a <= 0
then Nothing
else Just x -- a == 1
else nthElementIf xs (a-1)
nthElementCases :: [a] …
Run Code Online (Sandbox Code Playgroud) 而不是这个:
a = {"foo": None, "bar": None}
Run Code Online (Sandbox Code Playgroud)
有没有办法写这个?
b = {"foo", "bar"}
Run Code Online (Sandbox Code Playgroud)
并且仍然允许b
持续时间访问(即不是Python集,无法键入)?
给定一个简单的文件加载功能,
std::string load_file(const std::string &filename) {
std::ifstream file(filename);
std::string line;
std::stringstream stream;
while (std::getline(file, line)) {
stream << line << "\n";
}
return stream.str();
}
Run Code Online (Sandbox Code Playgroud)
为什么以下打印another_file
两次内容?
const char *some_file = load_file("some_file").c_str();
const char *another_file = load_file("another_file").c_str();
printf("%s", some_file);
printf("%s", another_file);
Run Code Online (Sandbox Code Playgroud) 对于以下代码段(可通过Go Playground运行),
package main
import (
"fmt"
"net/http"
"reflect"
"runtime"
)
type User struct{}
var u = &User{}
func (_ User) DummyHandler(w http.ResponseWriter, r *http.Request) {}
func funcName(i interface{}) {
p := reflect.ValueOf(i).Pointer()
n := runtime.FuncForPC(p).Name()
fmt.Println(n)
}
func main() {
funcName(u.DummyHandler)
}
Run Code Online (Sandbox Code Playgroud)
输出为main.(User).DummyHandler-fm
。
为什么-fm
函数名称的末尾有一个?
我正在学习现代3D图形编程,我正在尝试运行"你好,世界!" 三角计划.但是,我收到此错误:
jason@ubuntu:~/Desktop/Tutorial 0.3.8/Tut 01 Hello Triangle$ ./Tut\ 01\ Main
freeglut (./Tut 01 Main): glXCreateContextAttribsARB not found
Run Code Online (Sandbox Code Playgroud)
运行'glxinfo'给了我这个:
jason@ubuntu:~/Desktop/Tutorial 0.3.8/Tut 01 Hello Triangle$ glxinfo | grep OpenGL
OpenGL vendor string: Tungsten Graphics, Inc
OpenGL renderer string: Mesa DRI Intel(R) Ironlake Mobile
OpenGL version string: 2.1 Mesa 7.11
OpenGL shading language version string: 1.20
OpenGL extensions:
Run Code Online (Sandbox Code Playgroud)
'lspci'命令给了我这个:
jason@ubuntu:~/Desktop/Tutorial 0.3.8/Tut 01 Hello Triangle$ lspci | grep "VGA"
00:02.0 VGA compatible controller: Intel Corporation Core Processor Integrated Graphics Controller (rev 02) …
Run Code Online (Sandbox Code Playgroud) 对于Python dicts,可以做到
a = {'b': 5}
c = a.get('c', 0)
Run Code Online (Sandbox Code Playgroud)
以便在密钥不存在时具有默认值.Python实例变量是否有类似的"默认值"功能?
python ×2
c++ ×1
case ×1
dictionary ×1
freeglut ×1
go ×1
haskell ×1
if-statement ×1
mesa ×1
opengl ×1
reflection ×1
string ×1