News for hackers. Stuff that matters.
Re:Literals in Programming Languages by jmmcd on Thursday February 28, 2013 @06:03AM (#5298115)
This article is only about primitive literals, not compound ones. I think the list and dict literals in Python are the #1 reason I like it better than C. I think the regexp literals in Perl were one of the main reasons people liked Perl better than C.
Re:Literals in Programming Languages by mahmud on Thursday February 28, 2013 @08:12AM (#5298488)
That line blurs when you have homoiconic syntax, specially one with a programmable reader. Common Lisp uses the # for dispatch macro character, you can define your own literals, in whatever environment you want.

http://www.franz.com/support/documentation/6.2/ansicl/subsec...

Re:Literals in Programming Languages by arethuza on Thursday February 28, 2013 @08:40AM (#5298571)
Can't you set any dispatch character you like using make-dispatch-macro-character ?
Re:Literals in Programming Languages by mahmud on Thursday February 28, 2013 @09:11AM (#5298677)
Oh yes, you can set your own dispatch characters, but the # is the dispatch character for the CL standard syntax.
Re:Literals in Programming Languages by DerekL on Thursday February 28, 2013 @02:54PM (#5300560)
C99 has array and struct literals:

  (int []) { 1, 2, 3 }
  (struct Point) { 3, 5 }
  (struct Point) { .x = 3, .y = 5 }
Re:Literals in Programming Languages by masklinn on Thursday February 28, 2013 @02:20PM (#5300350)
> This article is only about primitive literals, not compound ones.

It mentions array literals: http://www.gavilan.edu/csis/languages/literals.html#_Toc7587...

Re:Literals in Programming Languages by pilgrim689 on Thursday February 28, 2013 @08:57AM (#5298624)
> I like [Python] better than C

Isn't it strange to compare Python/Perl to C and say that one is better than the other? It's apples to oranges. You wouldn't use Python or Perl to build an OS, and you wouldn't use C to prototype a web app.

Re:Literals in Programming Languages by jmmcd on Thursday February 28, 2013 @04:31PM (#5301163)
Sure, but I said "like", not "better". When I learned Python, I had that feeling described as weightlessness by xkcd [http://xkcd.com/353/], because I didn't have to write several lines and a loop to make a list. It made me happy. Fair comparisons don't really come into it.
Re:Literals in Programming Languages by tantalor on Thursday February 28, 2013 @03:09AM (#5297664)
> Booleans are ordinal values and usually false is less than true.

I was surprised to find this is true,

http://plato.stanford.edu/entries/truth-values/#3

Re:Literals in Programming Languages by jonsen on Thursday February 28, 2013 @03:27AM (#5297710)
So in fact you believed it was false before true then ;-)
Re:Literals in Programming Languages by ibotty on Thursday February 28, 2013 @04:52AM (#5297964)
well i believed that they are not ordered. (which they are not in some languages)
Re:Literals in Programming Languages by tantalor on Thursday February 28, 2013 @10:04AM (#5298915)
That's what I thought, but it appears truth values are typically defined with a partial ordering a <= b iff a && b == a, which gives false <= false < true <= true.

You could choose to ignore that partial ordering at your own peril.

Re:Literals in Programming Languages by cpeterso on Thursday February 28, 2013 @03:47AM (#5297774)
In Visual Basic, False is 0 and True is -1.
Re:Literals in Programming Languages by eterm on Thursday February 28, 2013 @05:23AM (#5298036)
-1 == 1 (mod 2) [But yes, this is Yet Another Reason vb can be irritating to the seasoned programmer.]
Re:Literals in Programming Languages by saurik on Thursday February 28, 2013 @06:53AM (#5298244)
(I always found VB's definition more obvious, given that -1 == ~0.)
Re:Literals in Programming Languages by ubernostrum on Thursday February 28, 2013 @04:20AM (#5297875)
In Python, bool is a subclass of int. The constants True and False have the values 1 and 0 respectively, and it's legal to do arithmetic with them :)
Re:Literals in Programming Languages by swah on Thursday February 28, 2013 @07:09AM (#5298304)
Factor has them for many data-structures: http://docs.factorcode.org/content/article-syntax-literals.h..., but they are simple to add in a concatenative language

(they might as well have been added by a user library).

Re:Literals in Programming Languages by anders0 on Thursday February 28, 2013 @07:03AM (#5298278)
To nitpick, -14 isn't a literal in all languages. :)

(In Haskell, it's just sugar for negate 14, while in Standard ML it's spelt ~14. And I assume there are other exceptions too.)

Re:Literals in Programming Languages by pdw on Thursday February 28, 2013 @07:19AM (#5298336)
Even in C it's not a literal. The consequence is that in a 32-bit implementation, you can't write INT_MIN as -2147483648 (-2^31), because 2147483648 would overflow a signed int. Instead a workaround such as -2147483647-1 must be used.
Re:Literals in Programming Languages by shaurz on Thursday February 28, 2013 @10:02AM (#5298904)
Making the minus part of the literal can lead to parsing ambiguity. For example, "x-3" would parse as 2 tokens "x" and "-3" (instead of 3 tokens "x", "-" and "3") which would be a syntax error in C. The only workaround I can think of is making any expression followed by a negative number parse as a subtraction.
Re:Literals in Programming Languages by reycharles on Thursday February 28, 2013 @12:17PM (#5299654)
> Making the minus part of the literal can lead to parsing ambiguity.

Not really. It's done in java. Usually, minus ("-") is parsed as a token and then unary minus on integer literals are transformed to a negative integer literal.

So, -2147483648 is read as MINUS INT_LITERAL and thus transformed into "-2147483648" as an INT_LITERAL, but -(2147483648) should be read as MINUS L_PAREN INT_LITERAL R_PAREN and should thus not be transformed.

Re:Literals in Programming Languages by anders0 on Thursday February 28, 2013 @07:38AM (#5298386)
Huh. I always assumed it was in C. Shows what I know… :p