built-in

Using Python's max function when you have a variable named max?

回眸只為那壹抹淺笑 提交于 2019-12-06 12:02:47
问题 Python includes the built in max() function. However, despite it being built in it is not a keyword. That is to say, you are allowed to do max=4 . This makes sense since the maximum of something comes up a lot. But! If you use max as a variable, then it disables use of the max function in that scope. So if you do: max = 4 max(1, 2) You will get an error of int object not callable . Again, makes sense. But is there any way to specify that you would like the max function? Like a std.max() ?

Intrinsic __lzcnt64 returns different values with different compile options

北战南征 提交于 2019-12-06 08:52:11
问题 I have the following code: #include <stdint.h> #include <stdio.h> #include <x86intrin.h> long long lzcnt(long long l) { return __lzcnt64(l); } int main(int argc, char** argv) { printf("%lld\n", lzcnt(atoll(argv[1]))); return 0; } Running with different compilers and options I get (assembly shown): Clang $ clang -Wall src/test.c -D__LZCNT__ && ./a.out 2047 53 0000000000400560 <lzcnt>: 400560: 55 push %rbp 400561: 48 89 e5 mov %rsp,%rbp 400564: 48 89 7d f0 mov %rdi,-0x10(%rbp) 400568: 48 8b 7d

plain js to select element by attribute name starts with

天涯浪子 提交于 2019-12-06 03:11:16
问题 Context : HTML <div ng-me=""></div> <div ng-you=""></div> <p ng-you=""></p> I want to select all elements which has attribute name starts with ng- . Using jQuery , the following links are the closest threads to this issue : jQuery - How to select value by attribute name starts with . How to remove all Attributes by attribute name starts with . However ,the first uses jQuery , and the second resolves removing issue of already selected elements NOT selection . I try this : document

How to stop myself overwriting Python functions when coding?

馋奶兔 提交于 2019-12-06 01:49:57
问题 A source of constant headache when tracking down bugs in my Python code are seemingly innocuous snippets like this: list = ['a', 'b', 'c', 'c'] list(set(list)) This fails because I've overwritten the function list() with the variable list. A contrived example obviously, but the point is Python happily lets me overwrite built-in functions with variables. I realise this is a crucial feature in Python but I would quite like it if the interpreter would warn me when I do it in my code as I usually

Built-in functions in c++

对着背影说爱祢 提交于 2019-12-05 19:27:29
I was browsing through some codes at the end of the contest and found out that many people were using functions like __gcd(int,int) . What are these functions ? Similar functions include __builtin_popcount(int) __builtin_ctz(int) __builtin_clz(int) Where can I study about these functions ? Googling it didn't help much. Those are all GCC specifics. you can read about them here: http://gcc.gnu.org/onlinedocs/gcc/C-Extensions.html#C-Extensions - but be aware, they're NOT C/C++ Standards. 来源: https://stackoverflow.com/questions/13443463/built-in-functions-in-c

Replace Pythons builtin type with custom one

守給你的承諾、 提交于 2019-12-05 14:13:58
Is it possible to replace some built-in python types with custom ones? I want to create something like: class MyInt(object): ... __builtin__.int = MyInt x = 5 Since you want to write a Pythonesque DSL, you have two options: Compile the code to an AST and walk the AST replacing nodes as appropriate. Build your own AST by hand. Once you have the AST you can go ahead and execute it directly. In either case, look at Python's Language Services for generation and manipulation of the AST. You seem to be asking if it's possible to override the type that is created when you enter literals . The answer

__sync_val_compare_and_swap vs __sync_bool_compare_and_swap

荒凉一梦 提交于 2019-12-05 13:02:35
I've been thinking about the return values of these two functions. The __sync_bool_compare_and_swap function's return value seems to have obvious benefits, i.e. I can use it to tell whether the swap operation took place. However I can't see a good use of __sync_val_compare_and_swap's return value. Firstly, lets have a function signature for reference (from GCC docs minus the var args): type __sync_val_compare_and_swap (type *ptr, type oldval type newval); The problem I see is that the return value of __sync_val_compare_and_swap is the old value of the *ptr. To be precise, it's the value which

Are built-in intrinsic functions available in Swift 3?

不问归期 提交于 2019-12-05 13:01:32
I can see various built-in functions (like __builtin_popount, __builtin_clz, etc) in the Xcode auto-completion pop-up. I'm not sure where these are getting picked up from though. Command clicking doesn't lead to a swift definition or any documentation. Are any __builtin_* or equivalent intrinsic functions available in Swift 3 and if so, what modules do I need to include and how can I call them? 来源: https://stackoverflow.com/questions/41353482/are-built-in-intrinsic-functions-available-in-swift-3

How to shadow python builtin pwd module

北城余情 提交于 2019-12-05 10:24:38
There is some python code that works under Linux. It uses the pwd module in a way like that: import pwd ... def func(): user=pwd.getpwnam(user)[2] Now we have a specific need to cover this code with tests, and tests have to be runnable under Windows. The program itself is intended to run only under Linux. The problem is that pwd module is not available under Windows, so the code under test will fail with ImportError, even if the implementation of pwd functions is mocked using MagicMock. The basic idea to solve this issue was to shadow the pwd module when running tests. So when running tests,

Does android have a built-in PDF viewer?

风格不统一 提交于 2019-12-05 10:17:54
I heard something recently about it being included in Froyo and I was wondering if there was any truth to it. If there is, it would help me with an app idea greatly. kgiannakakis You are probably referring to the Adobe Reader , which is freely available for Android 2.1+. Some devices also have other applications pre-installed for rendering pdf files. See this question on how you can open the default pdf viewer from your application. Android has a built in framework from Android 5.0 / Lollipop, it's called PDFRenderer . There's an official example on Google's developer site: http://developer