Questions tagged [standard-library]
The standard library contains core utilities provided by all implementations of the language.
683
questions
-2
votes
1
answer
90
views
What's the difference between types.Implements and types.Satisfies?
What's the difference between types.Implements and types.Satisfies in golang?
I'm working on a code that inspects Go AST.
6
votes
3
answers
442
views
How to compose functions through purely using Python's standard library?
Python's standard library is vast, and my intuition tells that there must be a way in it to accomplish this, but I just can't figure it out. This is purely for curiosity and learning purposes:
I have ...
0
votes
0
answers
45
views
Rust custom panic_fmt lead to found duplicate lang item `panic_fmt` the lang item is first defined in crate `core`
On an embedded project with Rust, I'm currently facing the following issue when I try to implement my own panic handler.
To give you some context, I'm currently building my project with rust nightly ...
1
vote
2
answers
102
views
Can Arrays.sort(T[] a, Comparator<? super T> c) ever throw ClassCastException if c is not null?
The javadoc for Arrays.sort(T[] a, Comparator<? super T> c) from the package java.util in the standard library for Java 20 API docs reads as follows:
public static void sort(T[] a, Comparator&...
1
vote
0
answers
64
views
How does my compiler know what printf() does? [duplicate]
Maybe this is a stupid question, but I'm new to this and trying to understand things.
Let's say I want to write a simple "Hello World" program:
// hello.c
int main() {
printf("%s\n&...
1
vote
2
answers
61
views
What is the basic type that underlies all other Swift types?
I'm currently trying to get a better understanding of Apple's open-source Swift compiler on GitHub. After using Swift for several years, I've gotten used to the philosophy of defining important types ...
0
votes
1
answer
82
views
Is there any tool to remove rvalue reference but not lvalue refrence within the standard library?
Basically I want to this:
template<typename TYPE>
struct not_rvalue_reference{
typedef std::conditional_t<std::is_rvalue_reference_v<TYPE>, std::remove_reference_t<TYPE>, TYPE&...
3
votes
1
answer
95
views
When can the standard library functions throw exceptions?
I'm having trouble understanding which functions from the standard library can throw exceptions, and if so which and when.
Some functions are noexcept, in which case ok they don't, but if I look for ...
0
votes
1
answer
78
views
Are there any rust functions for wrapping an iterator that is dependent on a reference so the wrapper contains the referent?
In this case I want to read integers from standard input such that they are separated by spaces and newline. My first attempt was similar to the following code:
fn splitter(x: String) -> impl ...
1
vote
1
answer
29
views
Rascal MPL overload library functions
It's easy to overload your own functions like so:
void testVal(loc l) {
println("LOC <l>");
}
void testVal(value v) {
println("VAL <v>");
}
such that testVal(|...
0
votes
1
answer
78
views
scala: Ordering.by vs Ordering.on
What is the difference between Ordering.by() and Ordering.on() in Scala?
(Well, one is defined in the trait and the other in the companion object, and the implementation code is also different, but ...
2
votes
1
answer
227
views
Namespaces and C++ library
Is a namespace contained in a library or a library is contained in a namespace?
How many namespaces are there in the C++ standard library ?
4
votes
3
answers
401
views
va_list in C: Creating a function that doesn't need a argument count like 'printf'
Using the <stdarg.h> header, one can make a function that has a variable number of arguments, but:
To start using a va_list, you need to use a va_start macro that needs to know how many ...
2
votes
1
answer
253
views
Exception in Python Trace Module: "Charmap Can't Encode..."
I am using the python trace module in order to figure out why my program is exiting early.
However, there seems to be a bug with the trace module itself.
When i run py -m trace -t src/main.py > ...
0
votes
1
answer
108
views
Why does Go stdlib use a mutually exclusive lock to read context's error field?
There are a number of under-the-hood implementations of the Context interface in the Go standard library. For instance, the Background and TODO contexts are backed by the unexposed emptyCtx type which ...
0
votes
3
answers
140
views
Where can I see how OCaml’s standard library functions are implemented?
I'm interested in how List.init and other library functions are implemented in OCaml. Where can I see the implementations? I checked this official link: https://v2.ocaml.org/api/List.html and only ...
4
votes
1
answer
588
views
How and why is Kotlin's `Map` iterable even though it is not `Iterable`?
As it was in Java, any object that is Iterable can be used in an enhanced for loop. I thought the same held true for Kotlin as well, until I discovered that kotlin.collections.Map is not Iterable at ...
0
votes
1
answer
49
views
Logging message inside except exception
I am trying to use logging when try fails. I have a for loop for converting a string of date into datetime format.
For example, converting "03/05/2021" to 2021-05-03. However, there are ...
0
votes
2
answers
317
views
Does FileInputStream incorrectly implement InputStream?
The docs for InputStream.read(bytes) say "This method blocks until input data is available, end of file is detected, or an exception is thrown."
However, java.io.FileInputStream extends java....
7
votes
1
answer
1k
views
Why will Rust integer types be deprecated soon?
I've noticed a deprecation note on the Rust std page next to u8, i8, u16 and so on:
What is going on, and what will the replacement be?
3
votes
1
answer
1k
views
Why is there no Disjoint Set (Union Find Algorithm) implemented in most mainstream programming languages' standard library?
I have found articles on how to implement a Disjoint Set (Union Find Algorithm implementation) for C++, Java, Kotlin, Python, etc.. The implementation of it is not especially difficult, although there ...
4
votes
1
answer
103
views
Why does a module type annotation in OCaml cause this code to not compile?
I am working with the Map module in OCaml. Consider the following code to create a map with ints as keys:
module Int = struct
type t = int
let compare a b = a - b
end
module IntMap = Map....
1
vote
1
answer
4k
views
Python: setting generator Polynomial in zlib.crc32
I am trying to use zlib.crc32 to compute CRC in Python.
I would like to be able to set the generator polynomial of the CRC, but I cannot find any documentation. So the question is: can this be done?
I ...
3
votes
0
answers
94
views
Does Scala use Java collections implementations under the hood?
As a part of academic project I was about to microbenchmark some Java and Kotlin collections behaviours, and compare them to each other.
Recently I found out, that under the hood Kotlin, when run on ...
3
votes
3
answers
208
views
Smart pointers with functions returning a pointer in an argument
This question was discussed a few times but all those discussions almost a decade old and there was no good solution. The question is the same.
We have smart pointers, like unique_ptr, that is great. ...
0
votes
1
answer
215
views
how to solve error ModuleNotFoundError on virtual env subdirectory?
As seen in the image below, I finished working on my project folder "click" under the main folder "my project." I didn't establish a virtual environment when I first started ...
-2
votes
1
answer
92
views
In a C program, what exactly happens under the hood if I call a function from a header file from /usr/include? [closed]
The header files of C library functions can be found under /usr/include. The actual source files, however, don't seem to be simply located anywhere in the file system.
So what exactly happens under ...
0
votes
1
answer
301
views
Why Int8.max &+ Int8.max equals to "-2"?
Following Swift Standard Library documentation, &+ discards any bits that overflow the fixed width of the integer type. I just did not get why adding two maximum values, 8-bit signed integer can ...
1
vote
1
answer
1k
views
Are there any functions like getattr/hasattr but which skip instance attributes?
Are there any functions like the built-in functions getattr and hasattr in the standard library but which skip instance attributes during attribute lookup, like the implicit lookup of special methods?
...
21
votes
1
answer
18k
views
Get Unix time in Python
In Python, I want to get the current Unix timestamp and then store the value for the long term and be handled by non-Python systems. (I am not merely trying to compute the difference between two ...
3
votes
2
answers
671
views
Data structure like frozenset which maintains insertion order?
I need set-like data structure with these properties:
hashable
no duplicate elements
maintains order
immutable
iterable
part of standard library? want to keep it simple
What is happening:
frozenset([...
4
votes
2
answers
6k
views
CPU utilization during testing in Python?
I want to get the cpu usage during testing for my ML model (during a call to predict). Here is currently what I am doing. p is the current process:
start = p.cpu_percent(interval=1)
y_hat = clf....
0
votes
0
answers
50
views
My implementation of EqualsIgnoreCase in C is not working
I am currently attempting to program a sort of database in C.
When I create a new character for the database, it should not have the same name as any other character, case-insensitive - so, if "...
0
votes
2
answers
1k
views
How to calculate average from text file without numpy or pandas
Here is the code I used to calculate average with numpy and pandas
def calc_average_books_stock():
text_file = open('book_data_file.txt')
values = []
for index,data in df.iterrows(...
0
votes
0
answers
27
views
Overloading operator + starting from += for vector class in C++ [duplicate]
I know there are plenty of discussions about this topic, like this famous one (see sbi's answer). My goal is to overload the operator + for two vectors, starting from the operator +=, as explained in ...
12
votes
2
answers
4k
views
How to get current unixtime on Kotlin standard library (multiplatform)
I have a Kotlin multiplatform project, and I would like to get the current unixtime in the shared code.
How do you do that in the Kotlin standard library?
3
votes
2
answers
1k
views
How to get Node-Entry Reference from LinkedList in java
How to get the reference to the actual Node (entry) object from LinkedList - Not the value that it holds?
Something like this :
import java.util.LinkedList;
public class Main {
public static ...
1
vote
1
answer
136
views
A Function to Test if `get-in` will Succeed
In Clojure/Script the contains? function can be used to check if a subsequent get will succeed. I believe that the Clojure version will do the test without retrieving the value. The ClojureScript ...
-1
votes
1
answer
134
views
Get iterable of 2-tuples from even iterable [duplicate]
Is there a function in the standard library, that can generate an iterable of 2-tuples of an iterable that is guaranteed to have an even amount of elements?
INPUT = 'ABCDEF'
OUTPUT = [('A', 'B'), ('C',...
-2
votes
1
answer
1k
views
Python - How to create a delete function for user input?
I've been trying to create a program which allows users to view a text file's contents and delete some or all of a single entry block.
An example of the text's file contents can be seen below:
Special ...
1
vote
0
answers
120
views
I have a question about the source, 'multipelx async iterator' of Deno standard library
What is purpose of iteratorCount in the following code (from https://deno.land/[email protected]/async/mux_async_iterator.ts)?
#iteratorCount = 0
#yields = []
#throws = []
#signal = deferred()
add () {
++...
-1
votes
1
answer
347
views
How to include «pty.h» Header File on Unix / Add «pty.h» to Standard library C / C++
I would like to include pty.h which is not normally available on Unix (Not included in standard library). On the Internet, you can get the related header file content. So how do you add this header ...
0
votes
1
answer
635
views
Kotlin: Hashcode of chars is same as ASCII value
I noticed that the hashcode of Char-values is exactly the ID they have in ASCII, for example:
println('a'.hashCode()) //is 97
Is this true by contract and where can I see the implementation for this? ...
10
votes
1
answer
3k
views
Is undefined behavior possible in safe Rust?
Is there any way to achieve undefined behavior in Rust without using unsafe?
Of course, such behavior can be wrapped by a third-party library in a "safe" function so let's assume we're using ...
0
votes
1
answer
138
views
Lifting a boolean statement to a proposition
Given a list, a "property" (a function to Bools), and a proof any f xs ≡ true, I want to get a value of Any (λ x → T (f x)) ns, i.e. I want a to convert a proof from any to a proof of Any.
So far, I ...
1
vote
1
answer
100
views
Serializing the current state of "Module Random" in OCaml's StdLib
I must have read the OCaml manual page on the standard library modules Random and Random.State half a dozen times (probably even more often) but I can't figure out how to serialize the current ...
2
votes
0
answers
601
views
Modelica Standard Library 3.2.2
Where can I download the older versions of Modelica Standard Library like 3.2.2? Then, is it possible to call it from OpenModelica?
2
votes
1
answer
180
views
PureScript equivalent to Haskell’s >> operator
Is there a PureScript standard library equivalent to Haskell’s >> operator?
class Monad m where
...
(>>) :: m a -> m b -> m b
...
Obviously it’s trivial to define but I would ...
0
votes
1
answer
225
views
Inverted "repeat" function in Kotlin
There is a Kotlin Standard Library repeat() function that allows for executing a given function specified number of times and retrieving the index of a current repetition. For example:
repeat(3) {
...
3
votes
1
answer
723
views
Python Add Inline Images to multipart/alternative emails
When adding inline attachments to the email body they are not displayed with the code below.
from email.message import EmailMessage
from email.mime.image import MIMEImage
msg = EmailMessage()
msg["...