Questions tagged [standard-library]
The standard library contains core utilities provided by all implementations of the language.
668
questions
3
votes
1
answer
53
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
18
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
73
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....
6
votes
1
answer
293
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?
2
votes
1
answer
196
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 ...
3
votes
1
answer
52
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....
0
votes
1
answer
599
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
83
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
93
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
115
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
69
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
75
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 ...
0
votes
1
answer
498
views
Are there any functions like getattr/hasattr but bypassing instance attributes?
Are there any functions like the built-in functions getattr and hasattr in the standard library but which bypass instance attributes during attribute lookup, like the implicit lookup of special ...
5
votes
0
answers
5k
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 ...
1
vote
2
answers
273
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([...
3
votes
2
answers
2k
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
47
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
400
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 ...
9
votes
2
answers
2k
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?
2
votes
2
answers
580
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
94
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
84
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
689
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
104
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/std@0.64.0/async/mux_async_iterator.ts)?
#iteratorCount = 0
#yields = []
#throws = []
#signal = deferred()
add () {
++...
-1
votes
1
answer
206
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
326
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? ...
6
votes
1
answer
2k
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
90
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 ...
0
votes
1
answer
65
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
430
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
144
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
82
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) {
...
1
vote
1
answer
331
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["...
5
votes
1
answer
681
views
How are entrypoints of the Python standard library registered?
Regular Python packages register entrypoints in their setup.py or specify them in a pyporject.toml file. The latter is the case, if they don't use distutils/setuptools for packaging. As an example, ...
7
votes
1
answer
294
views
Expected behaviour of freopen() with regards to buffering (setvbuf())?
In an attempt to implement freopen(), I've come up to a piece of specification in the standard that doesn't actually specify anything, as far as I can see.
So... freopen() will close the stream (...
1
vote
1
answer
591
views
Hacklang : why were container classes replaced with built-in types?
Just a quote from hack documentation :
Legacy Vector, Map, and Set
These container types should be avoided in new code; use dict,
keyset, and vec instead.
Early in Hack's life, the ...
1
vote
0
answers
127
views
How to run Sqlite CLI dot-commands (not SQL) using a C#.NET API or Nuget package
I'm looking for an API — ideally compatible with the .NET Standard Library, otherwise .NET Core or else .NET Framework (in that order) — that can be used to issue SQLite CLI dot-commands like .save ....
8
votes
1
answer
223
views
Is there an equivalent of `sum()` builtin which uses augmented assignment?
Is there any standard library/numpy equivalent of the following function:
def augmented_assignment_sum(iterable, start=0):
for n in iterable:
start += n
return start
?
While sum(...
0
votes
1
answer
116
views
Are any standard library modules missing from `print( help('modules'))`
In a very brief python script, we can write:
print( help('modules'))
This lists a great number of things, including the following:
PIL _weakrefset html ...
0
votes
2
answers
75
views
How to work out if a member of a struct was set or not?
Say I have the following struct:
struct cube {
int height;
int length;
int width;
};
I need to create a library that allows the user to enter values into the struct and then pass it ...
0
votes
1
answer
97
views
What is the behavior of iscntrl?
The function iscntrl is standardized. Unfortuneately on C99 we have:
The iscntrl function tests for any control character
Considering the prototype which is int iscntrl(int c); I am expecting ...
1
vote
1
answer
59
views
What are common uses for the system (3) command?
I came across the command while reading the famous C Language Book (1988). Is the command commonly used today?
From the book (section 7.8.4):
The function system(char *s) executes the command ...
7
votes
3
answers
14k
views
Is there a maxheap in the C++ standard library?
I know the std::priority_queue class implements a minheap. Is there a way to use this as a Max heap? Or is there an alternative Maxheap structure? I know I can use the std::make_heap() function on a ...
2
votes
1
answer
45
views
Is there a built-in container which maps int -> element?
I need something very similar to a standard dict which is being used to map integers (ranging from 0 to several hundreds) to arbitrary elements:
d = {}
d[5] = "hello"
d[100] = "world"
d[70] = "pretty"...
-1
votes
1
answer
131
views
String to Double and leading whitespace
I found odd behavior in the Swift standard library struct Double(). This function converts a string representing a number into a double precision number. All well and good.
I recently discovered odd ...
8
votes
2
answers
4k
views
Is there a Binary Search method in the C standard library?
I cannot find any method implementing binary search. Is that because I failed to locate it, or is it because it doesn't exist?
I think the second, but I couldn't find a duplicate question, so maybe I ...
1
vote
0
answers
65
views
What is the internal method System.Double.IsNegative() for in C#?
While browsing the source for System.Double, I came across this method:
[SecuritySafeCritical]
internal static unsafe bool IsNegative(double d)
{
return (*(long*) &d & long.MinValue) == ...
6
votes
2
answers
74
views
Where does this .get(x) behavior come from?
Some("abcdefg").get(3) //res0: Char = d
The argument to get() is sent to the apply() method of the String, but the source code for Option (and Some) doesn't have a get() method that takes parameters,...
1
vote
0
answers
99
views
Why does clang fail to restrict the construction of a tuple to be explicit?
Per [tuple.cnstr]/6:
EXPLICIT constexpr tuple();
Effects: Value-initializes each element.
Remarks: This constructor shall not participate in overload resolution
unless is_default_...