FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

December 10th -- toString now called, slicing

 
Post new topic   Reply to topic     Forum Index -> MiniD
View previous topic :: View next topic  
Author Message
JarrettBillingsley



Joined: 20 Jun 2006
Posts: 457
Location: Pennsylvania!

PostPosted: Mon Dec 11, 2006 10:53 am    Post subject: December 10th -- toString now called, slicing Reply with quote

This would have gone up last night but CERTAIN SITES were down.

Fixed
  • Bug in the compiler that caused the compiler to go into an infinite loop when it encountered an underscore in a number.
  • Compiler did not follow spec for floats; now requires at least one digit after the decimal point.


Changed
  • Removed array.slice and string.slice, since slicing is part of the language.
  • table.contains now returns two values -- first, a boolean of whether or not the key exists, and if it does, the second value is the value. This way you can avoid double lookups. It's kind of like using "in" with D's AAs, and checking if the returned pointer is null or not.


Added
  • toString metamethods are now called when you use the toString baselib function, and when printing values out with write[f][ln].
  • Added a pop function to MDState to pop a value off the stack. This is another way to get the returns from a function - though they'll come off the stack in reverse order, of course.
  • Added a valueToString function to MDState which will take an MDValue and return an MDString representation. This is different from MDValue.toString() because it calls toString metamethods. If there is no toString metamethod for the value, or if the metamethod isn't a function or delegate, the value from MDValue.toString() will be returned.
  • Added slice expressions. You can now have opSlice and opSliceAssign metamethods.
  • Added array.toString which will give a string representation of the contents of the array. It won't call toString metamethods recursively, however, since that could end up with an infinite loop.


Some notes about slicing. It looks pretty much the same as in D, like arr[0 .. 5]. However, it takes some ideas from Python as well. Namely, you can omit indices to mean "all the way to the end". So what would be arr[5 .. $] in D becomes just arr[5 ..] in MiniD. The high index is noninclusive, just as in D. arr[..] is the slice of the entire thing, unlike arr[] in D. Lastly, you can pass negative indices to indicate distance from the end of the array. So what is arr[0 .. $ - 1] in D is arr[0 .. -1] in MiniD.

Overloading slicing (opSlice, opSliceAssign) is just like overloading opIndex and opIndexAssign except there are two indices instead of one. So it's opSlice(this, loIndex, hiIndex) and opSliceAssign(this, loIndex, hiIndex, value). Omitted indices are passed 'null'.

Slicing is implemented for arrays and strings by default; you can slice and sliceAssign arrays, and you can slice strings (since they're immutable). One thing that you can't do (yet, since I just thought about it) is copy values from one array to another with slicing, i.e. arr[0 .. 5] = arr2[3 .. 8]. I'll put that in soon Smile


Last edited by JarrettBillingsley on Thu Dec 14, 2006 1:58 pm; edited 3 times in total
Back to top
View user's profile Send private message
ideage



Joined: 12 Jul 2006
Posts: 63
Location: china

PostPosted: Mon Dec 11, 2006 9:40 pm    Post subject: Re: December 10th -- toString now called, slicing Reply with quote

JarrettBillingsley wrote:


[*]Added a pop function to MDState to pop a value off the stack.


It more like LUA.


Thank you!
________
e cigarette
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic     Forum Index -> MiniD All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group