EzDevInfo.com

comma

Comma is a small CSV (ie. comma separated values) generation extension for Ruby objects, that lets you seamlessly define a CSV output format via a small DSL comma-csv/comma · GitHub comma is a small csv (ie. comma separated values) generation extension for ruby objects, that lets you seamlessly define a csv output format via a small dsl

What does the code if ( blah(), 5) {} do?

What does the following code do in C/C++?

if ( blah(), 5) {
 //do something
}

Source: (StackOverflow)

Is the comma in a variable list a sequence point?

In the following type of code is there a sequence point between each variable construction, or is the result undefined?

int a = 0;
int b = a++, c = a++;

I wasn't able to find in the standard a specific reference to a sequence point here. Does that mean it is undefined, or just that I failed in my search? The completion of an expression is a sequence point, but does the above initialization also count?


Source: (StackOverflow)

Advertisements

Please Explain Comma Operator in this Program

Please explain me the output of this program:

int main()
{    
    int a,b,c,d;  
    a=10;  
    b=20;  
    c=a,b;  
    d=(a,b);  
    printf("\nC= %d",c);  
    printf("\nD= %d",d);  
}

The output which I am getting is:

C= 10  
D= 20

My doubt is what does the "," operator do here?
I compiled and ran the program using Code Blocks.


Source: (StackOverflow)

Can someone explain this C++ comma operator short-circuiting example?

Can someone explain this C++ comma operator short-circuiting example?

bIsTRUE     = true, false, true;
bIsFALSE    = (true, false), true;
bIsAlsoTRUE = ((true, false), true);

Why does the second version short-circuit and return false (at least in MSVC++) and the other two versions do not but return true?


Source: (StackOverflow)

Uses of C comma operator [duplicate]

This question already has an answer here:

You see it used in for loop statements, but it's legal syntax anywhere. What uses have you found for it elsewhere, if any?


Source: (StackOverflow)

Comma operator with typeid

I was studying A Generic Non-intrusive Smart Pointer Implementation. I have some confusion in section 4. One statement is

the expression supplied as the argument to the typeid operator is only evaluated if the result type is an lvalue of polymorphic class type.

And associated example code is:

template<typename T>
  void* startOfObject(T* p) {
  void* q=static_cast<void*>(p);
  typeid(q=dynamic_cast<void*>(p),*p); // This line
  return q;
}

AFAIU, it means q=dynamic_cast<void*>(p) will be evaluated if the result type is an lvalue of polymorphic class type. The result means the result of evaluating dynamic_cast<void*>(p) (I guess), so the dynamic_cast has to be applied in any case. The articles states (as I understand) that if p is not polymorphic then dynamic_cast will not be applied, but why? Before applying it, how can it be known whether the result is polymorphic or not? It will be helpful if someone describes in details how the full statement will be executed.

Another statement is

There is also a problem if p is NULL – the typeid will throw a std::bad cast.

The problem I see is with de-referencing if p is NULL, not with typeid (although it may throw bad_typeid, but that is not because of casting). dynamic_cast will return a NULL pointer of type void* if p is NULL, and typeid should be able to deduce the type information. Is that a typo, or am I missing something?


Source: (StackOverflow)

Trailing commas and C++

I've read somewhere that the C++ standard does not allow something like enum an_enum { a, b, c, };, while later versions of C(I think from mid-90s) do allow such declarations(with trailing commas). If C++ is supposed to have backwards compatibility with C, how come this feature is forbidden? Any special reason?

I also read that such trailing commas are actually good, so that just adds to the confusion.


Source: (StackOverflow)

comma separated string of selected values in mysql

i want to convert selected values into comma separated string in mysql

SELECT id FROM table_level where parent_id=4;


----------
output for above query
----------

'5'
'6'
'9'
'10'
'12'
'14'
'15'
'17'
'18'
'779'

----------
but,i want following output:
----------

    "5,6,9,10,12,14,15,17,18,779"

Source: (StackOverflow)

How to Remove last Comma in Jquery?

Here is my code in which i generate comma separated string to provide a list of id to the query string of another page and i get the comma at the end of string.

<script type="text/javascript">
    $(document).ready(function() {
        $('td.title_listing :checkbox').change(function() {
            $('#cbSelectAll').attr('checked', false);
        });
    });
    function CotactSelected() {
        var n = $("td.title_listing input:checked");
        alert(n.length);
        var s = "";
        n.each(function() {
            s += $(this).val() + ",";
        });
        window.location = "/D_ContactSeller.aspx?property=" + s;
        alert(s);
    }
</script>

I Need to remove this last comma. Can anyone tell me how to remove that. Thanks in Advance.


Source: (StackOverflow)

Haskell tuple constructor (GHC) and the separation between a language and its implementation

Haskell blew my mind yet again when I realised that

(x,y)

Is just syntactic sugar for

(,) x y

Naturally I wanted to extend this to larger tuples. But

(,) x ((,) y z)

Gave me

(x,(y,z))

Which was not what I was looking for. On a whim, I tried

(,,) x y z

And it worked, giving exactly what I wanted:

(x,y,z)

This raised the question: How far can you take it? Much to my astonishment, there seemed to be no limit. All of the below are valid operators:

(,)
(,,)
(,,,)
(,,,,)
--etc
(,,,,,,,,,,,,,,)
(,,,,,,,,,,,,,,,)
--etc
(,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,,)
--etc

This behaviour is amazing and leads to my actual question: Is it something which can be emulated in my own functions? Or is it just a GHC-specific feature of the tuple operator? I'm thinking it's the latter as I've read the haskell98 specification and iirc it says that implementations only have to define the tuple operator for up to 15 items. Whereas GHC has gone the whole hog and let you do it up to arbitrary limits.

So, would it be possible to define this family of operators/functions from within the haskell implementation itself, using nothing but the type system and existing language features (declarations, type signatures, function definitions etc.)? And if so, how? Or is it impossible and you have to instead look into the compiler to find the supporting framework for this collection of functions?

This leads to an even more general question: How much of Haskell is supported by Haskell itself, through type and function definitions, declarations etc; and how much is supported by the compiler/implementation? (I am aware that GHC was written in Haskell, that doesn't answer the question)

That is, if you were to abandon the standard libraries (including the prelude) and do everything from the ground up in raw Haskell; would it be possible to build a complete implementation that has all the features of GHC, using only that minimal set of features? What are the mimimum set of language features that you need in order to build a haskell implementation using Haskell? Would I be able to abandon the prelude and then completely rebuild it manually from within GHC? If you abandon the prelude and never import anything, what is left over for you to work with?

It may seem like I'm asking a million questions, but they're really all trying to ask the same thing with different wording. Give it your best shot SO!


Source: (StackOverflow)

Why does Python allow a trailing comma in list?

I am curious why in Python a trailing comma in a list is valid syntax, and it seems that Python simply ignores it:

>>> ['a','b',]
['a', 'b']

It makes sense when its a tuple since ('a') and ('a',) are two different things, but in lists?


Source: (StackOverflow)

Comma operator(,) Where it can "really" be useful

I read this question about the comma operator (,) and the MDN docs about it.

But I just can't think on a real scenario where it's handy and useful.

Is the comma operator really a confusing and useless "feature" of javascript?


Source: (StackOverflow)

Is this use of the "," operator considered bad form?

I have made a list class as a means of replacing variadic functions in my program used for initializing objects that need to contain a changing list of elements. The list class has a usage syntax that I really like. However I haven't seen it used before, so I was wondering if I shouldn't use it just because of that fact? A basic implementation of the list class looks like this...

#include <list>
#include <iostream>
template<typename T>
struct list
{
    std::list<T> items;
    list(const list&ref):items(ref.items){}
    list(){}
    list(T var){items.push_back(var);}
    list& operator,(list add_){
        items.insert(items.end(),add_.items.begin(), add_.items.end());
        return *this;
    }
    list& operator=(list add_){
        items.clear();
        items.insert(items.end(),add_.items.begin(), add_.items.end());
        return *this;
    }
    list& operator+=(list add_){
        items.insert(items.end(),add_.items.begin(), add_.items.end());
        return *this;
    }
};

This allows me to have use this in code like so...

struct music{
//...
};
struct music_playlist{
    list<music> queue;
//...
};
int main (int argc, const char * argv[])
{
    music_playlist playlist;
    music song1;
    music song2;
    music song3;
    music song4;
    playlist.queue = song1,song2; // The queue now contains song1 and song2
    playlist.queue+= song1,song3,song4; //The queue now contains two song1s and song2-4
    playlist.queue = song2; //the queue now only contains song2
    return 0;
}

I really think that the syntax is much nicer than it would of been if I had just exposed a regular stl container, and even nicer (and typesafe) than variadic functions. However, since I have not seen this syntax used, I am curious about whether I should avoid it, because above all the code should be easily understood by other programmers?

EDIT:

In joint with this question, I have posted this question more targeted at solutions to the actual problem.


Source: (StackOverflow)

What does a comma separated list of values, enclosed in paranthesis mean in C? a = (1, 2, 3); [duplicate]

This question already has an answer here:

I've just come across code that essentially does the following:

int a = (1, 2, 3);

I've never seen this notation before. What does it mean?


Source: (StackOverflow)

Use of commas versus semicolons in JavaScript?

Given the following code

var fn = function () {
    var x = 'x',
    y = 'y';
    this.a = 'a',
    this.b = 'b',
    this.c = 'c';
    this.d = 'd',
    this.e = 'e';   
}

You can see that there is a mix of both.
What would be the benefit of using one or the other?

My understanding is that the semicolon is to end the statement. And comma should be used to string together multiple declarations.

So is it safe to say that with this example then there should only be two semicolon?

var fn = function () {
    var x = 'x',
    y = 'y';
    this.a = 'a',
    this.b = 'b',
    this.c = 'c',
    this.d = 'd',
    this.e = 'e';   
}

Source: (StackOverflow)