473,729 Members | 2,235 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

check whether a value is scalar

Eli
Hi,

I want to check whether a value is a scalar. A scalar can be:
- None (null)
- string
- number (integer, float)
- boolean
How can I validate a value is one of these types?

I care about the value only, and not its class methods.
An object is not a scalar, since it's not a simple value.
An array might be considered as scalar.
The issue is I want to keep a set of values to share among several
applications in different languages, and only scalar values can be
shared. Since objects are not the same in all languages, it's possible
to share only simple values.

-thanks

Apr 22 '06 #1
5 11879
In article <11************ **********@i40g 2000cwc.googleg roups.com>,
"Eli" <el*****@gmail. com> wrote:
Hi,

I want to check whether a value is a scalar. A scalar can be:
- None (null)
- string
- number (integer, float)
- boolean
How can I validate a value is one of these types?

I care about the value only, and not its class methods.
An object is not a scalar, since it's not a simple value.
An array might be considered as scalar.
The issue is I want to keep a set of values to share among several
applications in different languages, and only scalar values can be
shared. Since objects are not the same in all languages, it's possible
to share only simple values.

-thanks


I'm not sure what "scalar" means in this context. You say "an object is
not a scalar", but you also assert that an integer is a scalar. These are
contradictory statements, since integers *are* objects:
isinstance (1, object)

True

You say that numbers are scalars. All nunmbers, or just integers and
floats? What about complex numbers? What about long integers?

In any case, the way to check for a type is with isinstance(), as I did
above).
Apr 22 '06 #2
would

isinstance(valu e,(type(None),s tr,int,float,bo ol))

be enough? This yields true if the type value is in the list of type
objects given as second argument, or a subtype of one of them. What,
however, do you mean with "I care about the value only, and not its
class method"?

Apr 22 '06 #3
Eli
Python treats integers as objects, but as I mentioned that I do care
about the value only, and not its object methods. I mean that it's not
possible to share objects among application in different programming
languages, but it's possible to share the scalar values among them.
Strings, booleans, integeres, floats, null are types that most
programming languages use. Arrays are also commonly used, but each
programming language defines and uses it differently, so it's more
problematic to treat it as scalar (for example python uses dictionaries
while other langs uses regular arrays only).

Apr 23 '06 #4
"Eli" <el*****@gmail. com> wrote:
The issue is I want to keep a set of values to share among several
applications in different languages, and only scalar values can be
shared. Since objects are not the same in all languages, it's possible
to share only simple values.


I can assure you that people who've implemented various kinds of
RPC protocols and cross-language bindings would be rather surprised
to hear that you've discovered that it's impossible to do what they've
done.

I'm not entirely convinced that you know what you're talking about,
really. Maybe you should spend a little more time studying prior art ?

</F>

Apr 23 '06 #5
Eli a écrit :
Python treats integers as objects, but as I mentioned that I do care
about the value only, and not its object methods. I mean that it's not
possible to share objects among application in different programming
languages, but it's possible to share the scalar values among them.
Not so easily. Lower level languages have some strange rules about size
of an integer, signed/unsigned stuff, precision issues for floats,
etc... - and of course different representations for a 'string'.
Strings, booleans, integeres, floats, null are types that most
programming languages use. Arrays are also commonly used, but each
programming language defines and uses it differently,
Same thing for strings.
so it's more
problematic to treat it as scalar (for example python uses dictionaries
Python's dicts are hastables, not arrays.
while other langs uses regular arrays only).

Apr 24 '06 #6

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

20
10158
by: | last post by:
If I need to check if a certain value does exist in a field, and return either "yes" or "not" which query would be the most effestive?
2
2787
by: Martin MacRobert | last post by:
Hi, I'm trying to make a specialisation of a template function, so that the second parameter accepts scalar types only (int,double,float etc.). How can I do this without writing an explicit specialisation for all scalar types? This is because of the large number of functions to overload. For example:
21
21216
by: scandal | last post by:
I am a javascript newbie working on a script that checks whether a "path" from one element in an array to another is "blocked." Currently, the script pushes an already processed cell index (hence an integer) into an array. To prevent rechecking already processed cells, the script iterates through the (sorted) array to see whether that integer is an element of the array. After reading about javascript arrays a bit more, I thought...
5
4911
by: margospencer | last post by:
Does db2 support this subquery: select b.time_ssno, sum(b.time_hours) as hours95, (select sum(a.time_hours) from p0230.pyrltime_time_v1 a where time_date between '2005-01-01' and '2005-03-31' and time_orgn = '2300' and time_type = 'REG' and a.time_ssno = b.time_ssno) as total_hours from p0230.pyrltime_time_v1 b
5
1682
by: Bob Stearns | last post by:
When I run the following query with the two sections commented out, the response time is between 1 an 2 seconds; with the first indicated section enabled, the response goes up to 15 seconds even though t1.bh_disposal_code IS NOT NULL in only one row; with the second section enabled, it goes up to 592 seconds, even though t1.mating is NULL in all the rows chosen. Why should the (supposedly never executed) scalar subqueries cost so much? It...
5
3226
by: Robert Oschler | last post by:
I am converting a Perl script over to "C" for a potential open source project. I need some open source "C" code that will give me the same functionality of a Perl Style associative array: someArray = 6; I know I can't get the same syntactic sugar as Perl offers, with the usage of a string as the array key surrounded by square brackets. I just want the general functionality, that's all. That is, a data container that will maintain...
11
3043
by: Richard Meister | last post by:
Hi, I'd like to define several constants and make sure that all of them are smaller than a given other constant. I thought this could be done by a simple macro. Something like this: #define MAX 999 #define DEF_CHECKED_VAL( name, value) #if (value < MAX) \ #define name MAX \
2
2335
by: Earl | last post by:
Is there any sort of check that can be done to see if a particular instance of SQL Server is present? I already call a method to check for connection -- if no connection, I have the user re-enter server settings (server name and database name). But the connection check is made by calling for a scalar value in the database. What I'd rather do is graduate the error messages: 1. No server installed 2. Specified database name not installed...
4
19240
by: laredotornado | last post by:
Hi, I'm using php 4.4.4. How do i check if a given variable is an array or simply a scalar? Thanks, - Dave
0
8913
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
9280
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
9200
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8144
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6016
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2162
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.