Re: Syntax questions

2007-07-30 Thread Lars T Hansen
On 7/30/07, David Teller [EMAIL PROTECTED] wrote:

 Hi,
  I'm currently exploring the code, as a preliminary to writing a static
 analysis tool. At the moment, I'm stuck in the lexer, where I have two
 questions.

 Firstly, embedded comments seem to be forbidden. That is, a block such
 as
 /* bla /* more bla */ even more bla*/
 will be passed to the parser as
 even more bla */
 Is that normal ?

Yes.

 Is that desired ?

It's Traditional, at least.  Most languages don't seem to care about
nested comments.  Standard ML and Modula-3 are the only ones that come
to mind right now.

 Secondly, regular expressions. From what I gather, a regular expression
 containing a x anywhere can be multiline. Is that it ? It sounds too
 strange to be true.

No, a regular expression that is trailed by an 'x' flag can be multiline, eg

   /a*b
   c*d/x

This introduces an interesting problem for the lexer because it can't
know whether the x flag is present until it's lexed the regular
expression.  The rule is that it must assume the x flag is present,
and, coming to the end and finding it not there after all, must throw
a syntax error.

--lars


 Thanks,
  David

 --
 David Teller --
 Security of Distributed Systems ---
 -- http://www.univ-orleans.fr/lifo/Members/David.Teller
 - Laboratoire d'Informatique Fondamentale d'Orleans

 ___
 Es4-discuss mailing list
 Es4-discuss@mozilla.org
 https://mail.mozilla.org/listinfo/es4-discuss

___
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss


Re: Independent Date and Time objects/ISO Dates

2007-07-30 Thread Lars T Hansen
On 5/23/07, Brendan Eich [EMAIL PROTECTED] wrote:
 On May 16, 2007, at 10:37 AM, Lars T Hansen wrote:

  Ah.  No, we've not talked about doing that, and you don't get to set a
  bit on the Date object that says the time does not matter.  I
  suppose you could,  but I don't (yet) know what the consequences are.
  For backwards compatibility a date string probably needs to yield a
  Date object with a time.  For ISO strings we could conceivably do
  something different, but I'm not sure about that.

 We're talking about this thread in the TG1 meeting now. It would help
 us to see how you've worked around Date to meet your use-cases. We
 think a few lines of JS can force a fit, but we're interested to see
 what you did. We don't plan to add a strftime-like API, but if we're
 right about the few-lines scale of adaptation, that might fit in a
 standard method or two.

Part of the problem is that Date.parse does not yield a Date object,
but a timestamp, so retaining information about what was and wasn't
part of the time stamp requires a new parsing API.

IMO we should not take the Date class further than we've taken it.
Given the regularity of the ISO date format, it's reasonably
convenient to subclass Date and add parsers/serializer; JSON clients
can override toJSONString or even toISOString.  And so on.

--lars
___
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss


Re: Separating a Hash type from Object

2007-07-30 Thread Garrett Smith
On 7/25/07, Lars T Hansen [EMAIL PROTECTED] wrote:
 On 7/25/07, Garrett [EMAIL PROTECTED] wrote:
 
 
  Lars T Hansen-2 wrote:
  
   On 7/25/07, Garrett [EMAIL PROTECTED] wrote:
   I see this as two issues.
  
   1) The need for Collections/Data Structures.
   2) The desire for shorthand access to these.
  
   Indeed.  We've decided to support (1) but not (2), but to sweeten our
   solution by providing constructions and conversions from arbitrary
   objects, so you can say
  
 new Dict.Name,int({a: 1, b: 2, c: 3})
  
  What is Name? Is that a new type that I haven't seen yet? Looks like an
  Identifier.
  I don't see Name here:
  http://developer.mozilla.org/es4/spec/chapter_19_native_objects.html
  (That page could benefit from a TOC and alphabetization.)

 Indeed it could.

 The wiki is pretty much out of sync with reality at this point; we
 need to republish the internal wiki but haven't for a while, for
 various reasons having to do with manpower etc.  Hopefully soon.

 A Name is a data structure that holds a namespace and an identifier as
 separate entities.  I misspoke above, there is a more general type
 called EnumerableId that covers all the valid cases for a property
 name in an object (Name, uint, int, and string), so the type in
 question is Dict.EnumerableId,int in the example.

   We're discussing whether to accomodate a hashcode/equals protocol on
   keys, but if so this is guaranteed not to be the only protocol, and
   we're not putting these protocols into Object, which will likely
   reduce their utility a little.
  
  The reason for adding them to Object.prototype is to have a common interface
  for collections to compare objects with. The default behavior would be
  strict equality.

 I understand the motivation, but I don't think we'll be adding new
 names to Object -- it's far too easy to break existing content, even
 if these are DontEnum.  The global object probably needs to be an
 Object of some sort, and suddenly equals and hashcode will show up
 in the global environment because of that.  Tests for 'equals' in
 anything will suddenly return true.  etc.  It's a tough sell.  What
 I have *proposed* for Dict is that we make it possible for clients who
 want to use this OOP-like protocol to use it, and since we define what
 that protocol would be then at least there's a standard for it, but
 there will necessarily be some facility for supplying hashcode and
 equality functions to the Dict constructor as well (defaulting to
 intrinsic::hashcode and intrinsic::===) in cases where the protocol is
 impossible or undesirable.

  The case for HashMap: HashMap is that it is the most common type of
  collection that will be used. Dictionary is more flexible, but since the
  keys are not, by default, strings, it will require more work to serialize
  toJSONString. In most cases users will want Strings for keys.

 I think you have an uphill battle in restricting the functionality of
 Dict, esp since one can say

   type HashMap.T = Dict.String,T;

 and be done with it.  Not hard for the user, really.  Although I
 suppose it is an interesting idea to provide that type by default, in
 addition to Dict.

 It's a good point that Dict ought to have a reasonable toJSONString,
 and it's true that for String keys it can do a particularly good job.
 I'll be sure to add that to the proposal.




 (It actually opens up interesting questions about JSON -- the current
 JSON code from Doug Crockford relies on enumeration to get property
 names, but then filters the enumerated properties through
 hasOwnProperty.
That's for ES3.

So even when Dict provides an iterator, it would need
 to provide an override for hasOwnProperty to work correctly with the
 default JSON protocol, if it does not want to override toJSONString.)


var stuff = new HashTable.String, *();

stuff.add( one, 1 );

stuff.hasOwnProperty( one ); // false.
stuff.one;// undefined.
one in stuff; // false.

if( one in stuff.keys ) stuff.get( one ); // 1.

for( var key in stuff.keys ) {
  print( key + :  + stuff[ key ] );
}
// one: 1.

Should all Collections have a toJSONString?

Collection
 |
 +HashTable, SortedSet TreeMap ?


   (I don't much care for Dict as a name myself, but BiCaptialized
   suggestions like HashMap and hashCode won't get you anywhere with this
   committee ;-)
  
The current JS spec is camelCasing everything. I usually like it when
an API does one thing consistently. If it's underscores, then always
use underscore, et c. JavaScript (hey, that's camel'd, too!) alway
uses camelCase. The DOM stuff is consistent, too (textContent,
nodeValue, et c). Will adding an inconsistency add confusion?


  What about ByteArray, toString, toJSONString, valueOf, et c? If that's not
  camelCase, I'm confused.

 I'm sorry, I was being flip.  We've been deriding Java's choice of
 hashCode for a method name (vs hashcode in ES4), but the examples
 you cite are just as awful.  The splinter in your brother's eye and
 the beam in your own and 

Re: Transient property attribute

2007-07-30 Thread Kris Zyp
The transient property is not just for JSON serialization, but gives an
abstracting indication of transience that is important for any future
persistence, serialization, or mapping mechanisms (which could include
libraries or future language additions).
Thanks,
Kris

On 7/30/07, Lars T Hansen [EMAIL PROTECTED] wrote:

 On 6/6/07, Kris Zyp [EMAIL PROTECTED] wrote:
  Would it be possible to add a property attribute transient? It would
 not
  need any special treatment, it would serve purely as a marker. Java has
 this
  as a property attribute/field modifier, and it is very helpful for
 defining
  what fields should be included in persistence/serialization. The only
  implementation detail that this might effect is that I believe that it
 would
  be most proper if toJSONString ignored properties that had been marked
 as
  transient. So if one declared an instance variable:
  class A{
  transient var b
  }
  b would not be included in toJSONString serializations, and other
  persistence/serialization strategies could use introspection to be aware
  that such values should not be saved. Any chance this could make it in
 the
  spec?

 As this is probably just one more approach to customizing JSON
 serialization, and we're not trying to do much with that (despite
 extensive debate on that list), my guess is no.

 --lars

___
Es4-discuss mailing list
Es4-discuss@mozilla.org
https://mail.mozilla.org/listinfo/es4-discuss