246
questions
0
votes
1
answer
19
views
How can I get an SAFEARRAY(short) output parameter from a COM server using C# dynamic types
I am using a COM server, which has two methods with the following signatures:
HRESULT setData
(
[in] long id,
[in] SAFEARRAY(short) *arr,
[in] double* scalar1,
[in] double* scalar2
);
...
2
votes
0
answers
62
views
Scala Seq.reduceLeft does not update the accumulator value?
I have the following code snippet to combine a Seq of (DataFrame, BloomFilter) tuples. The DFs are in chronological order, and the goal is to union and deduplicate all the DFs while always selecting ...
1
vote
1
answer
75
views
Handling Dynamic Outputs in Swift Functions Without Sacrificing Type Safety (Any)
I have a basic custom structure in Swift where using Any for input types is less than ideal due to the language's statically typed nature, which can bypass the compiler's type checking and lead to ...
0
votes
0
answers
53
views
Create an Object From Raw Pointer and Metadata [duplicate]
I am trying to do something complex in rust with wasm_bindgen I cannot export generic structs/functions from rust to javascript.
What I'm trying to do is something like this.
some function
pub fn foo()...
2
votes
0
answers
51
views
Typescript problem with dynamic interfaces according to type
Im working on an Angular 17 app where I have to apply specific interface according to a type in a generic interface.
First, I have the enum with all my block types
export enum BlockTypes {
text ...
0
votes
0
answers
56
views
Understanding Compilation and Dynamic Typing with Nuitka Compiler and LLVM-IR?
Hello Stack Overflow community,
I am trying to better understand compilation and dynamic typing, and I have a specific question regarding the Nuitka Compiler. As far as I understand, Nuitka compiles ...
0
votes
0
answers
21
views
Unit test in python: Conceptual question regarding dynamic typing / type hinting
Python is using dynamic typing. This makes me wonder, what I should actual test in unit test. Let's take a simple example:
import numpy as np
def foo(n, m):
bar = np.multiply(n, m)
return bar
...
3
votes
0
answers
190
views
Is there a mask-and-compare instruction for the x86_64 architecture?
Implementations of programming languages that need to preserve type information at runtime often use some bits of an integer value as tagging bits. A typical expression in the C programming language ...
0
votes
2
answers
371
views
Objects are not valid as a React child (found: [object Promise]) Error in data state attribute
I cannot understand, why do I keep getting "Objects are not valid as a React child (found: [object Promise]). If you meant to render a collection of children, use an array instead." error.
...
0
votes
1
answer
507
views
Remove all bound arguments from function signature?
Say, we have a function foo, which takes another function bar as an argument and does something based on bar's signature, and, sadly, throws an error when bar has default arguments. I want to use foo ...
0
votes
1
answer
54
views
Is there a way to create a class with a list of dynamic types?
I'm trying to create a controller class for my database, but some tables only have one primary key, and some have multiple. And the data type of the primary key differs between some tables.
I would ...
1
vote
2
answers
217
views
Read property of object as one of types
Type definitions for some objects are a little wonky. I know the properties and I know the type but the compiler doesn't. I want to write a small function that extracts the property with the type that ...
1
vote
1
answer
136
views
What’s the point of mixed-type lists
Some languages like Python allow you to define mixed type lists:
mixed = [1, 'a', 2, 'b']
While other languages would require that all elements of a list be of the same type.
numbers = [1, 2]
letters ...
2
votes
1
answer
100
views
How to avoid dummy clases during multiple inheritance with conditions
Is it possible to refactor multiinheritance without dummy classes?
Maybe anybody have similar issue or have experienxe to tackle it, or at least tell me which way to look??
Code from __init__.py
from ...
0
votes
0
answers
140
views
How to change type of class property based on value of env
I have a class
export class FeedItem extends Model {
tags: process.env.NODE_ENV === 'test' ? string : string[]
}
I would like to set the type of tags as a string if I am running tests otherwise a ...
-1
votes
1
answer
229
views
How to create a dynamic size int in C?
I would like to create a variable that could store an integer of a variable size, the variable should be able to resize itself as needed.
dyn_int num = 42;
// sizeof(num) == sizeof(char)
num = 1000;
//...
0
votes
1
answer
292
views
Python. Use object attributes to annotate methods; Dynamically-defined type annotations
Python pseudocode
I want to dynamically annotate returning types for my methods. I want something that looks like this:
class Foo:
def __init__(model: BaseModel):
self.model = model
...
1
vote
0
answers
150
views
Is there a 1:1 mapping between static typing and static dispatch vs dynamic typing and dynamic dispatch?
Context: I'm learning Julia and trying to figure out multiple dispatch. I understand the conceptual leap from single dynamic dispatch to multiple dynamic dispatch, but I'm trying to pin down single ...
1
vote
1
answer
111
views
Common Lisp: How to make just one method unbound? [duplicate]
Suppose I have a few classes
(defclass mammal ()
())
(defclass cat (mammal)
())
(defclass dog (mammal)
())
with their corresponding methods
(defmethod make-sound ((mammal mammal))
(print &...
3
votes
1
answer
701
views
How to disable dynamic properties on php objects, have them behave like undefined variables
Usually, when you access a property of a class that doesn't exist, it has no meaning to that class and it is likely a typo. Using a normal variable that doesn't exist raises a warning for that reason.
...
2
votes
1
answer
1k
views
Get union codec from type values in io-ts
I am trying to create union codec from type codec in io-ts.
What I am trying to achieve is basically transforming from:
import * as t from 'io-ts'
const FilterTypeC = t.type({
POTATO: t....
0
votes
2
answers
122
views
How R type identification works
I have studied that R uses dynamic typing, but I would like to know something more about it.
How can the interpreter understand that an object like the following one is numeric?
var <- 5
str(var)
...
0
votes
1
answer
1k
views
How do I emit a signal argument as an int instead of string?
In Godot 3.3, I'm trying to make a Label respond to text entered through a LineEdit node. I connected the objects and can emit the signal, but the signal is only ever sent as a string, not as the int ...
0
votes
2
answers
62
views
In dynamic typing the existing variable's ID isn't changing in python
value = 10
print(value, id(value), type(value))
value = "100"
print(value, id(value), type(value))
Output :
10 1383004224 <class 'int'>
100 21775456 <class 'str'>
...
1
vote
0
answers
638
views
Hidden sense of Python `isinstance` function signature
Reading PyCharm type hints for Python isinstance function, I noticed a very strange desing.
def isinstance(__obj: object,
__class_or_tuple: Union[type, tuple[Union[type, tuple[Any, ...]]...
1
vote
0
answers
55
views
What is the benefit of Python being dynamically typed? [duplicate]
I've noticed that, with programming experience, I increasingly code in a way that mimics static typing*:
using Python's type hints along PEP 484, PEP 526, PEP 544, PEP 586, PEP 589, and PEP 591
...
0
votes
0
answers
43
views
What is the best way to check if the value of a function's arguments match specified possibilities?
Say I have a very simple function that checks the value of an and behaves differently depending if it matches one of a number of possibilities. Here's a minimal example:
is_duck <- function(x) {
...
4
votes
1
answer
85
views
Haskell: proving with Typeable that `exists t. a ~ D t`
I have
data D t = ...
data SomeStuff = forall a (Typeable a, ...) => SomeStuff a
and at some point I get a SomeStuff whose internal a I'd like to try and cast to D t (where t can by any type, I'm ...
1
vote
1
answer
53
views
Return object of functions with argument types of incoming function argument values
I'd like to have function, let's call it DummyService that would accept some definition object as argument and return bunch of functions in a way that arguments of those returned functions can only ...
4
votes
1
answer
584
views
How to monkeypatch dunder methods to existing instances?
Context:
I'd like to use heapq (and anything else) on objects I didn't create, which don't themselves have a __lt__ operator. Can I? (without a wrapper class).
the class:
class Node:
def __init__(...
0
votes
1
answer
263
views
How can I make a more generic isEmpty() function in Dart?
I have the following utility function for checking if a String variable is empty or null:
bool isEmpty(String s){
return (s??'').isEmpty;
}
Now I want to make a similar function for Iterables. The ...
0
votes
3
answers
324
views
How to implement Javascript-like dynamic typing in C++
I have to write a very basic JSON serializer/deserializer in C++. The goal is to build something similar to this https://github.com/nlohmann/json. Unfortunately I can't use this awesome library ...
1
vote
1
answer
911
views
How to downcast Rc<RefCell<dyn io::Write>> into a concrete type?
I want to make a struct which the text output can be either displayed on the console or stored in an internal buffer. If the text is buffered, then I need a method that gives back the text content.
...
1
vote
0
answers
424
views
Dynamic properties passed as C# method parameters
In this code, we pass a property of a dynamic object. For the sake of argument we know the property exists and there isn't a bonehead error like bad casing of the property name.
When we use the ...
0
votes
2
answers
224
views
Ruby inheritance and typing
I am having trouble with some fundamental concepts in Ruby, specifically the interchangeability of a subclass for the superclass.
According to the Ruby documentation on classes, "Class" inherits from ...
0
votes
1
answer
2k
views
How to declare types for uninitialized variables in Python? [duplicate]
I'm learning to use mypy and static type checkers while practicing algorithms and data structures.
In a Binary Search Tree, a Node is initialized with no children. They are of type Node. However, it ...
0
votes
1
answer
46
views
How do you call functions of objects which were created within an array in javascript?
In the below code, the TypeError "database[(0 , 0)].returnVal is not a function" is spat back:
let database = [
[
new DatabaseItem("00", [1, 2, 3, 4], "abcd", ["haiku", "test"]),
...
2
votes
1
answer
5k
views
How to setup python typing for a type argument [duplicate]
I would like to properly add typing for Python types passed as arguments. E.g. let us assume that we would like to add typing to the following function:
def do_something_based_on_types(
...
...
1
vote
2
answers
2k
views
How to type in one line an javascript object in Typescript, were a root property has a variable name
I have the following javascript object:
var termsAndConditions = {
pt: ["url1", "url2"],
en: ["url3", "url4"]
}
And I want to type it in Typescript in just one line. Something like this:
...
18
votes
2
answers
1k
views
Requiring type declaration in Julia
Is there any way to explicitly require in Julia (e.g. say within a module or package) that types must be declared? Does e.g. PackageCompiler or Lint.jl have any support for such checks? More broadly, ...
-3
votes
3
answers
763
views
Is the choice of static and dynamic typing not visible to the programmers of the languages?
From Design Concepts in Programming Languages by Turbak
Although some dynamically typed languages have simple type markers (e.g., Perl variable names begin with a character that indicates the type ...
0
votes
3
answers
333
views
Why we don't have to define the type of an argument when creating an object from a class in Python?
I am new to Python and I have just created a class as part of the online course I am taking.
from math import sqrt
class Line:
def __init__(self,coor1,coor2):
self.coor1=coor1 #tuple (x1,y1)
...
0
votes
1
answer
154
views
Can the value model for variables only be used together with static typing, not with dynamic typing?
There are two models of variables: the value model (e.g. variables in C) and the reference model (e.g. variables in Python).
There is also a distinction between static typing and dynamic typing.
Can ...
4
votes
1
answer
143
views
why D's variant seems confusing
I experiment with the D language, and find the std.variant cool.
But then I find it confusing.
For example,
import std.stdio;
void main()
{
string x = "";
x ~= 'v';
writeln(x);
}
This does ...
0
votes
2
answers
176
views
Accepting Objects containing specific method instead of accepting specific Type
[EDIT]: This question is about Types that I have no control over. So making them inherit a superclass or implement an interface is not possible. I want to be able to do this without wrapping the Types....
2
votes
0
answers
2k
views
Protobuf define a field that can be either int or float
I would like to define a field that can be either int of float. Is this possible in Google's Protobuf? Is there another way that can be done? I need this of python, where types can be inferred in run-...
2
votes
0
answers
144
views
Making wrapper objects compatible with @singledispatch?
Say I have a class like this:
class Wrapper(object):
def __init__(self, obj):
self.__obj = obj
def __getattr__(self, name):
logger.debug('Accessing %s', name)
return ...
1
vote
0
answers
122
views
Why is sound gradual typing slow?
There are a whole bunch of articles making the claim that gradual typing is inherently slow. The most shocking claim comes from Takikawa et al (2016) who report a 100-fold slowdown on gradually typed ...
0
votes
1
answer
55
views
Creating a dynamic table in html for a firefox extention
I tried using:
<form>
<button>Save ID</button>
</form>
<script>
var table = '';
var rows = 10;
var columns = 3;
for (var r = 0; r < rows; r++)
{...
0
votes
1
answer
359
views
How to implement arbitrary add operator in Rust?
I'm working on an arbitrary expression evaluator in Rust,
Take Add operator as an example:
fn eval_add<T: ?Sized + Add<T, Output=T>>(l: Rc<Any>, r: Rc<Any>) -> Rc<Any&...