Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

There are some cool features in M. One of the neatest is the ability to create arrays on the fly.

Ex:

  >set array("node1")="Hello"
  >set array("node1","subNode1")="Hola"
  >set array("node1","subNodeX")="Howdy"
  >set array("node2")=39481
  >set array(19849,1,1,1,3,"Godzilla",5,8)="Greetings"
All dynamically created on the fly - no need to define the array in any way ahead of time! The nodes are also automatically sorted after any addition/deletion.

Looping over the arrays is very easy too. M has a function that lets you set a variable to the next node.

Ex. (using the above example):

  >set foo=$O(array(foo)) - result: foo="node1"
  >set foo=$O(array(foo)) - result: foo="node2"
  >kill foo
  >set foo=$O(array(foo)) - result: foo="node1"
  >set bar=$O(array(foo,bar) - result: bar="subNode1"
  >set output=array(foo,bar) - result: output="Hello"
  >set bar=$O(array(food,bar) - result: bar="subNodeX"
Variables can also be created on the fly, and don't need to be defined as a type ahead of time. (Technically you don't define them ahead of time at all, if you want a new variable just set it to something!) They can be strings or numbers, and you can change their type at any time by setting them to a new value.

Pretty cool, and particularly easy for someone with no coding experience to pick up. I'd only ever use it for managing a database, though.



Oops, in the 2nd example, output will equal "Hola", not "Hello" (arr("node1","subNode1")). Also I'm pretty sure numbers are sorted before strings, so in reality on the 1st pass foo would equal 19849.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: