Questions tagged [scalar]

In computing and programming, a scalar variable or value refers to a single value, as opposed to data structures such as arrays or lists.

In computing and programming, a scalar variable refers to a single value, as opposed to data structures such as or s. A scalar can be of any type, including a complex type such as an object or string. Being scalar only means that it is manipulated as a single value.

As an example, the string type in C++ is considered to be a scalar as it is a primitive type containing a single value, although in the C language there is no such primitive type. Thus, the char array implementation of strings typically used would not be considered as a scalar.

See also:

532 questions
4
votes
2 answers

How do I create an object that returns different values in different scalar contexts?

I want to return a different value in string context and numeric context like $! does. I know I can find out whether I am in list or scalar context with wantarray, but is there any way in pure Perl to determine which scalar context I am in? I…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
4
votes
8 answers

How can I keep only the first five lines in a Perl scalar?

From any kind of scalar, what regex could I use to match the first five lines of it and discard the rest?
Tanami
  • 196
  • 2
  • 3
  • 11
4
votes
2 answers

assigning string literal vs array to char

I have a char pointer with string literal like this char *d="abc"; and I am incrementing it like *(d+1) I get something like b if I do printf("%c",*(d+1)) But when I have these lines char *c={'a','b','c'} printf("%c\n",*(c+1)); /// CAUSES…
user786
  • 3,902
  • 4
  • 40
  • 72
4
votes
2 answers

Is there a Laravel validation rule that checks if a field is scalar

I am using Laravel's validator to validate a JSON request inside the controller: class InsertProduct extends ModuleApiController { public function handle(Request $request, int $fileId) { $data = $request->json()->all(); …
kaan_a
  • 3,503
  • 1
  • 28
  • 52
4
votes
1 answer

Fortran to C interface for arrays and scalars

I am learning how to interface Fortran with C. I wrote as simple C code that sets all array values to 1: #include void cset( int *array, int size ) { for (size_t i = 0; i < size; i++) { array[i] = 1; } return; } I wanted to…
jcerar
  • 467
  • 4
  • 13
4
votes
1 answer

Referencing operator function '*' on 'SIMD' requires that '_.Scalar' conform to 'FloatingPoint'

I've just started teaching myself to write in Swift. I'm currently trying to rotate an image when I press a button (just practicing with really simple stuff) and Xcode has thrown two errors at me: Referencing operator function '*' on 'SIMD'…
SwiftBeginner
  • 49
  • 1
  • 2
4
votes
2 answers

Why do I see odd behavior of subscript on scalars?

It appears as if a scalar by itself is sort of a list of one item: > "foo"[1] Index out of range. Is: 1, should be in 0..0 in block at line 5 > "foo"[0] foo > "foo"[*-1] foo I say sort of a list of one because lists don't…
Chas. Owens
  • 64,182
  • 22
  • 135
  • 226
4
votes
2 answers

Converting Unicode in Swift

I currently have a string as follows which I received through an API call: \n\nIt\U2019s a great place to discover Berlin and a comfortable place to come home to. And I want to convert it into something like this which is more readable: It's a…
Richard
  • 43
  • 1
  • 7
4
votes
3 answers

NumPy: 2D array from a list of arrays and scalars

I need to create a 2D numpy array from a list of 1D arrays and scalars so that the scalars are replicated to match the length of the 1D arrays. Example of desired behaviour >>> x = np.ones(5) >>> something([x, 0, x]) array([[ 1., 1., 1., 1., …
zegkljan
  • 8,051
  • 5
  • 34
  • 49
4
votes
4 answers

returning a lazily-computed scalar, in perl

I'm trying to add some functionality to our code base by using tied scalars. We have a function which is specified to return scalars. I thought I could add some features to the system by tie-ing these scalars before returning them, but it looks like…
bukzor
  • 37,539
  • 11
  • 77
  • 111
4
votes
1 answer

Perl 'context' in assignments

As a newbie to Perl, I just don't understand what kind of philosophy is behind of the following result: $cnt1 = @arr; # this gives the length of the array 'arr' $cnt2 = @arr[ @indices_arr ]; # this gives the last element of the…
Byungjoon Lee
  • 913
  • 6
  • 18
4
votes
2 answers

Can't use string ("Server1") as a SCALAR ref while "strict refs" in use

#!/usr/bin/perl -w use strict; use warnings; use Class::Struct; struct System => { Name => '$', }; my $system = new System; $system->Name("Server1"); my $strout1 = qq{Server is ${$system->Name}\n}; my $strout2 = "Server is…
Ryan
  • 219
  • 3
  • 12
4
votes
1 answer

How to Set a variable using OPENQUERY in SQL Server

I am trying to read data from a table. This table have a list of table name. for each row of the data set I want to run a couple of queries to pull data and insert it into a temporary table. Here is What I have done DECLARE @campName…
Jaylen
  • 39,043
  • 40
  • 128
  • 221
4
votes
2 answers

How can I call methods on Perl scalars?

I saw some code that called methods on scalars (numbers), something like: print 42->is_odd What do you have to overload so that you can achieve this sort of "functionality" in your code?
Geo
  • 93,257
  • 117
  • 344
  • 520
4
votes
2 answers

How can a scalar be passed to a vector (1D array) to a Fortran subroutine?

There is this program: INTEGER i,k REAL*8 mp(15,48) REAL*8 sp(15) k=0 do i=1,12 k=k+1 call Equaltensors(sp,mp(1,k),15) enddo end c===================== subroutine Equaltensors(tensA,tensB,n) REAL*8 tensA(n),tensB(n) INTEGER i do i=1,n …