FAQ Database Discussion Community


Fitting string literals for different string classes

string,templates,c++11,literals,prefix
The problem I am implementing a class where I want to let the user choose the string type (std::string, std::wstring, std::u16string, ...) via a template parameter. I currently fail to make the string literals fit the chosen string type: Once I decide for a literal prefix ("hello" vs. L"hello" vs....

Why is [] faster than list()?

python,performance,list,instantiation,literals
I recently compared the processing speeds of [] and list() and was surprised to discover that [] runs more than three times faster than list(). I ran the same test with {} and dict() and the results were practically identical: [] and {} both took around 0.128sec / million cycles,...

How do I dynamically append text to a Literal Class in asp.net instead of overwriting it?

asp.net,vb.net,text,append,literals
Using asp.net and vb, I am trying to dynamically add names to a Literal Class based on the date associated with the name. I have created two Lists, listDate and listShiftName, with the dates and the associated names respectively. Each name has a date associated with it, but there are...

postgresql select multiple number literals for use in a subquery

postgresql,subquery,literals
I'll be short. I want a syntactically short way of checking tons of conditions in the postgres REPL. Writing the following is a huge pain: SELECT * FROM table WHERE specid = 1 OR specid = 3 OR specid = 7 OR ... It'd be way nicer if I could...

ValueError: invalid literal for int() with base 10 How to fix error

python,random,int,literals,value
import random import operator op = {"+":operator.add, "-":operator.sub, "*":operator.mul} num1 = random.randint(0,10) num2 = random.randint(0,10) ops = random.choice(list(op.keys())) print (num1 + int(ops) + num2) I am trying to make a random math question quiz and I cannot work out why I keep getting the error: Traceback (most recent call last):...

How can the suffix for numeric literals long int and long double both be l/L?

c++,syntax,literals
The suffix l and L for numeric literals long int and long double are the same. I don't understand how the compiler can know if I want my numeric literal to be a long int or a long double if they both share the same suffix. Why does this work?...

Type of integer literals and ~ in C

c,integer,bitwise-operators,literals
I'm a C beginner, and I'm confused by the following example found in the C answer book. One way to find the size of unsigned long long on your system is to type: printf("%llu", (unsigned long long) ~0); I have no idea why this syntax works? On my system, int...

Is using null to declare literal members for later initialization a viable praxis in JS?

javascript,null,literals,object-literal,member-initialization
I'm going to declare a literal as follows: var obj = { x: null, init: function (pX) { this.x = pX; } }; Objections? I'd like to do that because x: undefined would be the same as not declaring x at all. Whats a good practice when declaring literal members...

How can I pass a list literal to f:selectItems?

jsf,el,literals,selectmanycheckbox
For example: <h:selectManyCheckbox id="literalOptions" value="firstOption"> <f:selectItems value="[firstOption, secondOption, thirdOption]"/> </h:selectManyCheckbox> this doesn't work, but you get the idea? I want to pass literal (string-type) list options (not necessarily but possibly retrieved from a bean property as a String), the [a,b,c] list-syntax probably isn't correct, but which is? Or, alternatively, how...

What's the difference between (list nil) and '(nil) in Lisp? [duplicate]

lisp,common-lisp,literals
This question already has an answer here: Why does this function return a different value every time? 4 answers Unexpected persistence of data [duplicate] 1 answer First of all, let me say I'm a beginner in Lisp. To be honest I have been a beginner for some time now,...

Non-ASCII characters are not allowed outside of literals and identifiers objective-c

ios,objective-c,identifier,literals,non-ascii-chars
I'm getting an error as 'Non-ASCII characters are not allowed outside of literals and identifiers'. Below is code : - (void)purchaseMyProduct:(SKProduct *)product { if ([self canMakePurchases]) { SKPayment *payment = [SKPayment paymentWithProduct:product]; [[SKPaymentQueue defaultQueue] addTransactionObserver:self]; [[SKPaymentQueue defaultQueue] addPayment:payment]; } else{ UIAlertView *alertView = [[UIAlertView alloc] initWithTitle: @"Purchases are disabled in...

How to add key pairs to object literals using loop--WITHOUT overriding existing entries?

javascript,jquery,object,key,literals
I'm reading input field 'name' and 'value' attributes from ul lists. No two lists have the same amount of inputs and the 'name' and 'value' attributes are unknown till read. <ul id="options_set1"> <li><input name="width" value="10" /></li> <li><input name="height" value="20" /></li> <li><input name="depth" value="5" /></li> </ul> <ul id="options_set2"> <li><input name="finish" value="printed"...

Literal vs variable with spaces on divide operator in Ruby

ruby,variables,division,literals
Let's say I have a literal Fixnum 1420028751000 and I want to convert using this: Time.at(1420028751000 / 1000) # => 2014-12-31 20:25:51 +0800 I can put spaces also, let's say I am beginner and my coding is bad: Time.at(1420028751000 / 1000) Time.at(1420028751000 /1000) All these work fine and give me...

Unable to access method in object literal

javascript,function,object,methods,literals
In object literal we should be able to access the methods using this.name, but in my case below I'm using this.init() to trigger a method but gave me undefined function instead. However if I refer to allTabAnimation.init() it works, why is that ? var allTabAnimation = { desktopClick: function (){...

Are literals objects by the standard terminology?

c++,object,literals
The standard defines: An object is a region of storage. [ Note: A function is not an object, regardless of whether or not it occupies storage in the way that objects do. —end note ] An object is created by a definition (3.1), by a new-expression (5.3.4) or by the...

Swift Array(string) not working

ios,arrays,string,swift,literals
I'm trying to make a hangman game. I'm going to paste my code in because I feel my problem is somewhere in here that I'm just not seeing. Look down and find the part where I wrote THIS IS WHERE THE ERROR OCCURS. Here is the error message I get:...

How do I write hexadeximal floating point literal in java?

java,literals
For number -5 x 10^-1 i.e., -0.5, I could write, -5E-1f or -50E-2f or -0.05E+1F as "decimal floating point literal" in java. If the same number is written in "hexadecimal floating literal", I found it as -0X32p-2f which is wrong. This value is -25.0. I considered 50 as 0x32 and...

How can a constant be defined without using a literal?

java,constants,final,literals
I'm struggling to understand how a constant can be defined without using a literal. Does final int A = 1 + 1 count?

Java String Literal Pool

java,string,literals,pool
Let's say we have the following code String x = new String("xyz"); String y = "abc"; x = x + y; A friend of mine says that 4 objects are created in total, where I say that only 3 are created. Can someone explain what's going on in the background?...

What's the best way to get a Class object for an array type?

java,arrays,reflection,constants,literals
It's easy to get a class literal for a class: String.class But how can I get a class object for an array type? This works, but it's ugly, and probably not a compile time constant: new byte[0].getClass() I looked in the JLS but the only thing I found out is...

How to Make _ _ LINE _ _ and _ _ FILE_ _ run in perl? [closed]

windows,perl,literals,console2
(The Script) #!/usr/bin/perl # Program, named literals.perl written to test special literals 1 print "We are on line number ", _ _LINE_ _, ".\n"; 2 print "The name of this file is ",_ _FILE_ _,".\n"; 3 _ _END_ _ And this stuff is just a bunch of chitter–chatter that is...

Convert a hex string to a hex int

ruby,literals
I have to convert a hexadecimal string to a hexadecimal integer, like this: color = "0xFF00FF" #can be any color else, defined by functions colorto = 0xFF00FF #copy of color, but from string to integer without changes I can have RGB format too. I'm obliged to do this because this...

Is there a way to define new literal in Ruby?

ruby,literals
For example, here is a list of defined ruby literals. Does ruby give us a way to define new "custom" one? [Updated] Purpose is to simplify a process of object instantiation. For example if I want to create object based on some dynamic language i'd like to have something like...

Which part of a Javascript statement is literal?

javascript,variables,literals
I know that fixed values are literals, and variable values are variables. If I have a simple statement such as: var car = "Audi"; does it contain a literal? To which part of the statement is the variable applied? Is it "Audi", as that can be changed to another value...

Why is 1_2_3_4 a valid integer literal in java? [duplicate]

java,oop,inheritance,integer,literals
This question already has an answer here: Meaning of 0_0 in Java 7 [duplicate] 3 answers Wierd Syntax - Underscores between digits 1 answer Why does the following work? int a=1_2_3_4; System.out.println(a); // 1234 ...

Is there any way to force ipython to interpret utf-8 symbols?

string,utf-8,ipython,literals,diacritics
I'm using ipython notebook. What I want to do is search a literal string for any spanish accented letters (ñ,á,é,í,ó,ú,Ñ,Á,É,Í,Ó,Ú) and change them to their closest representation in the english alphabet. I decided to write down a simple function and give it a go: def remove_accent(n): listn = list(n) for...

Numeric literals in Java - octal? [duplicate]

java,literals,octal
This question already has an answer here: How does a leading zero change a numeric literal in Java? 3 answers Here is some code in java on datatypes: class Test { public static void main(String args[]) { int i = -0777; System.out.println(i); } } The output of the above...