Questions tagged [standard-library]

The standard library contains core utilities provided by all implementations of the language.

standard-library
Filter by
Sorted by
Tagged with
0 votes
0 answers
14 views

Vector operation modules in Python Standard Library?

I'm solving some competitive programming problems related to vectors, but I can only use modules from the standard library, I'm not sure if there is any module that defines vectors and vector ...
Peco's user avatar
  • 1
3 votes
1 answer
55 views

`from typing` vs. `from collections.abc` for standard primitive type annotation?

I'm looking at the standard library documentation, and I see that from typing import Sequence is just calling collections.abc under the hood. Now originally, there was a deprecation warning/error and ...
Dave Liu's user avatar
  • 1,055
5 votes
1 answer
146 views

Do any Ranges view-adaptor types (from `std::views`) rely on heap allocation?

I know that at least most Ranges view types don't require any heap-allocation. For example, you can take a C array on the stack and pipe it through std::views::take(42) without causing any heap-...
Quuxplusone's user avatar
  • 24.9k
-2 votes
1 answer
126 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.
Seiya's user avatar
  • 71
6 votes
3 answers
582 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 ...
ruohola's user avatar
  • 22.9k
0 votes
0 answers
84 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 ...
Tristan's user avatar
1 vote
2 answers
106 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&...
GreyBit's user avatar
  • 87
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&...
moped's user avatar
  • 21
1 vote
2 answers
86 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 ...
Frævik's user avatar
  • 17
0 votes
1 answer
91 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&...
AKL's user avatar
  • 1,377
3 votes
1 answer
127 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 ...
Eternal's user avatar
  • 2,707
0 votes
1 answer
100 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 ...
true equals false's user avatar
1 vote
1 answer
35 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(|...
Teun M.'s user avatar
  • 184
0 votes
1 answer
103 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 ...
18446744073709551615's user avatar
2 votes
1 answer
237 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 ?
Sonu Gupta's user avatar
4 votes
3 answers
501 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 ...
KianFakheriAghdam's user avatar
2 votes
1 answer
316 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 > ...
Michael Sohnen's user avatar
0 votes
1 answer
130 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 ...
Ivan Velichko's user avatar
0 votes
3 answers
174 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 ...
stht55 's user avatar
  • 390
4 votes
1 answer
755 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 ...
SMMH's user avatar
  • 332
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 ...
Jaino's user avatar
  • 1
0 votes
2 answers
336 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....
Max Heiber's user avatar
  • 14.9k
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?
Oleksandr Novik's user avatar
4 votes
1 answer
2k 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 ...
AaronC's user avatar
  • 693
4 votes
1 answer
113 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....
ajax2112's user avatar
  • 238
1 vote
1 answer
5k 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 ...
TJ1's user avatar
  • 8,108
3 votes
0 answers
100 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 ...
Adalbert's user avatar
3 votes
3 answers
254 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. ...
Alex's user avatar
  • 701
0 votes
1 answer
223 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 ...
B A C H A S H's user avatar
-2 votes
1 answer
94 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 ...
cssdev's user avatar
  • 59
0 votes
1 answer
387 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 ...
David Taylor's user avatar
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? ...
Géry Ogam's user avatar
  • 7,126
23 votes
1 answer
23k 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 ...
Nayuki's user avatar
  • 18.2k
3 votes
2 answers
786 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([...
Octavio del Ser's user avatar
4 votes
2 answers
7k 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....
Yurroffian's user avatar
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 "...
DivineGoose's user avatar
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(...
Shaheed Blackman's user avatar
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 ...
Vefhug's user avatar
  • 149
14 votes
2 answers
5k 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?
Daniele B's user avatar
  • 20.2k
3 votes
2 answers
2k 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 ...
Dost Arora's user avatar
1 vote
1 answer
140 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 ...
clartaq's user avatar
  • 5,352
-1 votes
1 answer
143 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',...
Richard Neumann's user avatar
-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 ...
TropicalMagic's user avatar
1 vote
0 answers
121 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 () { ++...
kwonryul's user avatar
  • 533
-1 votes
1 answer
396 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 ...
Tthrow's user avatar
  • 55
0 votes
1 answer
697 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? ...
Moritz Groß's user avatar
  • 1,412
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 ...
passing_through's user avatar
0 votes
1 answer
158 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 ...
helq's user avatar
  • 1,501
1 vote
1 answer
103 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 ...
repeat's user avatar
  • 18.6k
2 votes
0 answers
648 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?
AJodeiri's user avatar
  • 314

1
2 3 4 5
14