constants

Un-define constants with define/apc_define_constants in PHP

老子叫甜甜 提交于 2019-12-24 09:39:59
问题 I'm using constants for output messages in different languages. For example, if a user chooses "English", a file with this constant would be required: define('welcomeMessage','Welcome!'); If she chooses "Spanish": define('welcomeMessage','Bien Venidos!'); etc etc... The problem occurs when a user iterates through languages. I can't redefine constants with either define/apc_define_constants (as far as I know). Can I delete and redefine them? Is there a good solution for this? 回答1: Constants

Accessing PHP MySQLI predefined constants via respective value?

孤街浪徒 提交于 2019-12-24 08:55:39
问题 I am writing a function that takes a mysqli_result and adds all of the returned columns into an associative array in my result object. As of right now everything that is returned via the mysqli::multi_query is in string format, while the description as to what value type the value should be is kept in the array of objects returned by mysqli::fetch_fields. I feel that so far this is pretty confusing so let me code it out if ($mysqli->multi_query($inputQuery)) { if ($result = $mysqli->store

Convert a NSString into the name of a Constant

半世苍凉 提交于 2019-12-24 08:23:28
问题 I have a bunch of constants declared like this: #define kConstant0 @"Cow" #define kConstant1 @"Horse" #define kConstant2 @"Zebra" Elsewhere in code I'm trying to extract the constant value by adding an integer to the string name of the constant: int myInt = 1; // (Actual intValue Pulled From Elsewhere) myLabel.text = [@"kConstant" stringByAppendingString:[NSString stringWithFormat:@"%i",myInt]]; But of course this returns: myLabel.text = @"kConstant1"; When I want it to return: myLabel.text =

Prolog Tree Traversal

人盡茶涼 提交于 2019-12-24 05:05:47
问题 Good Day, I am trying to write a Prolog program that given a tree with a functor of a: start(a(f,2,9), X). I want it to square any values inside so that it yields: X = a(f,4,81). I have code that squares numbers in a list already that works. Here's what I have so far: start([],[]). start(Tree, []) :- Tree =.. [P|C], write(P), nl, write(C), nl, squareMe([P|C], []). squareMe([X|T], [Y|Result]) :- % I think the problem is here atom(X), Y=X, squareMe(T, Result). squareMe([X|T], [Y|Result]) :-

Prolog Tree Traversal

微笑、不失礼 提交于 2019-12-24 05:05:11
问题 Good Day, I am trying to write a Prolog program that given a tree with a functor of a: start(a(f,2,9), X). I want it to square any values inside so that it yields: X = a(f,4,81). I have code that squares numbers in a list already that works. Here's what I have so far: start([],[]). start(Tree, []) :- Tree =.. [P|C], write(P), nl, write(C), nl, squareMe([P|C], []). squareMe([X|T], [Y|Result]) :- % I think the problem is here atom(X), Y=X, squareMe(T, Result). squareMe([X|T], [Y|Result]) :-

Getting constants from another file in Perl

人走茶凉 提交于 2019-12-24 03:17:42
问题 I'm trying to extract some constants from a Perl file which I've defined in file A.pm package A; use constant ERROR_ID_MAP => [ PLAYBACK_ERROR => { defaultMessage => "Sorry there was an error with a playback", errorCode => 0, }, PURCHASE_ERROR => { defaultMessage => "Sorry, we've encountered a problem with purchasing. Please try again.", errorCode => 2123, }, ]; and so on... then in package B, I want to get that error file somehow. My thought was to get it like: sub getErrorMap { my ($self) =

Why are constants declared inside an array, and assigned to other constants, accessible as Class constants in Ruby?

会有一股神秘感。 提交于 2019-12-24 01:16:33
问题 Given the following Ruby class class Example PARENTS = [ FATHER = :father, MOTHER = :mother ] end These work as expected > Example::PARENTS #=> [:father, :mother] > Example::PARENTS[0] #=> :father > Example::PARENTS[1] #=> :mother However, why does this work? > Example::FATHER #=> :father > Example::MOTHER #=> :mother In fact, why are there three constants in the Example class's scope? > Example.constants #=> [:MOTHER, :PARENTS, :FATHER] To the point, that if I extend the class with an

Name Clash with Top Level constant when autoloading with Rails

北城余情 提交于 2019-12-24 00:48:53
问题 I'm having a class Dog in app/models/dog.rb and another class Services::My::Deeply::Nested::Dog in app/services/my/deeply/nested/dog.rb . Now in Services::My (app/services/my.rb), I have a reference to one of the following (no need to distinguish, since the behaviour is exaclty the same in all situations): Deeply::Nested::Dog Services::My::Deeply::Nested::Dog ::Services::My::Deeply::Nested::Dog No matter which of the above I choose, I always get the following error message: services/my.rb:

What does the compiler at casting integer constants?

ⅰ亾dé卋堺 提交于 2019-12-23 21:06:53
问题 Using the following macro: #define MIN_SWORD (signed int) 0x8000 In e.g. the following expression: signed long s32; if (s32 < (signed long)MIN_SWORD)... is expected to do the following check: if (s32 < -32768) One some compilers it seems to work fine. But on some other compiler the exprssion is evaluated as: if (s32 < 32768) My question: How is a ANSI-C compiler supposed to evaluate the following expression: (signed long) (signed int) 0x8000 ? It seems that on some compilers the cast to `

Best/proper way to define uint64_t constants

放肆的年华 提交于 2019-12-23 18:45:05
问题 constexpr auto v = static_cast<std::uint64_t>(1) << 32; is not ideal, because of the tedious syntax and the cast which is semantically indirect. From this thread, I learned constexpr auto v = UINT64_C(1) << 32; However, the precise semantics of the macro is expands to an integer constant expression having the value specified by its argument and the type uint_least64_t . Therefore, it's not exactly uint64_t . I'm wondering what is the best/proper way to define uint64_t constants. Note that