Skip to content
Browse files

JavaScript-like hashes have been documented (Closes: #1134).

  • Loading branch information...
1 parent 86714b0 commit c0956650763ac4de7be2727c4aad5021d116a10c @angelortega committed Oct 17, 2011
Showing with 25 additions and 11 deletions.
  1. +3 −1 TODO
  2. +22 −10 doc/mpsl_overview.txt
View
4 TODO
@@ -4,7 +4,7 @@ Minimum Profit Scripting Language (mpsl) TODO / Bug List
Release Critical Bugs
---------------------
- * 1134: Document the JavaScript style of defining hashes.
+None!
Open Bugs
---------
@@ -216,5 +216,7 @@ Closed
* 1129: Document the new multithreading support
(Tue, 19 Apr 2011 09:49:07 +0200).
* 1133: Fix for() (Wed, 20 Apr 2011 06:35:17 +0200).
+ * 1134: Document the JavaScript style of defining hashes
+ (Mon, 17 Oct 2011 20:13:21 +0200).
Email bugs to angel@triptico.com
View
32 doc/mpsl_overview.txt
@@ -152,21 +152,33 @@ values can be of any type (scalar, array or hash). However, keys are
usually scalar values, in particular strings.
en2es_workdays = {
- 'monday' => 'lunes',
- 'tuesday' => 'martes',
- 'wednesday' => 'miercoles',
- 'thursday' => 'jueves',
- 'friday' => 'viernes'
- };
+ 'monday' => 'lunes',
+ 'tuesday' => 'martes',
+ 'wednesday' => 'miercoles',
+ 'thursday' => 'jueves',
+ 'friday' => 'viernes'
+ };
print(en2es_workdays['monday'], "\n"); /* prints lunes */
week = {
- 'workdays' => workdays,
- 'weekend' => [ 'saturday', 'sunday' ]
- };
+ 'workdays' => workdays,
+ 'weekend' => [ 'saturday', 'sunday' ]
+ };
-Hash definitions *must* use the => to mark key/value pairs.
+Hash definitions can use the => to mark key/value pairs (what is called
+the "traditional" or Perl-like syntax), or a special, JavaScript-like
+simpler mode (supported since version 2.0.1) which is useful when the
+keys are composed only by alphanumeric characters (letters, numbers and
+the _ symbol). Like this:
+
+ en2es_workdays = {
+ monday: 'lunes',
+ tuesday: 'martes',
+ wednesday: 'miercoles',
+ thursday: 'jueves',
+ friday: 'viernes'
+ };
Hash assignation is always by reference, as in arrays (in fact, hashes are
just a special case of array).

0 comments on commit c095665

Please sign in to comment.
Something went wrong with that request. Please try again.